#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 timeval {
  int tv_sec;
  scalar_t__ tv_usec;
};
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;
typedef int /*<<< orphan*/ buffer;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ IPPROTO_TCP;
int /*<<< orphan*/ PF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ close(int);
scalar_t__ connect(int, struct sockaddr *, int);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/);
int /*<<< orphan*/ htons(unsigned short);
int /*<<< orphan*/ inet_addr(char *);
char *inet_ntoa(TYPE_1__);
int /*<<< orphan*/ memset(struct sockaddr_in *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, ...);
int recv(int, char *, int, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stdout;
int main(int argc, char **argv) {
  int sock;
  struct sockaddr_in sin;
  char *serv_addr;
  unsigned short serv_port = 2222;
  char buffer[1024];
  int n, k, len;
  unsigned packets_received, packets_printed, msec;
  double bytes_received;
  struct timeval t0, now;
  if (argc != 2) {
    printf("Usage: tcp-client <server-ip-address>\n");
    return 1;
  }
  serv_addr = argv[1];
  sock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
  if (sock < 0) {
    printf("Error creating socket, aborted\n");
    return 1;
  }
  memset(&sin, 0, sizeof(sin));
  sin.sin_family = AF_INET;
  sin.sin_addr.s_addr = inet_addr(serv_addr);
  sin.sin_port = htons(serv_port);
  printf("Client started, connecting to %s\n", inet_ntoa(sin.sin_addr));
  packets_printed = 0;
  packets_received = 0;
  bytes_received = 0;
  gettimeofday(&t0, 0);
  if (connect(sock, (struct sockaddr *)&sin, sizeof(sin)) < 0) {
    printf("Error connecting, aborted\n");
    return 1;
  }
  for (;;) {
    n = recv(sock, buffer, 2, 0);
    if (n == 0) {
      printf("Connection closed by server\n");
      break;
    }
    if (n != 2) {
      printf("Error %d receiving packet length\n", n);
      break;
    }
    len = *(unsigned short *)buffer;
    if (len != sizeof(buffer)) {
      printf("<Bad packet length = %d> ", len);
      fflush(stdout);
      continue;
    }
    k = 2;
    while (k < len) {
      n = recv(sock, buffer + k, len - k, 0);
      if (n <= 0) {
        if (n < 0)
          printf("Error %d reading from socket\n", n);
        break;
      }
      k += n;
    }
    ++packets_received;
    bytes_received += len;
    if (packets_received >= packets_printed + 100) {
      packets_printed = packets_received;
      gettimeofday(&now, 0);
      msec = (now.tv_sec - t0.tv_sec) * 1000 +
             (int)(now.tv_usec - t0.tv_usec) / 1000;
      printf("Received %.3f Mbytes (%.1f kbytes/sec)\n",
             bytes_received / 1000000.0, bytes_received / msec);
    }
  }
  printf("\nClient finished\n");
  close(sock);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x470,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movw   $0x8ae,-0x2a(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11f3 <main+0x43>
lea    0xe28(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1525 <main+0x375>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x28(%rbp)
mov    0x2dc2(%rip),%rax
mov    (%rax),%edi
mov    0x2dc1(%rip),%rax
mov    (%rax),%esi
mov    0x2dc8(%rip),%rax
mov    (%rax),%edx
call   10d0 <socket@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1246 <main+0x96>
lea    0xdfc(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1525 <main+0x375>
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1080 <memset@plt>
mov    0x2d8b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    -0x28(%rbp),%rdi
call   10a0 <inet_addr@plt>
mov    %eax,-0x20(%rbp)
movzwl -0x2a(%rbp),%edi
call   1050 <htons@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x20(%rbp),%edi
call   1040 <inet_ntoa@plt>
mov    %rax,%rsi
lea    0xdc3(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x0,-0x444(%rbp)
movl   $0x0,-0x440(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x450(%rbp)
ff
lea    -0x460(%rbp),%rdi
xor    %esi,%esi
call   1070 <gettimeofday@plt>
mov    -0x14(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0xc,%edx
call   10c0 <connect@plt>
cmp    $0x0,%rax
jge    12f5 <main+0x145>
lea    0xd8f(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1525 <main+0x375>
jmp    12fa <main+0x14a>
mov    -0x14(%rbp),%edi
lea    -0x430(%rbp),%rsi
mov    $0x2,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,-0x434(%rbp)
cmpl   $0x0,-0x434(%rbp)
jne    1336 <main+0x186>
lea    0xd62(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    1508 <main+0x358>
cmpl   $0x2,-0x434(%rbp)
je     135c <main+0x1ac>
mov    -0x434(%rbp),%esi
lea    0xd59(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    1508 <main+0x358>
movzwl -0x430(%rbp),%eax
mov    %eax,-0x43c(%rbp)
movslq -0x43c(%rbp),%rax
cmp    $0x400,%rax
je     13a3 <main+0x1f3>
mov    -0x43c(%rbp),%esi
lea    0xd42(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    0x2c29(%rip),%rax
mov    (%rax),%edi
call   10b0 <fflush@plt>
jmp    12fa <main+0x14a>
movl   $0x2,-0x438(%rbp)
mov    -0x438(%rbp),%eax
cmp    -0x43c(%rbp),%eax
jge    1436 <main+0x286>
mov    -0x14(%rbp),%edi
lea    -0x430(%rbp),%rsi
movslq -0x438(%rbp),%rax
add    %rax,%rsi
mov    -0x43c(%rbp),%edx
sub    -0x438(%rbp),%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,-0x434(%rbp)
cmpl   $0x0,-0x434(%rbp)
jg     141f <main+0x26f>
cmpl   $0x0,-0x434(%rbp)
jge    141a <main+0x26a>
mov    -0x434(%rbp),%esi
lea    0xcd2(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    1436 <main+0x286>
mov    -0x434(%rbp),%eax
add    -0x438(%rbp),%eax
mov    %eax,-0x438(%rbp)
jmp    13ad <main+0x1fd>
mov    -0x440(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x440(%rbp)
cvtsi2sdl -0x43c(%rbp),%xmm0
ff
addsd  -0x450(%rbp),%xmm0
ff
movsd  %xmm0,-0x450(%rbp)
ff
mov    -0x440(%rbp),%eax
mov    -0x444(%rbp),%ecx
add    $0x64,%ecx
cmp    %ecx,%eax
jb     1503 <main+0x353>
mov    -0x440(%rbp),%eax
mov    %eax,-0x444(%rbp)
lea    -0x470(%rbp),%rdi
xor    %esi,%esi
call   1070 <gettimeofday@plt>
mov    -0x470(%rbp),%eax
mov    -0x468(%rbp),%ecx
mov    -0x460(%rbp),%esi
mov    -0x458(%rbp),%edx
sub    %esi,%eax
imul   $0x3e8,%eax,%eax
sub    %edx,%ecx
movslq %ecx,%rcx
imul   $0x10624dd3,%rcx,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x26,%rcx
add    %edx,%ecx
add    %ecx,%eax
mov    %eax,-0x448(%rbp)
movsd  -0x450(%rbp),%xmm1
ff
movsd  0xb21(%rip),%xmm2
movaps %xmm1,%xmm0
divsd  %xmm2,%xmm0
mov    -0x448(%rbp),%eax
cvtsi2sd %rax,%xmm2
divsd  %xmm2,%xmm1
lea    0xc07(%rip),%rdi
mov    $0x2,%al
call   1060 <printf@plt>
jmp    12fa <main+0x14a>
lea    0xc1c(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x14(%rbp),%edi
call   1090 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x470,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x448,%rsp
cmp    $0x2,%edi
jne    13ce <main+0x20e>
mov    0x8(%rsi),%rbp
mov    0x2de3(%rip),%rax
mov    (%rax),%edi
mov    0x2de2(%rip),%rax
mov    (%rax),%esi
mov    0x2de9(%rip),%rax
mov    (%rax),%edx
call   10e0 <socket@plt>
test   %eax,%eax
js     13e9 <main+0x229>
mov    %eax,%ebx
lea    0x10(%rsp),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1090 <memset@plt>
mov    0x2dc5(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x18(%rsp)
mov    %rbp,%rdi
call   10b0 <inet_addr@plt>
mov    %eax,0x10(%rsp)
mov    $0x8ae,%edi
call   1060 <htons@plt>
mov    %eax,0x14(%rsp)
mov    0x10(%rsp),%edi
call   1050 <inet_ntoa@plt>
lea    0xdbd(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0x30(%rsp),%rdi
xor    %esi,%esi
call   1080 <gettimeofday@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0xc,%edx
call   10d0 <connect@plt>
test   %rax,%rax
js     13f2 <main+0x232>
xorpd  %xmm0,%xmm0
movsd  %xmm0,(%rsp)
lea    0x40(%rsp),%r14
lea    0xdbe(%rip),%rbp
mov    0x2d23(%rip),%r12
xor    %r13d,%r13d
lea    0x64(%r13),%eax
mov    %eax,0xc(%rsp)
nopl   0x0(%rax,%rax,1)
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x2,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
cmp    $0x2,%eax
jne    13d7 <main+0x217>
movzwl 0x40(%rsp),%esi
cmp    $0x400,%esi
je     12ec <main+0x12c>
mov    %rbp,%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    (%r12),%edi
call   10c0 <fflush@plt>
jmp    12b0 <main+0xf0>
mov    $0x2,%r15d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movslq %r15d,%rax
lea    (%rsp,%rax,1),%rsi
add    $0x40,%rsi
mov    $0x400,%edx
sub    %eax,%edx
mov    %ebx,%edi
xor    %ecx,%ecx
call   1030 <recv@plt>
test   %eax,%eax
jle    132d <main+0x16d>
add    %eax,%r15d
cmp    $0x400,%r15d
jl     1300 <main+0x140>
jmp    133f <main+0x17f>
jns    133f <main+0x17f>
lea    0xd38(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1070 <printf@plt>
add    $0x1,%r13d
movsd  (%rsp),%xmm0
addsd  0xcb0(%rip),%xmm0
movsd  %xmm0,(%rsp)
cmp    0xc(%rsp),%r13d
lea    0x20(%rsp),%rdi
lea    0xd26(%rip),%r15
jb     12b0 <main+0xf0>
xor    %esi,%esi
call   1080 <gettimeofday@plt>
mov    0x20(%rsp),%eax
mov    0x28(%rsp),%ecx
sub    0x30(%rsp),%eax
imul   $0x3e8,%eax,%eax
sub    0x38(%rsp),%ecx
movslq %ecx,%rcx
imul   $0x10624dd3,%rcx,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x26,%rcx
add    %edx,%ecx
add    %eax,%ecx
movsd  (%rsp),%xmm1
movapd %xmm1,%xmm0
divsd  0xc55(%rip),%xmm0
xorps  %xmm2,%xmm2
cvtsi2sd %rcx,%xmm2
divsd  %xmm2,%xmm1
mov    %r15,%rdi
mov    $0x2,%al
call   1070 <printf@plt>
jmp    12a0 <main+0xe0>
lea    0xd45(%rip),%rdi
jmp    13f9 <main+0x239>
test   %eax,%eax
jne    1415 <main+0x255>
lea    0xce3(%rip),%rdi
call   1040 <puts@plt>
jmp    1425 <main+0x265>
lea    0xd0b(%rip),%rdi
jmp    13f9 <main+0x239>
lea    0xce8(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%eax
add    $0x448,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xc16(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xc88(%rip),%rdi
call   1040 <puts@plt>
mov    %ebx,%edi
call   10a0 <close@plt>
xor    %eax,%eax
jmp    1403 <main+0x243>

LLVM IR (-O0):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.timeval = type { i32, i64 }
%struct.sockaddr = type { i32 }
@.str = [39 x i8] c"Usage: tcp-client <server-ip-address>\0A\00"
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
@IPPROTO_TCP = global i32 0
@.str.1 = [32 x i8] c"Error creating socket, aborted\0A\00"
@AF_INET = global i32 0
@.str.2 = [34 x i8] c"Client started, connecting to %s\0A\00"
@.str.3 = [27 x i8] c"Error connecting, aborted\0A\00"
@.str.4 = [29 x i8] c"Connection closed by server\0A\00"
@.str.5 = [34 x i8] c"Error %d receiving packet length\0A\00"
@.str.6 = [26 x i8] c"<Bad packet length = %d> \00"
@stdout = global i32 0
@.str.7 = [30 x i8] c"Error %d reading from socket\0A\00"
@.str.8 = [40 x i8] c"Received %.3f Mbytes (%.1f kbytes/sec)\0A\00"
@.str.9 = [18 x i8] c"\0AClient finished\0A\00"
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 i16
%10 = alloca [1024 x i8]
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca double
%18 = alloca %struct.timeval
%19 = alloca %struct.timeval
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i16 2222, i16* %9
%20 = load i32, i32* %4
%21 = icmp ne i32 %20, 2
br i1 %21, label %22, label %24
22: ; preds = %2
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %155
24: ; preds = %2
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 1
%27 = load i8*, i8** %26
store i8* %27, i8** %8
%28 = load i32, i32* @PF_INET
%29 = load i32, i32* @SOCK_STREAM
%30 = load i32, i32* @IPPROTO_TCP
%31 = call i32 @socket(i32 %28, i32 %29, i32 %30)
store i32 %31, i32* %6
%32 = load i32, i32* %6
%33 = icmp slt i32 %32, 0
br i1 %33, label %34, label %36
34: ; preds = %24
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %3
br label %155
36: ; preds = %24
%37 = call i32 @memset(%struct.sockaddr_in* %7, i32 0, i32 12)
%38 = load i32, i32* @AF_INET
%39 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 2
store i32 %38, i32* %39
%40 = load i8*, i8** %8
%41 = call i32 @inet_addr(i8* %40)
%42 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 0
%43 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %42, i32 0, i32 0
store i32 %41, i32* %43
%44 = load i16, i16* %9
%45 = call i32 @htons(i16 zeroext %44)
%46 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 1
store i32 %45, i32* %46
%47 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 0
%48 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %47, i32 0, i32 0
%49 = load i32, i32* %48
%50 = call i8* @inet_ntoa(i32 %49)
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0), i8* %50)
store i32 0, i32* %15
store i32 0, i32* %14
store double 0.000000e+00, double* %17
%52 = call i32 @gettimeofday(%struct.timeval* %18, i32 0)
%53 = load i32, i32* %6
%54 = bitcast %struct.sockaddr_in* %7 to %struct.sockaddr*
%55 = call i64 @connect(i32 %53, %struct.sockaddr* %54, i32 12)
%56 = icmp slt i64 %55, 0
br i1 %56, label %57, label %59
57: ; preds = %36
%58 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0))
store i32 1, i32* %3
br label %155
59: ; preds = %36
br label %60
60: ; preds = %150, %82, %59
%61 = load i32, i32* %6
%62 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%63 = call i32 @recv(i32 %61, i8* %62, i32 2, i32 0)
store i32 %63, i32* %11
%64 = load i32, i32* %11
%65 = icmp eq i32 %64, 0
br i1 %65, label %66, label %68
66: ; preds = %60
%67 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0))
br label %151
68: ; preds = %60
%69 = load i32, i32* %11
%70 = icmp ne i32 %69, 2
br i1 %70, label %71, label %74
71: ; preds = %68
%72 = load i32, i32* %11
%73 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.5, i64 0, i64 0), i32 %72)
br label %151
74: ; preds = %68
%75 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%76 = bitcast i8* %75 to i16*
%77 = load i16, i16* %76
%78 = zext i16 %77 to i32
store i32 %78, i32* %13
%79 = load i32, i32* %13
%80 = sext i32 %79 to i64
%81 = icmp ne i64 %80, 1024
br i1 %81, label %82, label %87
82: ; preds = %74
%83 = load i32, i32* %13
%84 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.6, i64 0, i64 0), i32 %83)
%85 = load i32, i32* @stdout
%86 = call i32 @fflush(i32 %85)
br label %60
87: ; preds = %74
store i32 2, i32* %12
br label %88
88: ; preds = %111, %87
%89 = load i32, i32* %12
%90 = load i32, i32* %13
%91 = icmp slt i32 %89, %90
br i1 %91, label %92, label %115
92: ; preds = %88
%93 = load i32, i32* %6
%94 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%95 = load i32, i32* %12
%96 = sext i32 %95 to i64
%97 = getelementptr inbounds i8, i8* %94, i64 %96
%98 = load i32, i32* %13
%99 = load i32, i32* %12
%100 = sub nsw i32 %98, %99
%101 = call i32 @recv(i32 %93, i8* %97, i32 %100, i32 0)
store i32 %101, i32* %11
%102 = load i32, i32* %11
%103 = icmp sle i32 %102, 0
br i1 %103, label %104, label %111
104: ; preds = %92
%105 = load i32, i32* %11
%106 = icmp slt i32 %105, 0
br i1 %106, label %107, label %110
107: ; preds = %104
%108 = load i32, i32* %11
%109 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.7, i64 0, i64 0), i32 %108)
br label %110
110: ; preds = %107, %104
br label %115
111: ; preds = %92
%112 = load i32, i32* %11
%113 = load i32, i32* %12
%114 = add nsw i32 %113, %112
store i32 %114, i32* %12
br label %88
115: ; preds = %110, %88
%116 = load i32, i32* %14
%117 = add i32 %116, 1
store i32 %117, i32* %14
%118 = load i32, i32* %13
%119 = sitofp i32 %118 to double
%120 = load double, double* %17
%121 = fadd double %120, %119
store double %121, double* %17
%122 = load i32, i32* %14
%123 = load i32, i32* %15
%124 = add i32 %123, 100
%125 = icmp uge i32 %122, %124
br i1 %125, label %126, label %150
126: ; preds = %115
%127 = load i32, i32* %14
store i32 %127, i32* %15
%128 = call i32 @gettimeofday(%struct.timeval* %19, i32 0)
%129 = getelementptr inbounds %struct.timeval, %struct.timeval* %19, i32 0, i32 0
%130 = load i32, i32* %129
%131 = getelementptr inbounds %struct.timeval, %struct.timeval* %18, i32 0, i32 0
%132 = load i32, i32* %131
%133 = sub nsw i32 %130, %132
%134 = mul nsw i32 %133, 1000
%135 = getelementptr inbounds %struct.timeval, %struct.timeval* %19, i32 0, i32 1
%136 = load i64, i64* %135
%137 = getelementptr inbounds %struct.timeval, %struct.timeval* %18, i32 0, i32 1
%138 = load i64, i64* %137
%139 = sub nsw i64 %136, %138
%140 = trunc i64 %139 to i32
%141 = sdiv i32 %140, 1000
%142 = add nsw i32 %134, %141
store i32 %142, i32* %16
%143 = load double, double* %17
%144 = fdiv double %143, 1.000000e+06
%145 = load double, double* %17
%146 = load i32, i32* %16
%147 = uitofp i32 %146 to double
%148 = fdiv double %145, %147
%149 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.8, i64 0, i64 0), double %144, double %148)
br label %150
150: ; preds = %126, %115
br label %60
151: ; preds = %71, %66
%152 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.9, i64 0, i64 0))
%153 = load i32, i32* %6
%154 = call i32 @close(i32 %153)
store i32 0, i32* %3
br label %155
155: ; preds = %151, %57, %34, %22
%156 = load i32, i32* %3
ret i32 %156
}

LLVM IR (-O2):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.timeval = type { i32, i64 }
%struct.sockaddr = type { i32 }
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
@IPPROTO_TCP = global i32 0
@AF_INET = global i32 0
@.str.2 = [34 x i8] c"Client started, connecting to %s\0A\00"
@.str.5 = [34 x i8] c"Error %d receiving packet length\0A\00"
@.str.6 = [26 x i8] c"<Bad packet length = %d> \00"
@stdout = global i32 0
@.str.7 = [30 x i8] c"Error %d reading from socket\0A\00"
@.str.8 = [40 x i8] c"Received %.3f Mbytes (%.1f kbytes/sec)\0A\00"
@str = [17 x i8] c"\0AClient finished\00"
@str.10 = [28 x i8] c"Connection closed by server\00"
@str.11 = [26 x i8] c"Error connecting, aborted\00"
@str.12 = [31 x i8] c"Error creating socket, aborted\00"
@str.13 = [38 x i8] c"Usage: tcp-client <server-ip-address>\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca [1024 x i8]
%5 = alloca %struct.timeval
%6 = alloca %struct.timeval
%7 = bitcast %struct.sockaddr_in* %3 to i8*
%8 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%9 = bitcast %struct.timeval* %5 to i8*
%10 = bitcast %struct.timeval* %6 to i8*
%11 = icmp eq i32 %0, 2
br i1 %11, label %14, label %12
12: ; preds = %2
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @str.13, i64 0, i64 0))
br label %105
14: ; preds = %2
%15 = getelementptr inbounds i8*, i8** %1, i64 1
%16 = load i8*, i8** %15
%17 = load i32, i32* @PF_INET
%18 = load i32, i32* @SOCK_STREAM
%19 = load i32, i32* @IPPROTO_TCP
%20 = tail call i32 @socket(i32 %17, i32 %18, i32 %19)
%21 = icmp slt i32 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %14
%23 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str.12, i64 0, i64 0))
br label %105
24: ; preds = %14
%25 = call i32 @memset(%struct.sockaddr_in* %3, i32 0, i32 12)
%26 = load i32, i32* @AF_INET
%27 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %26, i32* %27
%28 = call i32 @inet_addr(i8* %16)
%29 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0, i32 0
store i32 %28, i32* %29
%30 = call i32 @htons(i16 zeroext 2222)
%31 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1
store i32 %30, i32* %31
%32 = load i32, i32* %29
%33 = call i8* @inet_ntoa(i32 %32)
%34 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0), i8* %33)
%35 = call i32 @gettimeofday(%struct.timeval* %5, i32 0)
%36 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%37 = call i64 @connect(i32 %20, %struct.sockaddr* %36, i32 12)
%38 = icmp slt i64 %37, 0
br i1 %38, label %45, label %39
39: ; preds = %24
%40 = bitcast [1024 x i8]* %4 to i16*
%41 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i64 0, i32 0
%42 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i64 0, i32 0
%43 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i64 0, i32 1
%44 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i64 0, i32 1
br label %95
45: ; preds = %24
%46 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str.11, i64 0, i64 0))
br label %105
47: ; preds = %99, %56
%48 = call i32 @recv(i32 %20, i8* %8, i32 2, i32 0)
switch i32 %48, label %51 [
i32 0, label %49
i32 2, label %53
]
49: ; preds = %47
%50 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str.10, i64 0, i64 0))
br label %102
51: ; preds = %47
%52 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.5, i64 0, i64 0), i32 %48)
br label %102
53: ; preds = %47
%54 = load i16, i16* %40
%55 = icmp eq i16 %54, 1024
br i1 %55, label %61, label %56
56: ; preds = %53
%57 = zext i16 %54 to i32
%58 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.6, i64 0, i64 0), i32 %57)
%59 = load i32, i32* @stdout
%60 = call i32 @fflush(i32 %59)
br label %47
61: ; preds = %53, %72
%62 = phi i32 [ %73, %72 ], [ 2, %53 ]
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 %63
%65 = sub nsw i32 1024, %62
%66 = call i32 @recv(i32 %20, i8* %64, i32 %65, i32 0)
%67 = icmp slt i32 %66, 1
br i1 %67, label %68, label %72
68: ; preds = %61
%69 = icmp slt i32 %66, 0
br i1 %69, label %70, label %75
70: ; preds = %68
%71 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.7, i64 0, i64 0), i32 %66)
br label %75
72: ; preds = %61
%73 = add nsw i32 %66, %62
%74 = icmp slt i32 %73, 1024
br i1 %74, label %61, label %75
75: ; preds = %72, %68, %70
%76 = add i32 %100, 1
%77 = fadd double %101, 1.024000e+03
%78 = icmp ult i32 %76, %98
br i1 %78, label %99, label %79
79: ; preds = %75
%80 = call i32 @gettimeofday(%struct.timeval* %6, i32 0)
%81 = load i32, i32* %41
%82 = load i32, i32* %42
%83 = sub nsw i32 %81, %82
%84 = mul nsw i32 %83, 1000
%85 = load i64, i64* %43
%86 = load i64, i64* %44
%87 = sub nsw i64 %85, %86
%88 = trunc i64 %87 to i32
%89 = sdiv i32 %88, 1000
%90 = add nsw i32 %89, %84
%91 = fdiv double %77, 1.000000e+06
%92 = uitofp i32 %90 to double
%93 = fdiv double %77, %92
%94 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str.8, i64 0, i64 0), double %91, double %93)
br label %95
95: ; preds = %79, %39
%96 = phi i32 [ %76, %79 ], [ 0, %39 ]
%97 = phi double [ %77, %79 ], [ 0.000000e+00, %39 ]
%98 = add i32 %96, 100
br label %99
99: ; preds = %95, %75
%100 = phi i32 [ %76, %75 ], [ %96, %95 ]
%101 = phi double [ %77, %75 ], [ %97, %95 ]
br label %47
102: ; preds = %51, %49
%103 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str, i64 0, i64 0))
%104 = call i32 @close(i32 %20)
br label %105
105: ; preds = %102, %45, %22, %12
%106 = phi i32 [ 1, %12 ], [ 1, %22 ], [ 1, %45 ], [ 0, %102 ]
ret i32 %106
}