#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*/ fprintf(int /*<<< orphan*/, char *);
scalar_t__ getbyte(int, unsigned char *);
int /*<<< orphan*/ putbyte(int, int);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ stderr;
int reset(int fd) {
  unsigned char r[2];
  if (!putbyte(fd, 0xFF)) {
    fprintf(stderr, "error reset\n");
    return 0;
  }
  sleep(5);
  if (getbyte(fd, &r[0]) && getbyte(fd, &r[1]))
    if (r[0] == 0xAA && r[1] == 0x00) {
      fprintf(stderr, "reset done\n");
      return 1;
    }
  fprintf(stderr, "error reset ack\n");
  return 0;
}


x86 assembly (clang, -O0):
<reset>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%edi
mov    $0xff,%esi
call   1050 <putbyte@plt>
cmp    $0x0,%eax
jne    1182 <reset+0x42>
mov    0x2e78(%rip),%rax
mov    (%rax),%edi
lea    0xe8f(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    121a <reset+0xda>
mov    $0x5,%edi
call   1060 <sleep@plt>
mov    -0x8(%rbp),%edi
lea    -0xa(%rbp),%rsi
call   1030 <getbyte@plt>
cmp    $0x0,%rax
je     11fe <reset+0xbe>
mov    -0x8(%rbp),%edi
lea    -0xa(%rbp),%rsi
add    $0x1,%rsi
call   1030 <getbyte@plt>
cmp    $0x0,%rax
je     11fe <reset+0xbe>
movzbl -0xa(%rbp),%eax
cmp    $0xaa,%eax
jne    11f9 <reset+0xb9>
movzbl -0x9(%rbp),%eax
cmp    $0x0,%eax
jne    11f9 <reset+0xb9>
mov    0x2e01(%rip),%rax
mov    (%rax),%edi
lea    0xe25(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    121a <reset+0xda>
jmp    11fe <reset+0xbe>
mov    0x2ddb(%rip),%rax
mov    (%rax),%edi
lea    0xe0b(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<reset>:
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebx
mov    $0xff,%esi
call   1050 <putbyte@plt>
test   %eax,%eax
je     11bd <reset+0x7d>
mov    $0x5,%edi
call   1060 <sleep@plt>
lea    0xe(%rsp),%rsi
mov    %ebx,%edi
call   1030 <getbyte@plt>
test   %rax,%rax
je     11ab <reset+0x6b>
lea    0xf(%rsp),%rsi
mov    %ebx,%edi
call   1030 <getbyte@plt>
test   %rax,%rax
je     11ab <reset+0x6b>
cmpb   $0xaa,0xe(%rsp)
jne    11ab <reset+0x6b>
cmpb   $0x0,0xf(%rsp)
jne    11ab <reset+0x6b>
mov    0x2e4a(%rip),%rax
mov    (%rax),%edi
lea    0xe6e(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%eax
jmp    11d4 <reset+0x94>
mov    0x2e2e(%rip),%rax
mov    (%rax),%edi
lea    0xe5e(%rip),%rsi
jmp    11cd <reset+0x8d>
mov    0x2e1c(%rip),%rax
mov    (%rax),%edi
lea    0xe33(%rip),%rsi
call   1040 <fprintf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [13 x i8] c"error reset\0A\00"
@.str.1 = [12 x i8] c"reset done\0A\00"
@.str.2 = [17 x i8] c"error reset ack\0A\00"
define i32 @reset(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca [2 x i8]
store i32 %0, i32* %3
%5 = load i32, i32* %3
%6 = call i32 @putbyte(i32 %5, i32 255)
%7 = icmp ne i32 %6, 0
br i1 %7, label %11, label %8
8: ; preds = %1
%9 = load i32, i32* @stderr
%10 = call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %2
br label %39
11: ; preds = %1
%12 = call i32 @sleep(i32 5)
%13 = load i32, i32* %3
%14 = getelementptr inbounds [2 x i8], [2 x i8]* %4, i64 0, i64 0
%15 = call i64 @getbyte(i32 %13, i8* %14)
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %36
17: ; preds = %11
%18 = load i32, i32* %3
%19 = getelementptr inbounds [2 x i8], [2 x i8]* %4, i64 0, i64 1
%20 = call i64 @getbyte(i32 %18, i8* %19)
%21 = icmp ne i64 %20, 0
br i1 %21, label %22, label %36
22: ; preds = %17
%23 = getelementptr inbounds [2 x i8], [2 x i8]* %4, i64 0, i64 0
%24 = load i8, i8* %23
%25 = zext i8 %24 to i32
%26 = icmp eq i32 %25, 170
br i1 %26, label %27, label %35
27: ; preds = %22
%28 = getelementptr inbounds [2 x i8], [2 x i8]* %4, i64 0, i64 1
%29 = load i8, i8* %28
%30 = zext i8 %29 to i32
%31 = icmp eq i32 %30, 0
br i1 %31, label %32, label %35
32: ; preds = %27
%33 = load i32, i32* @stderr
%34 = call i32 @fprintf(i32 %33, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %2
br label %39
35: ; preds = %27, %22
br label %36
36: ; preds = %35, %17, %11
%37 = load i32, i32* @stderr
%38 = call i32 @fprintf(i32 %37, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %2
br label %39
39: ; preds = %36, %32, %8
%40 = load i32, i32* %2
ret i32 %40
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [13 x i8] c"error reset\0A\00"
@.str.1 = [12 x i8] c"reset done\0A\00"
@.str.2 = [17 x i8] c"error reset ack\0A\00"
define i32 @reset(i32 %0) {
%2 = alloca [2 x i8]
%3 = getelementptr inbounds [2 x i8], [2 x i8]* %2, i64 0, i64 0
%4 = tail call i32 @putbyte(i32 %0, i32 255)
%5 = icmp eq i32 %4, 0
br i1 %5, label %6, label %9
6: ; preds = %1
%7 = load i32, i32* @stderr
%8 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
br label %29
9: ; preds = %1
%10 = tail call i32 @sleep(i32 5)
%11 = call i64 @getbyte(i32 %0, i8* %3)
%12 = icmp eq i64 %11, 0
br i1 %12, label %26, label %13
13: ; preds = %9
%14 = getelementptr inbounds [2 x i8], [2 x i8]* %2, i64 0, i64 1
%15 = call i64 @getbyte(i32 %0, i8* %14)
%16 = icmp eq i64 %15, 0
br i1 %16, label %26, label %17
17: ; preds = %13
%18 = load i8, i8* %3
%19 = icmp eq i8 %18, -86
%20 = load i8, i8* %14
%21 = icmp eq i8 %20, 0
%22 = select i1 %19, i1 %21, i1 false
br i1 %22, label %23, label %26
23: ; preds = %17
%24 = load i32, i32* @stderr
%25 = call i32 @fprintf(i32 %24, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
br label %29
26: ; preds = %17, %13, %9
%27 = load i32, i32* @stderr
%28 = call i32 @fprintf(i32 %27, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
br label %29
29: ; preds = %26, %23, %6
%30 = phi i32 [ 1, %23 ], [ 0, %26 ], [ 0, %6 ]
ret i32 %30
}