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


x86 assembly (clang, -O0):
<connect>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0xa,-0xc(%rbp)
mov    $0x0,%al
call   1060 <open_port_default@plt>
cmp    $0x0,%rax
je     116c <connect+0x2c>
movl   $0x1,-0x4(%rbp)
jmp    11e4 <connect+0xa4>
jmp    1171 <connect+0x31>
mov    $0x5,%edi
call   1040 <put_byte@plt>
mov    $0x0,%al
call   1030 <get_byte@plt>
mov    %eax,-0x8(%rbp)
xor    %eax,%eax
cmpl   $0x6,-0x8(%rbp)
mov    %al,-0xd(%rbp)
je     11b5 <connect+0x75>
xor    %eax,%eax
cmpl   $0xfffffffd,-0x8(%rbp)
mov    %al,-0xd(%rbp)
je     11b5 <connect+0x75>
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
cmp    $0x0,%eax
setne  %al
mov    %al,-0xd(%rbp)
mov    -0xd(%rbp),%al
test   $0x1,%al
jne    1171 <connect+0x31>
cmpl   $0x6,-0x8(%rbp)
je     11dd <connect+0x9d>
mov    $0x0,%al
call   1050 <close_port_reset_state@plt>
movl   $0x1,-0x4(%rbp)
jmp    11e4 <connect+0xa4>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<connect>:
push   %rbx
xor    %ebx,%ebx
xor    %eax,%eax
call   1060 <open_port_default@plt>
test   %rax,%rax
jne    129d <connect+0x15d>
mov    $0x5,%edi
call   1040 <put_byte@plt>
xor    %eax,%eax
call   1030 <get_byte@plt>
cmp    $0xfffffffd,%eax
je     1296 <connect+0x156>
cmp    $0x6,%eax
je     12a2 <connect+0x162>
mov    $0x5,%edi
call   1040 <put_byte@plt>
xor    %ebx,%ebx
xor    %eax,%eax
call   1030 <get_byte@plt>
cmp    $0xfffffffd,%eax
je     1296 <connect+0x156>
cmp    $0x6,%eax
je     12a2 <connect+0x162>
mov    $0x5,%edi
call   1040 <put_byte@plt>
xor    %ebx,%ebx
xor    %eax,%eax
call   1030 <get_byte@plt>
cmp    $0xfffffffd,%eax
je     1296 <connect+0x156>
cmp    $0x6,%eax
je     12a2 <connect+0x162>
mov    $0x5,%edi
call   1040 <put_byte@plt>
xor    %ebx,%ebx
xor    %eax,%eax
call   1030 <get_byte@plt>
cmp    $0xfffffffd,%eax
je     1296 <connect+0x156>
cmp    $0x6,%eax
je     12a2 <connect+0x162>
mov    $0x5,%edi
call   1040 <put_byte@plt>
xor    %ebx,%ebx
xor    %eax,%eax
call   1030 <get_byte@plt>
cmp    $0xfffffffd,%eax
je     1296 <connect+0x156>
cmp    $0x6,%eax
je     12a2 <connect+0x162>
mov    $0x5,%edi
call   1040 <put_byte@plt>
xor    %ebx,%ebx
xor    %eax,%eax
call   1030 <get_byte@plt>
cmp    $0xfffffffd,%eax
je     1296 <connect+0x156>
cmp    $0x6,%eax
je     12a2 <connect+0x162>
mov    $0x5,%edi
call   1040 <put_byte@plt>
xor    %ebx,%ebx
xor    %eax,%eax
call   1030 <get_byte@plt>
cmp    $0xfffffffd,%eax
je     1296 <connect+0x156>
cmp    $0x6,%eax
je     12a2 <connect+0x162>
mov    $0x5,%edi
call   1040 <put_byte@plt>
xor    %ebx,%ebx
xor    %eax,%eax
call   1030 <get_byte@plt>
cmp    $0xfffffffd,%eax
je     1296 <connect+0x156>
cmp    $0x6,%eax
je     12a2 <connect+0x162>
mov    $0x5,%edi
call   1040 <put_byte@plt>
xor    %ebx,%ebx
xor    %eax,%eax
call   1030 <get_byte@plt>
cmp    $0xfffffffd,%eax
je     1296 <connect+0x156>
cmp    $0x6,%eax
je     12a2 <connect+0x162>
mov    $0x5,%edi
call   1040 <put_byte@plt>
xor    %ebx,%ebx
xor    %eax,%eax
call   1030 <get_byte@plt>
cmp    $0x6,%eax
je     12a2 <connect+0x162>
xor    %eax,%eax
call   1050 <close_port_reset_state@plt>
mov    $0x1,%ebx
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
define i32 @connect() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
store i32 10, i32* %3
%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 %29
7: ; preds = %0
br label %8
8: ; preds = %21, %7
%9 = call i32 @put_byte(i32 5)
%10 = call i32 (...) @get_byte()
store i32 %10, i32* %2
br label %11
11: ; preds = %8
%12 = load i32, i32* %2
%13 = icmp ne i32 %12, 6
br i1 %13, label %14, label %21
14: ; preds = %11
%15 = load i32, i32* %2
%16 = icmp ne i32 %15, -3
br i1 %16, label %17, label %21
17: ; preds = %14
%18 = load i32, i32* %3
%19 = add nsw i32 %18, -1
store i32 %19, i32* %3
%20 = icmp ne i32 %19, 0
br label %21
21: ; preds = %17, %14, %11
%22 = phi i1 [ false, %14 ], [ false, %11 ], [ %20, %17 ]
br i1 %22, label %8, label %23
23: ; preds = %21
%24 = load i32, i32* %2
%25 = icmp ne i32 %24, 6
br i1 %25, label %26, label %28
26: ; preds = %23
%27 = call i32 (...) @close_port_reset_state()
store i32 1, i32* %1
br label %29
28: ; preds = %23
store i32 0, i32* %1
br label %29
29: ; preds = %28, %26, %6
%30 = load i32, i32* %1
ret i32 %30
}

LLVM IR (-O2):
define i32 @connect() {
%1 = tail call i64 (...) @open_port_default()
%2 = icmp eq i64 %1, 0
br i1 %2, label %3, label %36
3: ; preds = %0
%4 = tail call i32 @put_byte(i32 5)
%5 = tail call i32 (...) @get_byte()
switch i32 %5, label %6 [
i32 6, label %36
i32 -3, label %34
]
6: ; preds = %3
%7 = tail call i32 @put_byte(i32 5)
%8 = tail call i32 (...) @get_byte()
switch i32 %8, label %9 [
i32 6, label %36
i32 -3, label %34
]
9: ; preds = %6
%10 = tail call i32 @put_byte(i32 5)
%11 = tail call i32 (...) @get_byte()
switch i32 %11, label %12 [
i32 6, label %36
i32 -3, label %34
]
12: ; preds = %9
%13 = tail call i32 @put_byte(i32 5)
%14 = tail call i32 (...) @get_byte()
switch i32 %14, label %15 [
i32 6, label %36
i32 -3, label %34
]
15: ; preds = %12
%16 = tail call i32 @put_byte(i32 5)
%17 = tail call i32 (...) @get_byte()
switch i32 %17, label %18 [
i32 6, label %36
i32 -3, label %34
]
18: ; preds = %15
%19 = tail call i32 @put_byte(i32 5)
%20 = tail call i32 (...) @get_byte()
switch i32 %20, label %21 [
i32 6, label %36
i32 -3, label %34
]
21: ; preds = %18
%22 = tail call i32 @put_byte(i32 5)
%23 = tail call i32 (...) @get_byte()
switch i32 %23, label %24 [
i32 6, label %36
i32 -3, label %34
]
24: ; preds = %21
%25 = tail call i32 @put_byte(i32 5)
%26 = tail call i32 (...) @get_byte()
switch i32 %26, label %27 [
i32 6, label %36
i32 -3, label %34
]
27: ; preds = %24
%28 = tail call i32 @put_byte(i32 5)
%29 = tail call i32 (...) @get_byte()
switch i32 %29, label %30 [
i32 6, label %36
i32 -3, label %34
]
30: ; preds = %27
%31 = tail call i32 @put_byte(i32 5)
%32 = tail call i32 (...) @get_byte()
%33 = icmp eq i32 %32, 6
br i1 %33, label %36, label %34
34: ; preds = %30, %3, %6, %9, %12, %15, %18, %21, %24, %27
%35 = tail call i32 (...) @close_port_reset_state()
br label %36
36: ; preds = %30, %3, %6, %9, %12, %15, %18, %21, %24, %27, %0, %34
%37 = phi i32 [ 1, %34 ], [ 1, %0 ], [ 0, %30 ], [ 0, %27 ], [ 0, %24 ], [ 0, %21 ], [ 0, %18 ], [ 0, %15 ], [ 0, %12 ], [ 0, %9 ], [ 0, %6 ], [ 0, %3 ]
ret i32 %37
}