#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 dummy;
};
struct sysinfo {
  int freeram;
};
struct TYPE_2__ {
  int /*<<< orphan*/ s_addr;
};
struct sockaddr_in {
  int /*<<< orphan*/ sin_port;
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
typedef scalar_t__ ssize_t;
typedef int /*<<< orphan*/ echoserver;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ Die(char *);
int /*<<< orphan*/ IPPROTO_TCP;
int /*<<< orphan*/ PF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ atoi(char *);
int /*<<< orphan*/ close(int);
scalar_t__ connect(int, struct sockaddr *, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int /*<<< orphan*/ htons(int /*<<< orphan*/);
int /*<<< orphan*/ inet_addr(char *);
char *malloc(int);
int /*<<< orphan*/ memset(struct sockaddr_in *, int /*<<< orphan*/, int);
scalar_t__ recv(int, char *, int, int /*<<< orphan*/);
unsigned int send(int, char *, unsigned int, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
unsigned int strlen(char *);
int /*<<< orphan*/ sysinfo(struct sysinfo *);
int /*<<< orphan*/ timeval_subtract(struct timeval *, struct timeval *,
                                    struct timeval *);
scalar_t__ timeval_to_int(struct timeval *);
int /*<<< orphan*/ timeval_to_str(struct timeval *);
int main(int argc, char *argv[]) {
  int sock;
  struct sockaddr_in echoserver;
  char *buffer = NULL;
  unsigned int echolen;
  long long int received;
  ssize_t bytes;
  struct timeval t0, t1, td;
  if (argc != 4) {
    fprintf(stderr,
            "USAGE: bulkclient <server_ip> <port> <data-length-requested>\n");
    exit(1);
  }
  struct sysinfo si;
  sysinfo(&si);
  int alloc_req = 2147479552 < (si.freeram / 2) ? 2147479552 : si.freeram / 2;
  fprintf(stderr, "allocating %dM buffer\n", alloc_req / (2 << 19));
  buffer = malloc(alloc_req);
  if (NULL == buffer) {
    Die("Failed to allocate buffer");
  }
  if ((sock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) {
    Die("Failed to create socket");
  }
  memset(&echoserver, 0, sizeof(echoserver));
  echoserver.sin_family = AF_INET;
  echoserver.sin_addr.s_addr = inet_addr(argv[1]);
  echoserver.sin_port = htons(atoi(argv[2]));
  if (connect(sock, (struct sockaddr *)&echoserver, sizeof(echoserver)) < 0) {
    Die("Failed to connect with server");
  }
  echolen = strlen(argv[3]);
  if (send(sock, argv[3], echolen, 0) != echolen) {
    Die("Mismatch in number of sent bytes");
  }
  gettimeofday(&t0, NULL);
  received = 0;
  do {
    bytes = recv(sock, buffer, alloc_req, 0);
    received += bytes;
  } while (bytes > 0);
  gettimeofday(&t1, NULL);
  timeval_subtract(&td, &t1, &t0);
  fprintf(stdout, "Received: %lld bytes in %s secs\n", received,
          timeval_to_str(&td));
  double rxd = (double)received;
  double elapsed = (double)timeval_to_int(&td) / (double)1000000;
  fprintf(stdout, "approx bandwidth %f Mbps\n",
          (8 * rxd) / (1000000 * elapsed));
  close(sock);
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x28(%rbp)
cmpl   $0x4,-0x8(%rbp)
je     127c <main+0x4c>
mov    0x2d6e(%rip),%rax
mov    (%rax),%edi
lea    0xda5(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    $0x1,%edi
call   1130 <exit@plt>
lea    -0x60(%rbp),%rdi
call   1110 <sysinfo@plt>
mov    -0x60(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    $0x7ffff000,%eax
cmp    %ecx,%eax
jge    12ac <main+0x7c>
mov    $0x7ffff000,%eax
mov    %eax,-0x7c(%rbp)
jmp    12ba <main+0x8a>
mov    -0x60(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x7c(%rbp)
mov    -0x7c(%rbp),%eax
mov    %eax,-0x64(%rbp)
mov    0x2d09(%rip),%rax
mov    (%rax),%edi
mov    -0x64(%rbp),%eax
mov    $0x100000,%ecx
cltd
idiv   %ecx
mov    %eax,%edx
lea    0xd71(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    -0x64(%rbp),%edi
call   10e0 <malloc@plt>
mov    %rax,-0x28(%rbp)
xor    %eax,%eax
cmp    -0x28(%rbp),%rax
jne    1308 <main+0xd8>
lea    0xd62(%rip),%rdi
call   10f0 <Die@plt>
mov    0x2cb1(%rip),%rax
mov    (%rax),%edi
mov    0x2cb0(%rip),%rax
mov    (%rax),%esi
mov    0x2cbf(%rip),%rax
mov    (%rax),%edx
call   1150 <socket@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    1340 <main+0x110>
lea    0xd44(%rip),%rdi
call   10f0 <Die@plt>
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1080 <memset@plt>
mov    0x2c91(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10a0 <inet_addr@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1100 <atoi@plt>
mov    %eax,%edi
call   1050 <htons@plt>
mov    %eax,-0x20(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0xc,%edx
call   1140 <connect@plt>
cmp    $0x0,%rax
jge    13aa <main+0x17a>
lea    0xcf2(%rip),%rdi
call   10f0 <Die@plt>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x14(%rbp),%edi
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rsi
mov    -0x2c(%rbp),%edx
xor    %ecx,%ecx
call   1060 <send@plt>
cmp    -0x2c(%rbp),%eax
je     13e4 <main+0x1b4>
lea    0xcd6(%rip),%rdi
call   10f0 <Die@plt>
lea    -0x48(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1070 <gettimeofday@plt>
movq   $0x0,-0x38(%rbp)
mov    -0x14(%rbp),%edi
mov    -0x28(%rbp),%rsi
mov    -0x64(%rbp),%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rax
add    -0x38(%rbp),%rax
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x40(%rbp)
jg     13f9 <main+0x1c9>
lea    -0x50(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1070 <gettimeofday@plt>
lea    -0x58(%rbp),%rdi
lea    -0x50(%rbp),%rsi
lea    -0x48(%rbp),%rdx
call   10c0 <timeval_subtract@plt>
mov    0x2b6e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x8c(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,-0x88(%rbp)
lea    -0x58(%rbp),%rdi
call   1120 <timeval_to_str@plt>
mov    -0x8c(%rbp),%edi
mov    -0x88(%rbp),%rdx
mov    %eax,%ecx
lea    0xc5a(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
cvtsi2sdq -0x38(%rbp),%xmm0
movsd  %xmm0,-0x70(%rbp)
lea    -0x58(%rbp),%rdi
call   10d0 <timeval_to_int@plt>
cvtsi2sd %rax,%xmm0
movsd  0xb5c(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x78(%rbp)
mov    0x2b04(%rip),%rax
mov    (%rax),%edi
movsd  0xb4a(%rip),%xmm0
mulsd  -0x70(%rbp),%xmm0
movsd  0xb35(%rip),%xmm1
mulsd  -0x78(%rbp),%xmm1
divsd  %xmm1,%xmm0
lea    0xc1c(%rip),%rsi
mov    $0x1,%al
call   10b0 <fprintf@plt>
mov    -0x14(%rbp),%edi
call   1090 <close@plt>
xor    %edi,%edi
call   1130 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x40,%rsp
cmp    $0x4,%edi
jne    1446 <main+0x216>
mov    %rsi,%r15
lea    0x8(%rsp),%rdi
call   1110 <sysinfo@plt>
mov    0x8(%rsp),%eax
mov    %eax,%r12d
shr    $0x1f,%r12d
add    %eax,%r12d
sar    %r12d
mov    0x2d66(%rip),%rcx
mov    (%rcx),%edi
lea    0x1fffff(%rax),%edx
test   %eax,%eax
cmovns %eax,%edx
sar    $0x15,%edx
lea    0xdcd(%rip),%rsi
xor    %eax,%eax
call   10b0 <fprintf@plt>
mov    %r12d,%edi
call   10e0 <malloc@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    12a4 <main+0x74>
lea    0xdc6(%rip),%rdi
call   10f0 <Die@plt>
mov    0x2d15(%rip),%rax
mov    (%rax),%edi
mov    0x2d14(%rip),%rax
mov    (%rax),%esi
mov    0x2d23(%rip),%rax
mov    (%rax),%edx
call   1150 <socket@plt>
mov    %eax,%r14d
test   %eax,%eax
jns    12d7 <main+0xa7>
lea    0xdad(%rip),%rdi
call   10f0 <Die@plt>
lea    0x18(%rsp),%rbp
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1080 <memset@plt>
mov    0x2cf6(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x20(%rsp)
mov    0x8(%r15),%rdi
call   10a0 <inet_addr@plt>
mov    %eax,0x1c(%rsp)
mov    0x10(%r15),%rdi
call   1100 <atoi@plt>
mov    %eax,%edi
call   1050 <htons@plt>
mov    %eax,0x18(%rsp)
mov    %r14d,%edi
mov    %rbp,%rsi
mov    $0xc,%edx
call   1140 <connect@plt>
test   %rax,%rax
jns    133a <main+0x10a>
lea    0xd62(%rip),%rdi
call   10f0 <Die@plt>
mov    0x18(%r15),%rdi
call   1040 <strlen@plt>
mov    %eax,%ebp
mov    0x18(%r15),%rsi
mov    %r14d,%edi
mov    %eax,%edx
xor    %ecx,%ecx
call   1060 <send@plt>
cmp    %ebp,%eax
je     1365 <main+0x135>
lea    0xd55(%rip),%rdi
call   10f0 <Die@plt>
xor    %ebp,%ebp
lea    0x10(%rsp),%rdi
xor    %esi,%esi
call   1070 <gettimeofday@plt>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r14d,%edi
mov    %rbx,%rsi
mov    %r12d,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
add    %rax,%rbp
test   %rax,%rax
jg     1380 <main+0x150>
lea    0x38(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
call   1070 <gettimeofday@plt>
lea    0x30(%rsp),%r15
lea    0x10(%rsp),%rdx
mov    %r15,%rdi
mov    %rbx,%rsi
call   10c0 <timeval_subtract@plt>
mov    0x2bf5(%rip),%r12
mov    (%r12),%ebx
mov    %r15,%rdi
call   1120 <timeval_to_str@plt>
lea    0xd00(%rip),%rsi
mov    %ebx,%edi
mov    %rbp,%rdx
mov    %eax,%ecx
xor    %eax,%eax
call   10b0 <fprintf@plt>
cvtsi2sd %rbp,%xmm0
movsd  %xmm0,0x28(%rsp)
mov    %r15,%rdi
call   10d0 <timeval_to_int@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
movsd  0xbf9(%rip),%xmm1
divsd  %xmm1,%xmm0
mov    (%r12),%edi
movsd  0x28(%rsp),%xmm2
mulsd  0xbeb(%rip),%xmm2
mulsd  %xmm1,%xmm0
divsd  %xmm0,%xmm2
movapd %xmm2,%xmm0
lea    0xcc7(%rip),%rsi
mov    $0x1,%al
call   10b0 <fprintf@plt>
mov    %r14d,%edi
call   1090 <close@plt>
xor    %edi,%edi
call   1130 <exit@plt>
mov    0x2b83(%rip),%rax
mov    (%rax),%edi
lea    0xbba(%rip),%rsi
xor    %eax,%eax
call   10b0 <fprintf@plt>
mov    $0x1,%edi
call   1130 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.timeval = type { i32 }
%struct.sysinfo = type { i32 }
%struct.sockaddr = type { i32 }
@stderr = global i32 0
@.str = [62 x i8] c"USAGE: bulkclient <server_ip> <port> <data-length-requested>\0A\00"
@.str.1 = [23 x i8] c"allocating %dM buffer\0A\00"
@.str.2 = [26 x i8] c"Failed to allocate buffer\00"
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
@IPPROTO_TCP = global i32 0
@.str.3 = [24 x i8] c"Failed to create socket\00"
@AF_INET = global i32 0
@.str.4 = [30 x i8] c"Failed to connect with server\00"
@.str.5 = [33 x i8] c"Mismatch in number of sent bytes\00"
@stdout = global i32 0
@.str.6 = [33 x i8] c"Received: %lld bytes in %s secs\0A\00"
@.str.7 = [26 x i8] c"approx bandwidth %f Mbps\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 i32
%10 = alloca i64
%11 = alloca i64
%12 = alloca %struct.timeval
%13 = alloca %struct.timeval
%14 = alloca %struct.timeval
%15 = alloca %struct.sysinfo
%16 = alloca i32
%17 = alloca double
%18 = alloca double
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* null, i8** %8
%19 = load i32, i32* %4
%20 = icmp ne i32 %19, 4
br i1 %20, label %21, label %25
21: ; preds = %2
%22 = load i32, i32* @stderr
%23 = call i32 (i32, i8*, ...) @fprintf(i32 %22, i8* getelementptr inbounds ([62 x i8], [62 x i8]* @.str, i64 0, i64 0))
%24 = call i32 @exit(i32 1)
unreachable
25: ; preds = %2
%26 = call i32 @sysinfo(%struct.sysinfo* %15)
%27 = getelementptr inbounds %struct.sysinfo, %struct.sysinfo* %15, i32 0, i32 0
%28 = load i32, i32* %27
%29 = sdiv i32 %28, 2
%30 = icmp slt i32 2147479552, %29
br i1 %30, label %31, label %32
31: ; preds = %25
br label %36
32: ; preds = %25
%33 = getelementptr inbounds %struct.sysinfo, %struct.sysinfo* %15, i32 0, i32 0
%34 = load i32, i32* %33
%35 = sdiv i32 %34, 2
br label %36
36: ; preds = %32, %31
%37 = phi i32 [ 2147479552, %31 ], [ %35, %32 ]
store i32 %37, i32* %16
%38 = load i32, i32* @stderr
%39 = load i32, i32* %16
%40 = sdiv i32 %39, 1048576
%41 = call i32 (i32, i8*, ...) @fprintf(i32 %38, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 %40)
%42 = load i32, i32* %16
%43 = call i8* @malloc(i32 %42)
store i8* %43, i8** %8
%44 = load i8*, i8** %8
%45 = icmp eq i8* null, %44
br i1 %45, label %46, label %48
46: ; preds = %36
%47 = call i32 @Die(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
br label %48
48: ; preds = %46, %36
%49 = load i32, i32* @PF_INET
%50 = load i32, i32* @SOCK_STREAM
%51 = load i32, i32* @IPPROTO_TCP
%52 = call i32 @socket(i32 %49, i32 %50, i32 %51)
store i32 %52, i32* %6
%53 = icmp slt i32 %52, 0
br i1 %53, label %54, label %56
54: ; preds = %48
%55 = call i32 @Die(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0))
br label %56
56: ; preds = %54, %48
%57 = call i32 @memset(%struct.sockaddr_in* %7, i32 0, i32 12)
%58 = load i32, i32* @AF_INET
%59 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 2
store i32 %58, i32* %59
%60 = load i8**, i8*** %5
%61 = getelementptr inbounds i8*, i8** %60, i64 1
%62 = load i8*, i8** %61
%63 = call i32 @inet_addr(i8* %62)
%64 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 1
%65 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %64, i32 0, i32 0
store i32 %63, i32* %65
%66 = load i8**, i8*** %5
%67 = getelementptr inbounds i8*, i8** %66, i64 2
%68 = load i8*, i8** %67
%69 = call i32 @atoi(i8* %68)
%70 = call i32 @htons(i32 %69)
%71 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 0
store i32 %70, i32* %71
%72 = load i32, i32* %6
%73 = bitcast %struct.sockaddr_in* %7 to %struct.sockaddr*
%74 = call i64 @connect(i32 %72, %struct.sockaddr* %73, i32 12)
%75 = icmp slt i64 %74, 0
br i1 %75, label %76, label %78
76: ; preds = %56
%77 = call i32 @Die(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0))
br label %78
78: ; preds = %76, %56
%79 = load i8**, i8*** %5
%80 = getelementptr inbounds i8*, i8** %79, i64 3
%81 = load i8*, i8** %80
%82 = call i32 @strlen(i8* %81)
store i32 %82, i32* %9
%83 = load i32, i32* %6
%84 = load i8**, i8*** %5
%85 = getelementptr inbounds i8*, i8** %84, i64 3
%86 = load i8*, i8** %85
%87 = load i32, i32* %9
%88 = call i32 @send(i32 %83, i8* %86, i32 %87, i32 0)
%89 = load i32, i32* %9
%90 = icmp ne i32 %88, %89
br i1 %90, label %91, label %93
91: ; preds = %78
%92 = call i32 @Die(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.5, i64 0, i64 0))
br label %93
93: ; preds = %91, %78
%94 = call i32 @gettimeofday(%struct.timeval* %12, i32* null)
store i64 0, i64* %10
br label %95
95: ; preds = %103, %93
%96 = load i32, i32* %6
%97 = load i8*, i8** %8
%98 = load i32, i32* %16
%99 = call i64 @recv(i32 %96, i8* %97, i32 %98, i32 0)
store i64 %99, i64* %11
%100 = load i64, i64* %11
%101 = load i64, i64* %10
%102 = add nsw i64 %101, %100
store i64 %102, i64* %10
br label %103
103: ; preds = %95
%104 = load i64, i64* %11
%105 = icmp sgt i64 %104, 0
br i1 %105, label %95, label %106
106: ; preds = %103
%107 = call i32 @gettimeofday(%struct.timeval* %13, i32* null)
%108 = call i32 @timeval_subtract(%struct.timeval* %14, %struct.timeval* %13, %struct.timeval* %12)
%109 = load i32, i32* @stdout
%110 = load i64, i64* %10
%111 = call i32 @timeval_to_str(%struct.timeval* %14)
%112 = call i32 (i32, i8*, ...) @fprintf(i32 %109, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.6, i64 0, i64 0), i64 %110, i32 %111)
%113 = load i64, i64* %10
%114 = sitofp i64 %113 to double
store double %114, double* %17
%115 = call i64 @timeval_to_int(%struct.timeval* %14)
%116 = sitofp i64 %115 to double
%117 = fdiv double %116, 1.000000e+06
store double %117, double* %18
%118 = load i32, i32* @stdout
%119 = load double, double* %17
%120 = fmul double 8.000000e+00, %119
%121 = load double, double* %18
%122 = fmul double 1.000000e+06, %121
%123 = fdiv double %120, %122
%124 = call i32 (i32, i8*, ...) @fprintf(i32 %118, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.7, i64 0, i64 0), double %123)
%125 = load i32, i32* %6
%126 = call i32 @close(i32 %125)
%127 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.timeval = type { i32 }
%struct.sysinfo = type { i32 }
%struct.sockaddr = type { i32 }
@stderr = global i32 0
@.str = [62 x i8] c"USAGE: bulkclient <server_ip> <port> <data-length-requested>\0A\00"
@.str.1 = [23 x i8] c"allocating %dM buffer\0A\00"
@.str.2 = [26 x i8] c"Failed to allocate buffer\00"
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
@IPPROTO_TCP = global i32 0
@.str.3 = [24 x i8] c"Failed to create socket\00"
@AF_INET = global i32 0
@.str.4 = [30 x i8] c"Failed to connect with server\00"
@.str.5 = [33 x i8] c"Mismatch in number of sent bytes\00"
@stdout = global i32 0
@.str.6 = [33 x i8] c"Received: %lld bytes in %s secs\0A\00"
@.str.7 = [26 x i8] c"approx bandwidth %f Mbps\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca %struct.timeval
%5 = alloca %struct.timeval
%6 = alloca %struct.timeval
%7 = alloca %struct.sysinfo
%8 = bitcast %struct.sockaddr_in* %3 to i8*
%9 = bitcast %struct.timeval* %4 to i8*
%10 = bitcast %struct.timeval* %5 to i8*
%11 = bitcast %struct.timeval* %6 to i8*
%12 = icmp eq i32 %0, 4
br i1 %12, label %17, label %13
13: ; preds = %2
%14 = load i32, i32* @stderr
%15 = tail call i32 (i32, i8*, ...) @fprintf(i32 %14, i8* getelementptr inbounds ([62 x i8], [62 x i8]* @.str, i64 0, i64 0))
%16 = tail call i32 @exit(i32 1)
unreachable
17: ; preds = %2
%18 = bitcast %struct.sysinfo* %7 to i8*
%19 = call i32 @sysinfo(%struct.sysinfo* %7)
%20 = getelementptr inbounds %struct.sysinfo, %struct.sysinfo* %7, i64 0, i32 0
%21 = load i32, i32* %20
%22 = sdiv i32 %21, 2
%23 = load i32, i32* @stderr
%24 = sdiv i32 %21, 2097152
%25 = call i32 (i32, i8*, ...) @fprintf(i32 %23, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 %24)
%26 = call i8* @malloc(i32 %22)
%27 = icmp eq i8* %26, null
br i1 %27, label %28, label %30
28: ; preds = %17
%29 = call i32 @Die(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
br label %30
30: ; preds = %28, %17
%31 = load i32, i32* @PF_INET
%32 = load i32, i32* @SOCK_STREAM
%33 = load i32, i32* @IPPROTO_TCP
%34 = call i32 @socket(i32 %31, i32 %32, i32 %33)
%35 = icmp slt i32 %34, 0
br i1 %35, label %36, label %38
36: ; preds = %30
%37 = call i32 @Die(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0))
br label %38
38: ; preds = %36, %30
%39 = call i32 @memset(%struct.sockaddr_in* %3, i32 0, i32 12)
%40 = load i32, i32* @AF_INET
%41 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %40, i32* %41
%42 = getelementptr inbounds i8*, i8** %1, i64 1
%43 = load i8*, i8** %42
%44 = call i32 @inet_addr(i8* %43)
%45 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1, i32 0
store i32 %44, i32* %45
%46 = getelementptr inbounds i8*, i8** %1, i64 2
%47 = load i8*, i8** %46
%48 = call i32 @atoi(i8* %47)
%49 = call i32 @htons(i32 %48)
%50 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
store i32 %49, i32* %50
%51 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%52 = call i64 @connect(i32 %34, %struct.sockaddr* %51, i32 12)
%53 = icmp slt i64 %52, 0
br i1 %53, label %54, label %56
54: ; preds = %38
%55 = call i32 @Die(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0))
br label %56
56: ; preds = %54, %38
%57 = getelementptr inbounds i8*, i8** %1, i64 3
%58 = load i8*, i8** %57
%59 = call i32 @strlen(i8* %58)
%60 = load i8*, i8** %57
%61 = call i32 @send(i32 %34, i8* %60, i32 %59, i32 0)
%62 = icmp eq i32 %61, %59
br i1 %62, label %65, label %63
63: ; preds = %56
%64 = call i32 @Die(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.5, i64 0, i64 0))
br label %65
65: ; preds = %63, %56
%66 = call i32 @gettimeofday(%struct.timeval* %4, i32* null)
br label %67
67: ; preds = %67, %65
%68 = phi i64 [ 0, %65 ], [ %70, %67 ]
%69 = call i64 @recv(i32 %34, i8* %26, i32 %22, i32 0)
%70 = add nsw i64 %69, %68
%71 = icmp sgt i64 %69, 0
br i1 %71, label %67, label %72
72: ; preds = %67
%73 = call i32 @gettimeofday(%struct.timeval* %5, i32* null)
%74 = call i32 @timeval_subtract(%struct.timeval* %6, %struct.timeval* %5, %struct.timeval* %4)
%75 = load i32, i32* @stdout
%76 = call i32 @timeval_to_str(%struct.timeval* %6)
%77 = call i32 (i32, i8*, ...) @fprintf(i32 %75, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.6, i64 0, i64 0), i64 %70, i32 %76)
%78 = sitofp i64 %70 to double
%79 = call i64 @timeval_to_int(%struct.timeval* %6)
%80 = sitofp i64 %79 to double
%81 = fdiv double %80, 1.000000e+06
%82 = load i32, i32* @stdout
%83 = fmul double %78, 8.000000e+00
%84 = fmul double %81, 1.000000e+06
%85 = fdiv double %83, %84
%86 = call i32 (i32, i8*, ...) @fprintf(i32 %82, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.7, i64 0, i64 0), double %85)
%87 = call i32 @close(i32 %34)
%88 = call i32 @exit(i32 0)
unreachable
}