#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 */
typedef struct TYPE_2__ TYPE_1__;

/* Type definitions */
struct TYPE_2__ {
  int /*<<< orphan*/ s_addr;
};
struct sockaddr_in {
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ sin;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ IPPROTO_TCP;
int /*<<< orphan*/ PF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ capture();
int connect(int, struct sockaddr *, int);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ inet_addr(char *);
int read(int, char *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  int sock;
  struct sockaddr_in sin;
  char c;
  int cnt = 0;
  char *host;
  if (argc == 1)
    host = "192.168.161.44";
  else
    host = argv[1];
  sock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
  if (sock == -1)
    return 1;
  sin.sin_family = AF_INET;
  sin.sin_port = htons(500);
  sin.sin_addr.s_addr = inet_addr(host);
  if (connect(sock, (struct sockaddr *)&sin, sizeof(sin)) == -1)
    return 1;
  for (;;) {
    switch (read(sock, &c, 1)) {
    case 0:
      if (++cnt > 10)
        return 1;
      break;
    case 1:
      if (c == '1')
        capture();
      cnt = 0;
      break;
    case -1:
      break;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x28(%rbp)
cmpl   $0x1,-0x8(%rbp)
jne    1197 <main+0x37>
lea    0xe72(%rip),%rax
mov    %rax,-0x30(%rbp)
jmp    11a3 <main+0x43>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x30(%rbp)
mov    0x2e1e(%rip),%rax
mov    (%rax),%edi
mov    0x2e1d(%rip),%rax
mov    (%rax),%esi
mov    0x2e24(%rip),%rax
mov    (%rax),%edx
call   1080 <socket@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    11dc <main+0x7c>
movl   $0x1,-0x4(%rbp)
jmp    12be <main+0x15e>
mov    0x2e05(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    $0x1f4,%edi
call   1030 <htons@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x30(%rbp),%rdi
call   1050 <inet_addr@plt>
mov    %eax,-0x20(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0xc,%edx
call   1060 <connect@plt>
cmp    $0xffffffff,%eax
jne    1227 <main+0xc7>
movl   $0x1,-0x4(%rbp)
jmp    12be <main+0x15e>
jmp    122c <main+0xcc>
mov    -0x14(%rbp),%edi
lea    -0x21(%rbp),%rsi
mov    $0x1,%edx
call   1040 <read@plt>
mov    %eax,%ecx
mov    %ecx,-0x34(%rbp)
sub    $0xffffffff,%eax
je     12b4 <main+0x154>
jmp    1250 <main+0xf0>
mov    -0x34(%rbp),%eax
test   %eax,%eax
je     1271 <main+0x111>
jmp    1260 <main+0x100>
mov    -0x34(%rbp),%eax
sub    $0x1,%eax
je     1294 <main+0x134>
jmp    12b9 <main+0x159>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
cmp    $0xa,%eax
jle    128f <main+0x12f>
movl   $0x1,-0x4(%rbp)
jmp    12be <main+0x15e>
jmp    12b9 <main+0x159>
movsbl -0x21(%rbp),%eax
cmp    $0x31,%eax
jne    12a8 <main+0x148>
mov    $0x0,%al
call   1070 <capture@plt>
movl   $0x0,-0x28(%rbp)
jmp    12b9 <main+0x159>
jmp    12b9 <main+0x159>
jmp    122c <main+0xcc>
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x20,%rsp
cmp    $0x1,%edi
jne    1177 <main+0x17>
lea    0xe8b(%rip),%r14
jmp    117b <main+0x1b>
mov    0x8(%rsi),%r14
mov    0x2e46(%rip),%rax
mov    (%rax),%edi
mov    0x2e45(%rip),%rax
mov    (%rax),%esi
mov    0x2e4c(%rip),%rax
mov    (%rax),%edx
call   1080 <socket@plt>
cmp    $0xffffffff,%eax
je     1230 <main+0xd0>
mov    %eax,%ebx
mov    0x2e3b(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x18(%rsp)
mov    $0x1f4,%edi
call   1030 <htons@plt>
mov    %eax,0x14(%rsp)
mov    %r14,%rdi
call   1050 <inet_addr@plt>
mov    %eax,0x10(%rsp)
lea    0x10(%rsp),%rsi
mov    %ebx,%edi
mov    $0xc,%edx
call   1060 <connect@plt>
cmp    $0xffffffff,%eax
je     1230 <main+0xd0>
xor    %r15d,%r15d
lea    0xf(%rsp),%r14
nopl   0x0(%rax,%rax,1)
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x1,%edx
call   1040 <read@plt>
cmp    $0x1,%eax
je     1217 <main+0xb7>
test   %eax,%eax
jne    11f0 <main+0x90>
lea    0x1(%r15),%eax
cmp    $0x9,%r15d
mov    %eax,%r15d
jle    11f0 <main+0x90>
jmp    1230 <main+0xd0>
cmpb   $0x31,0xf(%rsp)
mov    $0x0,%r15d
jne    11f0 <main+0x90>
xor    %r15d,%r15d
xor    %eax,%eax
call   1070 <capture@plt>
jmp    11f0 <main+0x90>
mov    $0x1,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [15 x i8] c"192.168.161.44\00"
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
@IPPROTO_TCP = global i32 0
@AF_INET = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca %struct.sockaddr_in
%8 = alloca i8
%9 = alloca i32
%10 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %9
%11 = load i32, i32* %4
%12 = icmp eq i32 %11, 1
br i1 %12, label %13, label %14
13: ; preds = %2
store i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8** %10
br label %18
14: ; preds = %2
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = load i8*, i8** %16
store i8* %17, i8** %10
br label %18
18: ; preds = %14, %13
%19 = load i32, i32* @PF_INET
%20 = load i32, i32* @SOCK_STREAM
%21 = load i32, i32* @IPPROTO_TCP
%22 = call i32 @socket(i32 %19, i32 %20, i32 %21)
store i32 %22, i32* %6
%23 = load i32, i32* %6
%24 = icmp eq i32 %23, -1
br i1 %24, label %25, label %26
25: ; preds = %18
store i32 1, i32* %3
br label %59
26: ; preds = %18
%27 = load i32, i32* @AF_INET
%28 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 2
store i32 %27, i32* %28
%29 = call i32 @htons(i32 500)
%30 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 1
store i32 %29, i32* %30
%31 = load i8*, i8** %10
%32 = call i32 @inet_addr(i8* %31)
%33 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 0
%34 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %33, i32 0, i32 0
store i32 %32, i32* %34
%35 = load i32, i32* %6
%36 = bitcast %struct.sockaddr_in* %7 to %struct.sockaddr*
%37 = call i32 @connect(i32 %35, %struct.sockaddr* %36, i32 12)
%38 = icmp eq i32 %37, -1
br i1 %38, label %39, label %40
39: ; preds = %26
store i32 1, i32* %3
br label %59
40: ; preds = %26
br label %41
41: ; preds = %58, %40
%42 = load i32, i32* %6
%43 = call i32 @read(i32 %42, i8* %8, i32 1)
switch i32 %43, label %58 [
i32 0, label %44
i32 1, label %50
i32 -1, label %57
]
44: ; preds = %41
%45 = load i32, i32* %9
%46 = add nsw i32 %45, 1
store i32 %46, i32* %9
%47 = icmp sgt i32 %46, 10
br i1 %47, label %48, label %49
48: ; preds = %44
store i32 1, i32* %3
br label %59
49: ; preds = %44
br label %58
50: ; preds = %41
%51 = load i8, i8* %8
%52 = sext i8 %51 to i32
%53 = icmp eq i32 %52, 49
br i1 %53, label %54, label %56
54: ; preds = %50
%55 = call i32 (...) @capture()
br label %56
56: ; preds = %54, %50
store i32 0, i32* %9
br label %58
57: ; preds = %41
br label %58
58: ; preds = %41, %57, %56, %49
br label %41
59: ; preds = %48, %39, %25
%60 = load i32, i32* %3
ret i32 %60
}

LLVM IR (-O2):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [15 x i8] c"192.168.161.44\00"
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
@IPPROTO_TCP = global i32 0
@AF_INET = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca i8
%5 = bitcast %struct.sockaddr_in* %3 to i8*
%6 = icmp eq i32 %0, 1
br i1 %6, label %10, label %7
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
br label %10
10: ; preds = %2, %7
%11 = phi i8* [ %9, %7 ], [ getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), %2 ]
%12 = load i32, i32* @PF_INET
%13 = load i32, i32* @SOCK_STREAM
%14 = load i32, i32* @IPPROTO_TCP
%15 = tail call i32 @socket(i32 %12, i32 %13, i32 %14)
%16 = icmp eq i32 %15, -1
br i1 %16, label %41, label %17
17: ; preds = %10
%18 = load i32, i32* @AF_INET
%19 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %18, i32* %19
%20 = tail call i32 @htons(i32 500)
%21 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1
store i32 %20, i32* %21
%22 = tail call i32 @inet_addr(i8* %11)
%23 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0, i32 0
store i32 %22, i32* %23
%24 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%25 = call i32 @connect(i32 %15, %struct.sockaddr* %24, i32 12)
%26 = icmp eq i32 %25, -1
br i1 %26, label %41, label %27
27: ; preds = %17, %34
%28 = phi i32 [ %35, %34 ], [ 0, %17 ]
br label %29
29: ; preds = %27, %29
%30 = call i32 @read(i32 %15, i8* %4, i32 1)
switch i32 %30, label %29 [
i32 0, label %31
i32 1, label %36
]
31: ; preds = %29
%32 = add nsw i32 %28, 1
%33 = icmp sgt i32 %28, 9
br i1 %33, label %41, label %34
34: ; preds = %31, %39, %36
%35 = phi i32 [ 0, %36 ], [ 0, %39 ], [ %32, %31 ]
br label %27
36: ; preds = %29
%37 = load i8, i8* %4
%38 = icmp eq i8 %37, 49
br i1 %38, label %39, label %34
39: ; preds = %36
%40 = call i32 (...) @capture()
br label %34
41: ; preds = %31, %17, %10
ret i32 1
}