#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 *, ...);
int read(int, unsigned char *, int);
int /*<<< orphan*/ stderr;
int readAck(int fd) {
  int n;
  unsigned char x;
  for (n = 0; n < 30; n++) {
    if (read(fd, &x, 1) == 1) {
      if (x == 0x79)
        return 0;
      fprintf(stderr, "?? %02x\n", x);
      return -1;
    }
  }
  fprintf(stderr, "*TIMEOUT*\n");
  return -1;
}


x86 assembly (clang, -O0):
<readAck>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
cmpl   $0x1e,-0xc(%rbp)
jge    11a9 <readAck+0x89>
mov    -0x8(%rbp),%edi
lea    -0xd(%rbp),%rsi
mov    $0x1,%edx
call   1030 <read@plt>
cmp    $0x1,%eax
jne    1196 <readAck+0x76>
movzbl -0xd(%rbp),%eax
cmp    $0x79,%eax
jne    116f <readAck+0x4f>
movl   $0x0,-0x4(%rbp)
jmp    11c7 <readAck+0xa7>
mov    0x2e6a(%rip),%rax
mov    (%rax),%edi
movzbl -0xd(%rbp),%edx
lea    0xe7d(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c7 <readAck+0xa7>
jmp    119b <readAck+0x7b>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1132 <readAck+0x12>
mov    0x2e30(%rip),%rax
mov    (%rax),%edi
lea    0xe50(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readAck>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebx
mov    $0x1e,%ebp
lea    0xf(%rsp),%r14
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x1,%edx
call   1030 <read@plt>
cmp    $0x1,%eax
je     1172 <readAck+0x52>
add    $0xffffffff,%ebp
jne    1140 <readAck+0x20>
mov    0x2e80(%rip),%rax
mov    (%rax),%edi
lea    0xea0(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
jmp    1195 <readAck+0x75>
movzbl 0xf(%rsp),%edx
xor    %eax,%eax
cmp    $0x79,%edx
je     119a <readAck+0x7a>
mov    0x2e5b(%rip),%rax
mov    (%rax),%edi
lea    0xe72(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    $0xffffffff,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [9 x i8] c"?? %02x\0A\00"
@.str.1 = [11 x i8] c"*TIMEOUT*\0A\00"
define i32 @readAck(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8
store i32 %0, i32* %3
store i32 0, i32* %4
br label %6
6: ; preds = %24, %1
%7 = load i32, i32* %4
%8 = icmp slt i32 %7, 30
br i1 %8, label %9, label %27
9: ; preds = %6
%10 = load i32, i32* %3
%11 = call i32 @read(i32 %10, i8* %5, i32 1)
%12 = icmp eq i32 %11, 1
br i1 %12, label %13, label %23
13: ; preds = %9
%14 = load i8, i8* %5
%15 = zext i8 %14 to i32
%16 = icmp eq i32 %15, 121
br i1 %16, label %17, label %18
17: ; preds = %13
store i32 0, i32* %2
br label %30
18: ; preds = %13
%19 = load i32, i32* @stderr
%20 = load i8, i8* %5
%21 = zext i8 %20 to i32
%22 = call i32 (i32, i8*, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %21)
store i32 -1, i32* %2
br label %30
23: ; preds = %9
br label %24
24: ; preds = %23
%25 = load i32, i32* %4
%26 = add nsw i32 %25, 1
store i32 %26, i32* %4
br label %6
27: ; preds = %6
%28 = load i32, i32* @stderr
%29 = call i32 (i32, i8*, ...) @fprintf(i32 %28, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %2
br label %30
30: ; preds = %27, %18, %17
%31 = load i32, i32* %2
ret i32 %31
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [9 x i8] c"?? %02x\0A\00"
@.str.1 = [11 x i8] c"*TIMEOUT*\0A\00"
define i32 @readAck(i32 %0) {
%2 = alloca i8
br label %6
3: ; preds = %6
%4 = add nuw nsw i32 %7, 1
%5 = icmp eq i32 %4, 30
br i1 %5, label %17, label %6
6: ; preds = %1, %3
%7 = phi i32 [ 0, %1 ], [ %4, %3 ]
%8 = call i32 @read(i32 %0, i8* %2, i32 1)
%9 = icmp eq i32 %8, 1
br i1 %9, label %10, label %3
10: ; preds = %6
%11 = load i8, i8* %2
%12 = icmp eq i8 %11, 121
br i1 %12, label %20, label %13
13: ; preds = %10
%14 = zext i8 %11 to i32
%15 = load i32, i32* @stderr
%16 = tail call i32 (i32, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %14)
br label %20
17: ; preds = %3
%18 = load i32, i32* @stderr
%19 = tail call i32 (i32, i8*, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
br label %20
20: ; preds = %10, %17, %13
%21 = phi i32 [ -1, %13 ], [ -1, %17 ], [ 0, %10 ]
ret i32 %21
}