#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*/ clear_buffer();
int /*<<< orphan*/ close_port_reset_state();
int /*<<< orphan*/ flush_comm();
int get_byte();
scalar_t__ open_port_default();
int /*<<< orphan*/ put_byte(int);
int accept_connection(void) {
  int i = 10;
  if (open_port_default())
    return 1;
  while (i--) {
    int c = get_byte();
    if (c == 5) {
      clear_buffer();
      put_byte(6);
      flush_comm();
      return 0;
    }
    if (c == (-3))
      break;
  }
  close_port_reset_state();
  return 1;
}


x86 assembly (clang, -O0):
<accept_connection>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0xa,-0x8(%rbp)
mov    $0x0,%al
call   1080 <open_port_default@plt>
cmp    $0x0,%rax
je     118c <accept_connection+0x2c>
movl   $0x1,-0x4(%rbp)
jmp    11ff <accept_connection+0x9f>
jmp    1191 <accept_connection+0x31>
mov    -0x8(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x8(%rbp)
cmp    $0x0,%eax
je     11f1 <accept_connection+0x91>
mov    $0x0,%al
call   1040 <get_byte@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x5,-0xc(%rbp)
jne    11dd <accept_connection+0x7d>
mov    $0x0,%al
call   1030 <clear_buffer@plt>
mov    $0x6,%edi
call   1050 <put_byte@plt>
mov    $0x0,%al
call   1060 <flush_comm@plt>
movl   $0x0,-0x4(%rbp)
jmp    11ff <accept_connection+0x9f>
cmpl   $0xfffffffd,-0xc(%rbp)
jne    11ec <accept_connection+0x8c>
jmp    11f1 <accept_connection+0x91>
jmp    1191 <accept_connection+0x31>
mov    $0x0,%al
call   1070 <close_port_reset_state@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<accept_connection>:
push   %rbp
push   %rbx
push   %rax
xor    %eax,%eax
call   1080 <open_port_default@plt>
mov    $0x1,%ebx
test   %rax,%rax
jne    11b8 <accept_connection+0x58>
mov    $0xfffffff5,%ebp
nopl   0x0(%rax)
inc    %ebp
je     11b1 <accept_connection+0x51>
xor    %eax,%eax
call   1040 <get_byte@plt>
cmp    $0xfffffffd,%eax
je     11b1 <accept_connection+0x51>
cmp    $0x5,%eax
jne    1180 <accept_connection+0x20>
xor    %ebx,%ebx
xor    %eax,%eax
call   1030 <clear_buffer@plt>
mov    $0x6,%edi
call   1050 <put_byte@plt>
xor    %eax,%eax
call   1060 <flush_comm@plt>
jmp    11b8 <accept_connection+0x58>
xor    %eax,%eax
call   1070 <close_port_reset_state@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @accept_connection() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
store i32 10, i32* %2
%4 = call i64 (...) @open_port_default()
%5 = icmp ne i64 %4, 0
br i1 %5, label %6, label %7
6: ; preds = %0
store i32 1, i32* %1
br label %27
7: ; preds = %0
br label %8
8: ; preds = %24, %7
%9 = load i32, i32* %2
%10 = add nsw i32 %9, -1
store i32 %10, i32* %2
%11 = icmp ne i32 %9, 0
br i1 %11, label %12, label %25
12: ; preds = %8
%13 = call i32 (...) @get_byte()
store i32 %13, i32* %3
%14 = load i32, i32* %3
%15 = icmp eq i32 %14, 5
br i1 %15, label %16, label %20
16: ; preds = %12
%17 = call i32 (...) @clear_buffer()
%18 = call i32 @put_byte(i32 6)
%19 = call i32 (...) @flush_comm()
store i32 0, i32* %1
br label %27
20: ; preds = %12
%21 = load i32, i32* %3
%22 = icmp eq i32 %21, -3
br i1 %22, label %23, label %24
23: ; preds = %20
br label %25
24: ; preds = %20
br label %8
25: ; preds = %23, %8
%26 = call i32 (...) @close_port_reset_state()
store i32 1, i32* %1
br label %27
27: ; preds = %25, %16, %6
%28 = load i32, i32* %1
ret i32 %28
}

LLVM IR (-O2):
define i32 @accept_connection() {
%1 = tail call i64 (...) @open_port_default()
%2 = icmp eq i64 %1, 0
br i1 %2, label %3, label %15
3: ; preds = %0, %6
%4 = phi i32 [ %7, %6 ], [ 10, %0 ]
%5 = icmp eq i32 %4, 0
br i1 %5, label %13, label %6
6: ; preds = %3
%7 = add nsw i32 %4, -1
%8 = tail call i32 (...) @get_byte()
switch i32 %8, label %3 [
i32 5, label %9
i32 -3, label %13
]
9: ; preds = %6
%10 = tail call i32 (...) @clear_buffer()
%11 = tail call i32 @put_byte(i32 6)
%12 = tail call i32 (...) @flush_comm()
br label %15
13: ; preds = %6, %3
%14 = tail call i32 (...) @close_port_reset_state()
br label %15
15: ; preds = %9, %0, %13
%16 = phi i32 [ 1, %13 ], [ 1, %0 ], [ 0, %9 ]
ret i32 %16
}