#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 scalar_t__ uint8_t;

/* Variables and functions */
int SPI_Read(int);
int /*<<< orphan*/ SPI_Write(int, int);
int /*<<< orphan*/ close(scalar_t__);
uint8_t listen(uint8_t sock) {
  uint8_t retval = 0;
  if (sock != 0)
    return retval;
  if (SPI_Read(0x0403) == 0x13) {
    SPI_Write(0x0401, 0x02);
    while (SPI_Read(0x0401))
      ;
    if (SPI_Read(0x0403) == 0x14)
      retval = 1;
    else
      close(sock);
  }
  return retval;
}


x86 assembly (clang, -O0):
<listen>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     115c <listen+0x2c>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11cc <listen+0x9c>
mov    $0x403,%edi
call   1030 <SPI_Read@plt>
cmp    $0x13,%eax
jne    11c4 <listen+0x94>
mov    $0x401,%edi
mov    $0x2,%esi
call   1050 <SPI_Write@plt>
mov    $0x401,%edi
call   1030 <SPI_Read@plt>
cmp    $0x0,%eax
je     1196 <listen+0x66>
jmp    117e <listen+0x4e>
mov    $0x403,%edi
call   1030 <SPI_Read@plt>
cmp    $0x14,%eax
jne    11b6 <listen+0x86>
movq   $0x1,-0x18(%rbp)
jmp    11bf <listen+0x8f>
mov    -0x10(%rbp),%rdi
call   1040 <close@plt>
jmp    11c4 <listen+0x94>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<listen>:
push   %rbx
test   %rdi,%rdi
jne    118d <listen+0x5d>
mov    $0x403,%edi
call   1030 <SPI_Read@plt>
cmp    $0x13,%eax
jne    118d <listen+0x5d>
mov    $0x401,%edi
mov    $0x2,%esi
call   1050 <SPI_Write@plt>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    $0x401,%edi
call   1030 <SPI_Read@plt>
test   %eax,%eax
jne    1160 <listen+0x30>
mov    $0x403,%edi
call   1030 <SPI_Read@plt>
mov    $0x1,%ebx
cmp    $0x14,%eax
je     118f <listen+0x5f>
xor    %ebx,%ebx
xor    %edi,%edi
call   1040 <close@plt>
jmp    118f <listen+0x5f>
xor    %ebx,%ebx
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
define i64 @listen(i64 %0) {
%2 = alloca i64
%3 = alloca i64
%4 = alloca i64
store i64 %0, i64* %3
store i64 0, i64* %4
%5 = load i64, i64* %3
%6 = icmp ne i64 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %1
%8 = load i64, i64* %4
store i64 %8, i64* %2
br label %28
9: ; preds = %1
%10 = call i32 @SPI_Read(i32 1027)
%11 = icmp eq i32 %10, 19
br i1 %11, label %12, label %26
12: ; preds = %9
%13 = call i32 @SPI_Write(i32 1025, i32 2)
br label %14
14: ; preds = %17, %12
%15 = call i32 @SPI_Read(i32 1025)
%16 = icmp ne i32 %15, 0
br i1 %16, label %17, label %18
17: ; preds = %14
br label %14
18: ; preds = %14
%19 = call i32 @SPI_Read(i32 1027)
%20 = icmp eq i32 %19, 20
br i1 %20, label %21, label %22
21: ; preds = %18
store i64 1, i64* %4
br label %25
22: ; preds = %18
%23 = load i64, i64* %3
%24 = call i32 @close(i64 %23)
br label %25
25: ; preds = %22, %21
br label %26
26: ; preds = %25, %9
%27 = load i64, i64* %4
store i64 %27, i64* %2
br label %28
28: ; preds = %26, %7
%29 = load i64, i64* %2
ret i64 %29
}

LLVM IR (-O2):
define i64 @listen(i64 %0) {
%2 = icmp eq i64 %0, 0
br i1 %2, label %3, label %16
3: ; preds = %1
%4 = tail call i32 @SPI_Read(i32 1027)
%5 = icmp eq i32 %4, 19
br i1 %5, label %6, label %16
6: ; preds = %3
%7 = tail call i32 @SPI_Write(i32 1025, i32 2)
br label %8
8: ; preds = %8, %6
%9 = tail call i32 @SPI_Read(i32 1025)
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %8
11: ; preds = %8
%12 = tail call i32 @SPI_Read(i32 1027)
%13 = icmp eq i32 %12, 20
br i1 %13, label %16, label %14
14: ; preds = %11
%15 = tail call i32 @close(i64 0)
br label %16
16: ; preds = %3, %14, %11, %1
%17 = phi i64 [ 0, %1 ], [ 0, %14 ], [ 0, %3 ], [ 1, %11 ]
ret i64 %17
}