#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 ConnexOpen(char *, int);
int ConnexReadIP(int, unsigned char **);
int atoi(char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  int sock;
  int port = 0;
  char *host = NULL;
  int size;
  unsigned char *buffer = NULL;
  if (argc < 3) {
    fprintf(stderr, "host and port must be specified.\n");
    exit(-1);
  }
  host = argv[1];
  port = atoi(argv[2]);
  sock = ConnexOpen(host, port);
  if (sock < 0) {
    fprintf(stderr, "Could not connect to host.\n");
    exit(-1);
  }
  do {
    size = ConnexReadIP(sock, &buffer);
    if (size == -1)
      break;
    fprintf(stderr, "Message size:%d\n", size);
  } while (1);
  fprintf(stderr, "Connection failed.\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x30(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    11a8 <main+0x58>
mov    0x2e52(%rip),%rax
mov    (%rax),%edi
lea    0xe69(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x18(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%esi
call   1030 <ConnexOpen@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    11fe <main+0xae>
mov    0x2dfc(%rip),%rax
mov    (%rax),%edi
lea    0xe35(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>
jmp    1203 <main+0xb3>
mov    -0x14(%rbp),%edi
lea    -0x30(%rbp),%rsi
call   1050 <ConnexReadIP@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0xffffffff,-0x24(%rbp)
jne    1221 <main+0xd1>
jmp    124a <main+0xfa>
mov    0x2db8(%rip),%rax
mov    (%rax),%edi
mov    -0x24(%rbp),%edx
lea    0xe0a(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    $0x1,%al
test   $0x1,%al
jne    1203 <main+0xb3>
jmp    124a <main+0xfa>
mov    0x2d8f(%rip),%rax
mov    (%rax),%edi
lea    0xdf5(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
movq   $0x0,(%rsp)
cmp    $0x2,%edi
jle    11f4 <main+0xa4>
mov    0x8(%rsi),%rbx
mov    0x10(%rsi),%rdi
call   1060 <atoi@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1030 <ConnexOpen@plt>
test   %eax,%eax
js     1206 <main+0xb6>
mov    %eax,%ebx
mov    %rsp,%rsi
mov    %eax,%edi
call   1050 <ConnexReadIP@plt>
cmp    $0xffffffff,%eax
je     11cf <main+0x7f>
mov    0x2e40(%rip),%r12
lea    0xe97(%rip),%r14
mov    %rsp,%r15
nopw   0x0(%rax,%rax,1)
mov    (%r12),%edi
mov    %r14,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    %ebx,%edi
mov    %r15,%rsi
call   1050 <ConnexReadIP@plt>
cmp    $0xffffffff,%eax
jne    11b0 <main+0x60>
mov    0x2e0a(%rip),%rax
mov    (%rax),%edi
lea    0xe70(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    0x2de5(%rip),%rax
mov    (%rax),%edi
lea    0xdfc(%rip),%rsi
jmp    1216 <main+0xc6>
mov    0x2dd3(%rip),%rax
mov    (%rax),%edi
lea    0xe0c(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [34 x i8] c"host and port must be specified.\0A\00"
@.str.1 = [28 x i8] c"Could not connect to host.\0A\00"
@.str.2 = [17 x i8] c"Message size:%d\0A\00"
@.str.3 = [20 x i8] c"Connection failed.\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%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* %7
store i8* null, i8** %8
store i8* null, i8** %10
%11 = load i32, i32* %4
%12 = icmp slt i32 %11, 3
br i1 %12, label %13, label %17
13: ; preds = %2
%14 = load i32, i32* @stderr
%15 = call i32 (i32, i8*, ...) @fprintf(i32 %14, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
%16 = call i32 @exit(i32 -1)
unreachable
17: ; preds = %2
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
store i8* %20, i8** %8
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 2
%23 = load i8*, i8** %22
%24 = call i32 @atoi(i8* %23)
store i32 %24, i32* %7
%25 = load i8*, i8** %8
%26 = load i32, i32* %7
%27 = call i32 @ConnexOpen(i8* %25, i32 %26)
store i32 %27, i32* %6
%28 = load i32, i32* %6
%29 = icmp slt i32 %28, 0
br i1 %29, label %30, label %34
30: ; preds = %17
%31 = load i32, i32* @stderr
%32 = call i32 (i32, i8*, ...) @fprintf(i32 %31, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
%33 = call i32 @exit(i32 -1)
unreachable
34: ; preds = %17
br label %35
35: ; preds = %45, %34
%36 = load i32, i32* %6
%37 = call i32 @ConnexReadIP(i32 %36, i8** %10)
store i32 %37, i32* %9
%38 = load i32, i32* %9
%39 = icmp eq i32 %38, -1
br i1 %39, label %40, label %41
40: ; preds = %35
br label %46
41: ; preds = %35
%42 = load i32, i32* @stderr
%43 = load i32, i32* %9
%44 = call i32 (i32, i8*, ...) @fprintf(i32 %42, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i32 %43)
br label %45
45: ; preds = %41
br i1 true, label %35, label %46
46: ; preds = %45, %40
%47 = load i32, i32* @stderr
%48 = call i32 (i32, i8*, ...) @fprintf(i32 %47, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [34 x i8] c"host and port must be specified.\0A\00"
@.str.1 = [28 x i8] c"Could not connect to host.\0A\00"
@.str.2 = [17 x i8] c"Message size:%d\0A\00"
@.str.3 = [20 x i8] c"Connection failed.\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i8*
%4 = bitcast i8** %3 to i8*
store i8* null, i8** %3
%5 = icmp slt i32 %0, 3
br i1 %5, label %6, label %10
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = tail call i32 (i32, i8*, ...) @fprintf(i32 %7, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
%9 = tail call i32 @exit(i32 -1)
unreachable
10: ; preds = %2
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = getelementptr inbounds i8*, i8** %1, i64 2
%14 = load i8*, i8** %13
%15 = tail call i32 @atoi(i8* %14)
%16 = tail call i32 @ConnexOpen(i8* %12, i32 %15)
%17 = icmp slt i32 %16, 0
br i1 %17, label %21, label %18
18: ; preds = %10
%19 = call i32 @ConnexReadIP(i32 %16, i8** %3)
%20 = icmp eq i32 %19, -1
br i1 %20, label %31, label %25
21: ; preds = %10
%22 = load i32, i32* @stderr
%23 = tail call i32 (i32, i8*, ...) @fprintf(i32 %22, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
%24 = tail call i32 @exit(i32 -1)
unreachable
25: ; preds = %18, %25
%26 = phi i32 [ %29, %25 ], [ %19, %18 ]
%27 = load i32, i32* @stderr
%28 = call i32 (i32, i8*, ...) @fprintf(i32 %27, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i32 %26)
%29 = call i32 @ConnexReadIP(i32 %16, i8** %3)
%30 = icmp eq i32 %29, -1
br i1 %30, label %31, label %25
31: ; preds = %25, %18
%32 = load i32, i32* @stderr
%33 = call i32 (i32, i8*, ...) @fprintf(i32 %32, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
ret i32 0
}