#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 ConnexRead(int, int *, unsigned char **, int *, int *,
               int /*<<< orphan*/ *);
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 flag, status, 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 {
    status = ConnexRead(1, &sock, &buffer, &size, &flag, NULL);
    if (status == -1)
      break;
    if (flag == 1)
      fprintf(stderr, "Message:%s\n", buffer);
  } while (1);
  fprintf(stderr, "Connection failed.\n");
  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,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x38(%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    $0x1,%edi
lea    -0x14(%rbp),%rsi
lea    -0x38(%rbp),%rdx
lea    -0x2c(%rbp),%rcx
lea    -0x24(%rbp),%r8
xor    %eax,%eax
mov    %eax,%r9d
call   1050 <ConnexRead@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0xffffffff,-0x28(%rbp)
jne    1234 <main+0xe4>
jmp    126d <main+0x11d>
cmpl   $0x1,-0x24(%rbp)
jne    1259 <main+0x109>
mov    0x2d9b(%rip),%rax
mov    (%rax),%edi
mov    -0x38(%rbp),%rdx
lea    0xdec(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
jmp    125e <main+0x10e>
mov    $0x1,%al
test   $0x1,%al
jne    1203 <main+0xb3>
jmp    126d <main+0x11d>
mov    0x2d6c(%rip),%rax
mov    (%rax),%edi
lea    0xdcd(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
movq   $0x0,0x8(%rsp)
cmp    $0x2,%edi
jle    1240 <main+0xf0>
mov    0x8(%rsi),%rbx
mov    0x10(%rsi),%rdi
call   1060 <atoi@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1030 <ConnexOpen@plt>
mov    %eax,0x4(%rsp)
test   %eax,%eax
js     1252 <main+0x102>
lea    0x4(%rsp),%rsi
lea    0x8(%rsp),%rdx
lea    0x14(%rsp),%rcx
mov    %rsp,%r8
mov    $0x1,%edi
xor    %r9d,%r9d
call   1050 <ConnexRead@plt>
cmp    $0xffffffff,%eax
je     1218 <main+0xc8>
mov    0x2e22(%rip),%rbp
lea    0xe79(%rip),%r14
lea    0x4(%rsp),%r15
lea    0x8(%rsp),%r12
lea    0x14(%rsp),%r13
mov    %rsp,%rbx
jmp    11fe <main+0xae>
nopl   0x0(%rax)
mov    $0x1,%edi
mov    %r15,%rsi
mov    %r12,%rdx
mov    %r13,%rcx
mov    %rbx,%r8
xor    %r9d,%r9d
call   1050 <ConnexRead@plt>
cmp    $0xffffffff,%eax
je     1218 <main+0xc8>
cmpl   $0x1,(%rsp)
jne    11e0 <main+0x90>
mov    0x0(%rbp),%edi
mov    0x8(%rsp),%rdx
mov    %r14,%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
jmp    11e0 <main+0x90>
mov    0x2dc1(%rip),%rax
mov    (%rax),%edi
lea    0xe22(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d99(%rip),%rax
mov    (%rax),%edi
lea    0xdb0(%rip),%rsi
jmp    1262 <main+0x112>
mov    0x2d87(%rip),%rax
mov    (%rax),%edi
lea    0xdc0(%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 = [12 x i8] c"Message:%s\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 i32
%11 = alloca i32
%12 = 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** %12
%13 = load i32, i32* %4
%14 = icmp slt i32 %13, 3
br i1 %14, label %15, label %19
15: ; preds = %2
%16 = load i32, i32* @stderr
%17 = call i32 (i32, i8*, ...) @fprintf(i32 %16, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
%18 = call i32 @exit(i32 -1)
unreachable
19: ; preds = %2
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
store i8* %22, i8** %8
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 2
%25 = load i8*, i8** %24
%26 = call i32 @atoi(i8* %25)
store i32 %26, i32* %7
%27 = load i8*, i8** %8
%28 = load i32, i32* %7
%29 = call i32 @ConnexOpen(i8* %27, i32 %28)
store i32 %29, i32* %6
%30 = load i32, i32* %6
%31 = icmp slt i32 %30, 0
br i1 %31, label %32, label %36
32: ; preds = %19
%33 = load i32, i32* @stderr
%34 = call i32 (i32, i8*, ...) @fprintf(i32 %33, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
%35 = call i32 @exit(i32 -1)
unreachable
36: ; preds = %19
br label %37
37: ; preds = %50, %36
%38 = call i32 @ConnexRead(i32 1, i32* %6, i8** %12, i32* %11, i32* %9, i32* null)
store i32 %38, i32* %10
%39 = load i32, i32* %10
%40 = icmp eq i32 %39, -1
br i1 %40, label %41, label %42
41: ; preds = %37
br label %51
42: ; preds = %37
%43 = load i32, i32* %9
%44 = icmp eq i32 %43, 1
br i1 %44, label %45, label %49
45: ; preds = %42
%46 = load i32, i32* @stderr
%47 = load i8*, i8** %12
%48 = call i32 (i32, i8*, ...) @fprintf(i32 %46, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i8* %47)
br label %49
49: ; preds = %45, %42
br label %50
50: ; preds = %49
br i1 true, label %37, label %51
51: ; preds = %50, %41
%52 = load i32, i32* @stderr
%53 = call i32 (i32, i8*, ...) @fprintf(i32 %52, 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 = [12 x i8] c"Message:%s\0A\00"
@.str.3 = [20 x i8] c"Connection failed.\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = bitcast i32* %3 to i8*
%8 = bitcast i32* %4 to i8*
%9 = bitcast i32* %5 to i8*
%10 = bitcast i8** %6 to i8*
store i8* null, i8** %6
%11 = icmp slt i32 %0, 3
br i1 %11, label %12, label %16
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = tail call i32 (i32, i8*, ...) @fprintf(i32 %13, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
%15 = tail call i32 @exit(i32 -1)
unreachable
16: ; preds = %2
%17 = getelementptr inbounds i8*, i8** %1, i64 1
%18 = load i8*, i8** %17
%19 = getelementptr inbounds i8*, i8** %1, i64 2
%20 = load i8*, i8** %19
%21 = tail call i32 @atoi(i8* %20)
%22 = tail call i32 @ConnexOpen(i8* %18, i32 %21)
store i32 %22, i32* %3
%23 = icmp slt i32 %22, 0
br i1 %23, label %27, label %24
24: ; preds = %16
%25 = call i32 @ConnexRead(i32 1, i32* %3, i8** %6, i32* %5, i32* %4, i32* null)
%26 = icmp eq i32 %25, -1
br i1 %26, label %41, label %31
27: ; preds = %16
%28 = load i32, i32* @stderr
%29 = tail call i32 (i32, i8*, ...) @fprintf(i32 %28, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
%30 = tail call i32 @exit(i32 -1)
unreachable
31: ; preds = %24, %38
%32 = load i32, i32* %4
%33 = icmp eq i32 %32, 1
br i1 %33, label %34, label %38
34: ; preds = %31
%35 = load i32, i32* @stderr
%36 = load i8*, i8** %6
%37 = call i32 (i32, i8*, ...) @fprintf(i32 %35, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i8* %36)
br label %38
38: ; preds = %31, %34
%39 = call i32 @ConnexRead(i32 1, i32* %3, i8** %6, i32* %5, i32* %4, i32* null)
%40 = icmp eq i32 %39, -1
br i1 %40, label %41, label %31
41: ; preds = %38, %24
%42 = load i32, i32* @stderr
%43 = call i32 (i32, i8*, ...) @fprintf(i32 %42, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
ret i32 0
}