#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
int /*<<< orphan*/ read(int, unsigned char *, int);
int /*<<< orphan*/ write(int, unsigned char *, int);
int programmer_write_oscal(int port, int oscal, int fuse1) {
  unsigned char command;
  unsigned char buffer[4];
  command = 10;
  write(port, &command, 1);
  buffer[0] = (oscal >> 8) & 0xFF;
  buffer[1] = oscal & 0xFF;
  buffer[2] = (fuse1 >> 8) & 0xFF;
  buffer[3] = fuse1 & 0xFF;
  write(port, buffer, 4);
  read(port, buffer, 1);
  if (buffer[0] == 'C') {
    ;
    return -1;
  } else if (buffer[0] == 'F') {
    ;
    return -2;
  } else if (buffer[0] != 'Y') {
    return -3;
  }
  return 0;
}


x86 assembly (clang, -O0):
<programmer_write_oscal>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
movb   $0xa,-0x11(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x11(%rbp),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
mov    -0xc(%rbp),%eax
sar    $0x8,%eax
and    $0xff,%eax
mov    %al,-0x15(%rbp)
mov    -0xc(%rbp),%eax
and    $0xff,%eax
mov    %al,-0x14(%rbp)
mov    -0x10(%rbp),%eax
sar    $0x8,%eax
and    $0xff,%eax
mov    %al,-0x13(%rbp)
mov    -0x10(%rbp),%eax
and    $0xff,%eax
mov    %al,-0x12(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x15(%rbp),%rsi
mov    $0x4,%edx
call   1030 <write@plt>
mov    -0x8(%rbp),%edi
lea    -0x15(%rbp),%rsi
mov    $0x1,%edx
call   1040 <read@plt>
movzbl -0x15(%rbp),%eax
cmp    $0x43,%eax
jne    11b3 <programmer_write_oscal+0x93>
movl   $0xffffffff,-0x4(%rbp)
jmp    11f6 <programmer_write_oscal+0xd6>
movzbl -0x15(%rbp),%eax
cmp    $0x46,%eax
jne    11cc <programmer_write_oscal+0xac>
movl   $0xfffffffe,-0x4(%rbp)
jmp    11f6 <programmer_write_oscal+0xd6>
movzbl -0x15(%rbp),%eax
cmp    $0x59,%eax
je     11e5 <programmer_write_oscal+0xc5>
movl   $0xfffffffd,-0x4(%rbp)
jmp    11f6 <programmer_write_oscal+0xd6>
jmp    11ea <programmer_write_oscal+0xca>
jmp    11ef <programmer_write_oscal+0xcf>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<programmer_write_oscal>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %edx,%r14d
mov    %esi,%ebx
mov    %edi,%ebp
movb   $0xa,0xb(%rsp)
lea    0xb(%rsp),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
mov    %bh,0xc(%rsp)
mov    %bl,0xd(%rsp)
mov    %r14d,%eax
mov    %ah,0xe(%rsp)
mov    %al,0xf(%rsp)
lea    0xc(%rsp),%rbx
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x4,%edx
call   1030 <write@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1040 <read@plt>
mov    0xc(%rsp),%al
cmp    $0x43,%al
je     1190 <programmer_write_oscal+0x70>
cmp    $0x59,%al
je     1197 <programmer_write_oscal+0x77>
cmp    $0x46,%al
jne    119b <programmer_write_oscal+0x7b>
mov    $0xfffffffe,%eax
jmp    11a0 <programmer_write_oscal+0x80>
mov    $0xffffffff,%eax
jmp    11a0 <programmer_write_oscal+0x80>
xor    %eax,%eax
jmp    11a0 <programmer_write_oscal+0x80>
mov    $0xfffffffd,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @programmer_write_oscal(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8
%9 = alloca [4 x i8]
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i8 10, i8* %8
%10 = load i32, i32* %5
%11 = call i32 @write(i32 %10, i8* %8, i32 1)
%12 = load i32, i32* %6
%13 = ashr i32 %12, 8
%14 = and i32 %13, 255
%15 = trunc i32 %14 to i8
%16 = getelementptr inbounds [4 x i8], [4 x i8]* %9, i64 0, i64 0
store i8 %15, i8* %16
%17 = load i32, i32* %6
%18 = and i32 %17, 255
%19 = trunc i32 %18 to i8
%20 = getelementptr inbounds [4 x i8], [4 x i8]* %9, i64 0, i64 1
store i8 %19, i8* %20
%21 = load i32, i32* %7
%22 = ashr i32 %21, 8
%23 = and i32 %22, 255
%24 = trunc i32 %23 to i8
%25 = getelementptr inbounds [4 x i8], [4 x i8]* %9, i64 0, i64 2
store i8 %24, i8* %25
%26 = load i32, i32* %7
%27 = and i32 %26, 255
%28 = trunc i32 %27 to i8
%29 = getelementptr inbounds [4 x i8], [4 x i8]* %9, i64 0, i64 3
store i8 %28, i8* %29
%30 = load i32, i32* %5
%31 = getelementptr inbounds [4 x i8], [4 x i8]* %9, i64 0, i64 0
%32 = call i32 @write(i32 %30, i8* %31, i32 4)
%33 = load i32, i32* %5
%34 = getelementptr inbounds [4 x i8], [4 x i8]* %9, i64 0, i64 0
%35 = call i32 @read(i32 %33, i8* %34, i32 1)
%36 = getelementptr inbounds [4 x i8], [4 x i8]* %9, i64 0, i64 0
%37 = load i8, i8* %36
%38 = zext i8 %37 to i32
%39 = icmp eq i32 %38, 67
br i1 %39, label %40, label %41
40: ; preds = %3
store i32 -1, i32* %4
br label %56
41: ; preds = %3
%42 = getelementptr inbounds [4 x i8], [4 x i8]* %9, i64 0, i64 0
%43 = load i8, i8* %42
%44 = zext i8 %43 to i32
%45 = icmp eq i32 %44, 70
br i1 %45, label %46, label %47
46: ; preds = %41
store i32 -2, i32* %4
br label %56
47: ; preds = %41
%48 = getelementptr inbounds [4 x i8], [4 x i8]* %9, i64 0, i64 0
%49 = load i8, i8* %48
%50 = zext i8 %49 to i32
%51 = icmp ne i32 %50, 89
br i1 %51, label %52, label %53
52: ; preds = %47
store i32 -3, i32* %4
br label %56
53: ; preds = %47
br label %54
54: ; preds = %53
br label %55
55: ; preds = %54
store i32 0, i32* %4
br label %56
56: ; preds = %55, %52, %46, %40
%57 = load i32, i32* %4
ret i32 %57
}

LLVM IR (-O2):
define i32 @programmer_write_oscal(i32 %0, i32 %1, i32 %2) {
%4 = alloca i8
%5 = alloca [4 x i8]
%6 = getelementptr inbounds [4 x i8], [4 x i8]* %5, i64 0, i64 0
store i8 10, i8* %4
%7 = call i32 @write(i32 %0, i8* %4, i32 1)
%8 = lshr i32 %1, 8
%9 = trunc i32 %8 to i8
store i8 %9, i8* %6
%10 = trunc i32 %1 to i8
%11 = getelementptr inbounds [4 x i8], [4 x i8]* %5, i64 0, i64 1
store i8 %10, i8* %11
%12 = lshr i32 %2, 8
%13 = trunc i32 %12 to i8
%14 = getelementptr inbounds [4 x i8], [4 x i8]* %5, i64 0, i64 2
store i8 %13, i8* %14
%15 = trunc i32 %2 to i8
%16 = getelementptr inbounds [4 x i8], [4 x i8]* %5, i64 0, i64 3
store i8 %15, i8* %16
%17 = call i32 @write(i32 %0, i8* %6, i32 4)
%18 = call i32 @read(i32 %0, i8* %6, i32 1)
%19 = load i8, i8* %6
switch i8 %19, label %21 [
i8 67, label %23
i8 70, label %20
i8 89, label %22
]
20: ; preds = %3
br label %23
21: ; preds = %3
br label %23
22: ; preds = %3
br label %23
23: ; preds = %3, %22, %21, %20
%24 = phi i32 [ -2, %20 ], [ -3, %21 ], [ 0, %22 ], [ -1, %3 ]
ret i32 %24
}