#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 */
typedef int /*<<< orphan*/ ret;

/* Variables and functions */
int drv_generic_serial_read(char *, int);
int /*<<< orphan*/ message(int /*<<< orphan*/, char *);
int /*<<< orphan*/ usleep(int);
void drv_D4D_receive_ACK() {
  char ret[1];
  while (drv_generic_serial_read(ret, sizeof(ret)) != 1)
    usleep(1);
  if (ret[0] == 0x15) {
    message(0, "NAK!");
  } else if (ret[0] != 6) {
    message(0, "no ACK!");
  }
}


x86 assembly (clang, -O0):
<drv_D4D_receive_ACK>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    -0x1(%rbp),%rdi
mov    $0x1,%esi
call   1040 <drv_generic_serial_read@plt>
cmp    $0x1,%eax
je     115e <drv_D4D_receive_ACK+0x2e>
mov    $0x1,%edi
call   1050 <usleep@plt>
jmp    1138 <drv_D4D_receive_ACK+0x8>
movsbl -0x1(%rbp),%eax
cmp    $0x15,%eax
jne    117e <drv_D4D_receive_ACK+0x4e>
xor    %edi,%edi
lea    0xe8c(%rip),%rsi
call   1030 <message@plt>
jmp    119e <drv_D4D_receive_ACK+0x6e>
movsbl -0x1(%rbp),%eax
cmp    $0x6,%eax
je     1199 <drv_D4D_receive_ACK+0x69>
xor    %edi,%edi
lea    0xe71(%rip),%rsi
call   1030 <message@plt>
jmp    119e <drv_D4D_receive_ACK+0x6e>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<drv_D4D_receive_ACK>:
push   %rbx
sub    $0x10,%rsp
lea    0xf(%rsp),%rdi
mov    $0x1,%esi
call   1040 <drv_generic_serial_read@plt>
cmp    $0x1,%eax
je     116c <drv_D4D_receive_ACK+0x3c>
lea    0xf(%rsp),%rbx
xchg   %ax,%ax
mov    $0x1,%edi
call   1050 <usleep@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
call   1040 <drv_generic_serial_read@plt>
cmp    $0x1,%eax
jne    1150 <drv_D4D_receive_ACK+0x20>
mov    0xf(%rsp),%al
cmp    $0x6,%al
je     118f <drv_D4D_receive_ACK+0x5f>
cmp    $0x15,%al
jne    1181 <drv_D4D_receive_ACK+0x51>
lea    0xe81(%rip),%rsi
jmp    1188 <drv_D4D_receive_ACK+0x58>
lea    0xe7d(%rip),%rsi
xor    %edi,%edi
call   1030 <message@plt>
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [5 x i8] c"NAK!\00"
@.str.1 = [8 x i8] c"no ACK!\00"
define void @drv_D4D_receive_ACK() {
%1 = alloca [1 x i8]
br label %2
2: ; preds = %6, %0
%3 = getelementptr inbounds [1 x i8], [1 x i8]* %1, i64 0, i64 0
%4 = call i32 @drv_generic_serial_read(i8* %3, i32 1)
%5 = icmp ne i32 %4, 1
br i1 %5, label %6, label %8
6: ; preds = %2
%7 = call i32 @usleep(i32 1)
br label %2
8: ; preds = %2
%9 = getelementptr inbounds [1 x i8], [1 x i8]* %1, i64 0, i64 0
%10 = load i8, i8* %9
%11 = sext i8 %10 to i32
%12 = icmp eq i32 %11, 21
br i1 %12, label %13, label %15
13: ; preds = %8
%14 = call i32 @message(i32 0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %23
15: ; preds = %8
%16 = getelementptr inbounds [1 x i8], [1 x i8]* %1, i64 0, i64 0
%17 = load i8, i8* %16
%18 = sext i8 %17 to i32
%19 = icmp ne i32 %18, 6
br i1 %19, label %20, label %22
20: ; preds = %15
%21 = call i32 @message(i32 0, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
br label %22
22: ; preds = %20, %15
br label %23
23: ; preds = %22, %13
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c"NAK!\00"
@.str.1 = [8 x i8] c"no ACK!\00"
define void @drv_D4D_receive_ACK() {
%1 = alloca [1 x i8]
%2 = getelementptr inbounds [1 x i8], [1 x i8]* %1, i64 0, i64 0
%3 = call i32 @drv_generic_serial_read(i8* %2, i32 1)
%4 = icmp eq i32 %3, 1
br i1 %4, label %9, label %5
5: ; preds = %0, %5
%6 = call i32 @usleep(i32 1)
%7 = call i32 @drv_generic_serial_read(i8* %2, i32 1)
%8 = icmp eq i32 %7, 1
br i1 %8, label %9, label %5
9: ; preds = %5, %0
%10 = load i8, i8* %2
switch i8 %10, label %11 [
i8 21, label %12
i8 6, label %15
]
11: ; preds = %9
br label %12
12: ; preds = %9, %11
%13 = phi i8* [ getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), %11 ], [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), %9 ]
%14 = call i32 @message(i32 0, i8* %13)
br label %15
15: ; preds = %12, %9
ret void
}