#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 */
struct timeval {
  int tv_sec;
  scalar_t__ tv_usec;
};
struct in_addr {
  int dummy;
};
struct sockaddr_in {
  int /*<<< orphan*/ sin_port;
  struct in_addr sin_addr;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
struct hostent {
  scalar_t__ h_addr;
};
typedef int socklen_t;
typedef int /*<<< orphan*/ servaddr;
typedef int /*<<< orphan*/ cliaddr;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ atoi(char *);
int buildMessage(struct sockaddr_in *, char *, char *, char **);
int connect(int, struct sockaddr *, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ free(char *);
char *getNextMessage(int /*<<< orphan*/ *);
struct hostent *gethostbyname(char *);
int getsockname(int, struct sockaddr *, int *);
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int /*<<< orphan*/ htons(int /*<<< orphan*/);
int /*<<< orphan*/ memset(struct sockaddr_in *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, int, scalar_t__);
int recvfrom(int, char *, int, int /*<<< orphan*/, int /*<<< orphan*/ *,
             int /*<<< orphan*/ *);
int sendto(int, char *, int, int /*<<< orphan*/, struct sockaddr *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  int sockfd, ret;
  struct sockaddr_in servaddr, cliaddr;
  socklen_t cliaddr_len = sizeof(cliaddr);
  if (argc != 5) {
    fprintf(stderr, "Usage: %s <Server> <Port> <file1> <file2>\n", argv[0]);
    exit(1);
  }
  sockfd = socket(AF_INET, SOCK_DGRAM, 0);
  memset(&servaddr, 0, sizeof(servaddr));
  servaddr.sin_family = AF_INET;
  struct hostent *host = gethostbyname(argv[1]);
  servaddr.sin_addr = *(struct in_addr *)host->h_addr;
  servaddr.sin_port = htons(atoi(argv[2]));
  if (connect(sockfd, (struct sockaddr *)&servaddr, sizeof(servaddr)) == -1) {
    fprintf(stderr, "error in connecting!\n");
    exit(1);
  }
  if (getsockname(sockfd, (struct sockaddr *)&cliaddr, &cliaddr_len) == -1) {
    fprintf(stderr, "error in getsockname!\n");
    exit(1);
  }
  FILE *f1 = fopen(argv[3], "r");
  FILE *f2 = fopen(argv[4], "r");
  char *msg1 = getNextMessage(f1);
  char *msg2 = getNextMessage(f2);
  char *datagram = NULL;
  char ack_msg[512];
  struct timeval start, end;
  while (msg1 != NULL && msg2 != NULL) {
    int dg_len = buildMessage(&cliaddr, msg1, msg2, &datagram);
    if (sendto(sockfd, datagram, dg_len, 0, (struct sockaddr *)&servaddr,
               sizeof(servaddr)) == -1) {
      fprintf(stderr, "error in sending!\n");
      exit(1);
    }
    gettimeofday(&start, NULL);
    if (recvfrom(sockfd, ack_msg, 512, 0, NULL, NULL) == -1) {
      fprintf(stderr, "error in receiving!\n");
      exit(1);
    }
    gettimeofday(&end, NULL);
    printf(
        "transmit_time\t%d\t%lu\n", dg_len,
        ((end.tv_sec - start.tv_sec) * 1000000 + end.tv_usec - start.tv_usec));
    free(msg1);
    free(msg2);
    free(datagram);
    msg1 = getNextMessage(f1);
    msg2 = getNextMessage(f2);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2a0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0xc,-0x3c(%rbp)
cmpl   $0x5,-0x8(%rbp)
je     1262 <main+0x52>
mov    0x2d8f(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xdaf(%rip),%rsi
mov    $0x0,%al
call   10c0 <fprintf@plt>
mov    $0x1,%edi
call   1110 <exit@plt>
mov    0x2d7f(%rip),%rax
mov    (%rax),%edi
mov    0x2d6e(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1130 <socket@plt>
mov    %eax,-0x14(%rbp)
lea    -0x28(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1090 <memset@plt>
mov    0x2d53(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10b0 <gethostbyname@plt>
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rax
mov    (%rax),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1100 <atoi@plt>
mov    %eax,%edi
call   1050 <htons@plt>
mov    %eax,-0x28(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x28(%rbp),%rsi
mov    $0xc,%edx
call   1120 <connect@plt>
cmp    $0xffffffff,%eax
jne    1309 <main+0xf9>
mov    0x2ce1(%rip),%rax
mov    (%rax),%edi
lea    0xd33(%rip),%rsi
mov    $0x0,%al
call   10c0 <fprintf@plt>
mov    $0x1,%edi
call   1110 <exit@plt>
mov    -0x14(%rbp),%edi
lea    -0x38(%rbp),%rsi
lea    -0x3c(%rbp),%rdx
call   10f0 <getsockname@plt>
cmp    $0xffffffff,%eax
jne    1343 <main+0x133>
mov    0x2ca7(%rip),%rax
mov    (%rax),%edi
lea    0xd0f(%rip),%rsi
mov    $0x0,%al
call   10c0 <fprintf@plt>
mov    $0x1,%edi
call   1110 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
lea    0xd06(%rip),%rsi
call   10e0 <fopen@plt>
mov    %rax,-0x50(%rbp)
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rdi
lea    0xcee(%rip),%rsi
call   10e0 <fopen@plt>
mov    %rax,-0x58(%rbp)
mov    -0x50(%rbp),%rdi
call   1040 <getNextMessage@plt>
mov    %rax,-0x60(%rbp)
mov    -0x58(%rbp),%rdi
call   1040 <getNextMessage@plt>
mov    %rax,-0x68(%rbp)
movq   $0x0,-0x70(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x60(%rbp)
mov    %al,-0x295(%rbp)
je     13b6 <main+0x1a6>
cmpq   $0x0,-0x68(%rbp)
setne  %al
mov    %al,-0x295(%rbp)
mov    -0x295(%rbp),%al
test   $0x1,%al
jne    13c9 <main+0x1b9>
jmp    1503 <main+0x2f3>
mov    -0x60(%rbp),%rsi
mov    -0x68(%rbp),%rdx
lea    -0x38(%rbp),%rdi
lea    -0x70(%rbp),%rcx
call   1080 <buildMessage@plt>
mov    %eax,-0x294(%rbp)
mov    -0x14(%rbp),%edi
mov    -0x70(%rbp),%rsi
mov    -0x294(%rbp),%edx
lea    -0x28(%rbp),%r8
xor    %ecx,%ecx
mov    $0xc,%r9d
call   10a0 <sendto@plt>
cmp    $0xffffffff,%eax
jne    142c <main+0x21c>
mov    0x2bbe(%rip),%rax
mov    (%rax),%edi
lea    0xc3f(%rip),%rsi
mov    $0x0,%al
call   10c0 <fprintf@plt>
mov    $0x1,%edi
call   1110 <exit@plt>
lea    -0x280(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1070 <gettimeofday@plt>
mov    -0x14(%rbp),%edi
lea    -0x270(%rbp),%rsi
mov    $0x200,%edx
xor    %ecx,%ecx
xor    %eax,%eax
mov    %eax,%r9d
mov    %r9,%r8
call   10d0 <recvfrom@plt>
cmp    $0xffffffff,%eax
jne    1484 <main+0x274>
mov    0x2b66(%rip),%rax
mov    (%rax),%edi
lea    0xbfa(%rip),%rsi
mov    $0x0,%al
call   10c0 <fprintf@plt>
mov    $0x1,%edi
call   1110 <exit@plt>
lea    -0x290(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1070 <gettimeofday@plt>
mov    -0x294(%rbp),%esi
mov    -0x290(%rbp),%eax
sub    -0x280(%rbp),%eax
imul   $0xf4240,%eax,%eax
movslq %eax,%rdx
add    -0x288(%rbp),%rdx
sub    -0x278(%rbp),%rdx
lea    0xbbe(%rip),%rdi
call   1060 <printf@plt>
mov    -0x60(%rbp),%rdi
call   1030 <free@plt>
mov    -0x68(%rbp),%rdi
call   1030 <free@plt>
mov    -0x70(%rbp),%rdi
call   1030 <free@plt>
mov    -0x50(%rbp),%rdi
call   1040 <getNextMessage@plt>
mov    %rax,-0x60(%rbp)
mov    -0x58(%rbp),%rdi
call   1040 <getNextMessage@plt>
mov    %rax,-0x68(%rbp)
jmp    1395 <main+0x185>
mov    -0x4(%rbp),%eax
add    $0x2a0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x258,%rsp
mov    %rsi,%rbx
movl   $0xc,0xc(%rsp)
cmp    $0x5,%edi
jne    143b <main+0x22b>
mov    0x2dac(%rip),%r15
mov    (%r15),%edi
mov    0x2d9a(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1130 <socket@plt>
mov    %eax,%ebp
lea    0x10(%rsp),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1090 <memset@plt>
mov    (%r15),%eax
mov    %eax,0x18(%rsp)
mov    0x8(%rbx),%rdi
call   10b0 <gethostbyname@plt>
mov    (%rax),%rax
mov    (%rax),%eax
mov    %eax,0x14(%rsp)
mov    0x10(%rbx),%rdi
call   1100 <atoi@plt>
mov    %eax,%edi
call   1050 <htons@plt>
mov    %eax,0x10(%rsp)
mov    %ebp,%edi
mov    %r14,%rsi
mov    $0xc,%edx
call   1120 <connect@plt>
cmp    $0xffffffff,%eax
je     145f <main+0x24f>
lea    0x40(%rsp),%rsi
lea    0xc(%rsp),%rdx
mov    %ebp,%edi
call   10f0 <getsockname@plt>
cmp    $0xffffffff,%eax
je     1471 <main+0x261>
mov    0x18(%rbx),%rdi
lea    0xd89(%rip),%r15
mov    %r15,%rsi
call   10e0 <fopen@plt>
mov    %rax,%r14
mov    0x20(%rbx),%rdi
mov    %r15,%rsi
call   10e0 <fopen@plt>
mov    %rax,%r15
mov    %r14,%rdi
call   1040 <getNextMessage@plt>
mov    %rax,%rbx
mov    %r15,%rdi
call   1040 <getNextMessage@plt>
movq   $0x0,(%rsp)
test   %rbx,%rbx
je     13f4 <main+0x1e4>
nopl   (%rax)
mov    %rax,%r12
test   %rax,%rax
je     13f4 <main+0x1e4>
lea    0x40(%rsp),%rdi
mov    %rbx,%rsi
mov    %r12,%rdx
mov    %rsp,%rcx
call   1080 <buildMessage@plt>
mov    %eax,%r13d
mov    (%rsp),%rsi
mov    %ebp,%edi
mov    %eax,%edx
xor    %ecx,%ecx
lea    0x10(%rsp),%r8
mov    $0xc,%r9d
call   10a0 <sendto@plt>
cmp    $0xffffffff,%eax
je     1408 <main+0x1f8>
lea    0x30(%rsp),%rdi
xor    %esi,%esi
call   1070 <gettimeofday@plt>
mov    %ebp,%edi
lea    0x50(%rsp),%rsi
mov    $0x200,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
xor    %r9d,%r9d
call   10d0 <recvfrom@plt>
cmp    $0xffffffff,%eax
je     141a <main+0x20a>
lea    0x20(%rsp),%rdi
xor    %esi,%esi
call   1070 <gettimeofday@plt>
movslq 0x20(%rsp),%rax
movslq 0x30(%rsp),%rcx
sub    %rcx,%rax
imul   $0xf4240,%rax,%rax
mov    0x28(%rsp),%rdx
sub    0x38(%rsp),%rdx
add    %rax,%rdx
lea    0xccb(%rip),%rdi
mov    %r13d,%esi
call   1060 <printf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r12,%rdi
call   1030 <free@plt>
mov    (%rsp),%rdi
call   1030 <free@plt>
mov    %r14,%rdi
call   1040 <getNextMessage@plt>
mov    %rax,%rbx
mov    %r15,%rdi
call   1040 <getNextMessage@plt>
test   %rbx,%rbx
jne    1310 <main+0x100>
xor    %eax,%eax
add    $0x258,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2bc1(%rip),%rax
mov    (%rax),%edi
lea    0xc42(%rip),%rsi
jmp    142a <main+0x21a>
mov    0x2baf(%rip),%rax
mov    (%rax),%edi
lea    0xc43(%rip),%rsi
xor    %eax,%eax
call   10c0 <fprintf@plt>
mov    $0x1,%edi
call   1110 <exit@plt>
mov    0x2b8e(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xbb2(%rip),%rsi
xor    %eax,%eax
call   10c0 <fprintf@plt>
mov    $0x1,%edi
call   1110 <exit@plt>
mov    0x2b6a(%rip),%rax
mov    (%rax),%edi
lea    0xbbc(%rip),%rsi
jmp    142a <main+0x21a>
mov    0x2b58(%rip),%rax
mov    (%rax),%edi
lea    0xbc0(%rip),%rsi
jmp    142a <main+0x21a>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.in_addr, i32 }
%struct.in_addr = type { i32 }
%struct.hostent = type { i64 }
%struct.timeval = type { i32, i64 }
%struct.sockaddr = type { i32 }
@stderr = global i32 0
@.str = [43 x i8] c"Usage: %s <Server> <Port> <file1> <file2>\0A\00"
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str.1 = [22 x i8] c"error in connecting!\0A\00"
@.str.2 = [23 x i8] c"error in getsockname!\0A\00"
@.str.3 = [2 x i8] c"r\00"
@.str.4 = [19 x i8] c"error in sending!\0A\00"
@.str.5 = [21 x i8] c"error in receiving!\0A\00"
@.str.6 = [22 x i8] c"transmit_time\09%d\09%lu\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 %struct.sockaddr_in
%9 = alloca %struct.sockaddr_in
%10 = alloca i32
%11 = alloca %struct.hostent*
%12 = alloca i32*
%13 = alloca i32*
%14 = alloca i8*
%15 = alloca i8*
%16 = alloca i8*
%17 = alloca [512 x i8]
%18 = alloca %struct.timeval
%19 = alloca %struct.timeval
%20 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 12, i32* %10
%21 = load i32, i32* %4
%22 = icmp ne i32 %21, 5
br i1 %22, label %23, label %30
23: ; preds = %2
%24 = load i32, i32* @stderr
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 0
%27 = load i8*, i8** %26
%28 = call i32 (i32, i8*, ...) @fprintf(i32 %24, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), i8* %27)
%29 = call i32 @exit(i32 1)
unreachable
30: ; preds = %2
%31 = load i32, i32* @AF_INET
%32 = load i32, i32* @SOCK_DGRAM
%33 = call i32 @socket(i32 %31, i32 %32, i32 0)
store i32 %33, i32* %6
%34 = call i32 @memset(%struct.sockaddr_in* %8, i32 0, i32 12)
%35 = load i32, i32* @AF_INET
%36 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 2
store i32 %35, i32* %36
%37 = load i8**, i8*** %5
%38 = getelementptr inbounds i8*, i8** %37, i64 1
%39 = load i8*, i8** %38
%40 = call %struct.hostent* @gethostbyname(i8* %39)
store %struct.hostent* %40, %struct.hostent** %11
%41 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 1
%42 = load %struct.hostent*, %struct.hostent** %11
%43 = getelementptr inbounds %struct.hostent, %struct.hostent* %42, i32 0, i32 0
%44 = load i64, i64* %43
%45 = inttoptr i64 %44 to %struct.in_addr*
%46 = bitcast %struct.in_addr* %41 to i8*
%47 = bitcast %struct.in_addr* %45 to i8*
%48 = load i8**, i8*** %5
%49 = getelementptr inbounds i8*, i8** %48, i64 2
%50 = load i8*, i8** %49
%51 = call i32 @atoi(i8* %50)
%52 = call i32 @htons(i32 %51)
%53 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 0
store i32 %52, i32* %53
%54 = load i32, i32* %6
%55 = bitcast %struct.sockaddr_in* %8 to %struct.sockaddr*
%56 = call i32 @connect(i32 %54, %struct.sockaddr* %55, i32 12)
%57 = icmp eq i32 %56, -1
br i1 %57, label %58, label %62
58: ; preds = %30
%59 = load i32, i32* @stderr
%60 = call i32 (i32, i8*, ...) @fprintf(i32 %59, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
%61 = call i32 @exit(i32 1)
unreachable
62: ; preds = %30
%63 = load i32, i32* %6
%64 = bitcast %struct.sockaddr_in* %9 to %struct.sockaddr*
%65 = call i32 @getsockname(i32 %63, %struct.sockaddr* %64, i32* %10)
%66 = icmp eq i32 %65, -1
br i1 %66, label %67, label %71
67: ; preds = %62
%68 = load i32, i32* @stderr
%69 = call i32 (i32, i8*, ...) @fprintf(i32 %68, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
%70 = call i32 @exit(i32 1)
unreachable
71: ; preds = %62
%72 = load i8**, i8*** %5
%73 = getelementptr inbounds i8*, i8** %72, i64 3
%74 = load i8*, i8** %73
%75 = call i32* @fopen(i8* %74, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %75, i32** %12
%76 = load i8**, i8*** %5
%77 = getelementptr inbounds i8*, i8** %76, i64 4
%78 = load i8*, i8** %77
%79 = call i32* @fopen(i8* %78, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %79, i32** %13
%80 = load i32*, i32** %12
%81 = call i8* @getNextMessage(i32* %80)
store i8* %81, i8** %14
%82 = load i32*, i32** %13
%83 = call i8* @getNextMessage(i32* %82)
store i8* %83, i8** %15
store i8* null, i8** %16
br label %84
84: ; preds = %116, %71
%85 = load i8*, i8** %14
%86 = icmp ne i8* %85, null
br i1 %86, label %87, label %90
87: ; preds = %84
%88 = load i8*, i8** %15
%89 = icmp ne i8* %88, null
br label %90
90: ; preds = %87, %84
%91 = phi i1 [ false, %84 ], [ %89, %87 ]
br i1 %91, label %92, label %143
92: ; preds = %90
%93 = load i8*, i8** %14
%94 = load i8*, i8** %15
%95 = call i32 @buildMessage(%struct.sockaddr_in* %9, i8* %93, i8* %94, i8** %16)
store i32 %95, i32* %20
%96 = load i32, i32* %6
%97 = load i8*, i8** %16
%98 = load i32, i32* %20
%99 = bitcast %struct.sockaddr_in* %8 to %struct.sockaddr*
%100 = call i32 @sendto(i32 %96, i8* %97, i32 %98, i32 0, %struct.sockaddr* %99, i32 12)
%101 = icmp eq i32 %100, -1
br i1 %101, label %102, label %106
102: ; preds = %92
%103 = load i32, i32* @stderr
%104 = call i32 (i32, i8*, ...) @fprintf(i32 %103, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0))
%105 = call i32 @exit(i32 1)
unreachable
106: ; preds = %92
%107 = call i32 @gettimeofday(%struct.timeval* %18, i32* null)
%108 = load i32, i32* %6
%109 = getelementptr inbounds [512 x i8], [512 x i8]* %17, i64 0, i64 0
%110 = call i32 @recvfrom(i32 %108, i8* %109, i32 512, i32 0, i32* null, i32* null)
%111 = icmp eq i32 %110, -1
br i1 %111, label %112, label %116
112: ; preds = %106
%113 = load i32, i32* @stderr
%114 = call i32 (i32, i8*, ...) @fprintf(i32 %113, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0))
%115 = call i32 @exit(i32 1)
unreachable
116: ; preds = %106
%117 = call i32 @gettimeofday(%struct.timeval* %19, i32* null)
%118 = load i32, i32* %20
%119 = getelementptr inbounds %struct.timeval, %struct.timeval* %19, i32 0, i32 0
%120 = load i32, i32* %119
%121 = getelementptr inbounds %struct.timeval, %struct.timeval* %18, i32 0, i32 0
%122 = load i32, i32* %121
%123 = sub nsw i32 %120, %122
%124 = mul nsw i32 %123, 1000000
%125 = sext i32 %124 to i64
%126 = getelementptr inbounds %struct.timeval, %struct.timeval* %19, i32 0, i32 1
%127 = load i64, i64* %126
%128 = add nsw i64 %125, %127
%129 = getelementptr inbounds %struct.timeval, %struct.timeval* %18, i32 0, i32 1
%130 = load i64, i64* %129
%131 = sub nsw i64 %128, %130
%132 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.6, i64 0, i64 0), i32 %118, i64 %131)
%133 = load i8*, i8** %14
%134 = call i32 @free(i8* %133)
%135 = load i8*, i8** %15
%136 = call i32 @free(i8* %135)
%137 = load i8*, i8** %16
%138 = call i32 @free(i8* %137)
%139 = load i32*, i32** %12
%140 = call i8* @getNextMessage(i32* %139)
store i8* %140, i8** %14
%141 = load i32*, i32** %13
%142 = call i8* @getNextMessage(i32* %141)
store i8* %142, i8** %15
br label %84
143: ; preds = %90
%144 = load i32, i32* %3
ret i32 %144
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.in_addr, i32 }
%struct.in_addr = type { i32 }
%struct.timeval = type { i32, i64 }
%struct.hostent = type { i64 }
%struct.sockaddr = type { i32 }
@stderr = global i32 0
@.str = [43 x i8] c"Usage: %s <Server> <Port> <file1> <file2>\0A\00"
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str.1 = [22 x i8] c"error in connecting!\0A\00"
@.str.2 = [23 x i8] c"error in getsockname!\0A\00"
@.str.3 = [2 x i8] c"r\00"
@.str.4 = [19 x i8] c"error in sending!\0A\00"
@.str.5 = [21 x i8] c"error in receiving!\0A\00"
@.str.6 = [22 x i8] c"transmit_time\09%d\09%lu\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca %struct.sockaddr_in
%5 = alloca i32
%6 = alloca i8*
%7 = alloca [512 x i8]
%8 = alloca %struct.timeval
%9 = alloca %struct.timeval
%10 = bitcast %struct.sockaddr_in* %3 to i8*
%11 = bitcast %struct.sockaddr_in* %4 to i8*
%12 = bitcast i32* %5 to i8*
store i32 12, i32* %5
%13 = icmp eq i32 %0, 5
br i1 %13, label %19, label %14
14: ; preds = %2
%15 = load i32, i32* @stderr
%16 = load i8*, i8** %1
%17 = tail call i32 (i32, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), i8* %16)
%18 = tail call i32 @exit(i32 1)
unreachable
19: ; preds = %2
%20 = load i32, i32* @AF_INET
%21 = load i32, i32* @SOCK_DGRAM
%22 = tail call i32 @socket(i32 %20, i32 %21, i32 0)
%23 = call i32 @memset(%struct.sockaddr_in* %3, i32 0, i32 12)
%24 = load i32, i32* @AF_INET
%25 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %24, i32* %25
%26 = getelementptr inbounds i8*, i8** %1, i64 1
%27 = load i8*, i8** %26
%28 = call %struct.hostent* @gethostbyname(i8* %27)
%29 = getelementptr inbounds %struct.hostent, %struct.hostent* %28, i64 0, i32 0
%30 = load i64, i64* %29
%31 = inttoptr i64 %30 to i32*
%32 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1, i32 0
%33 = load i32, i32* %31
store i32 %33, i32* %32
%34 = getelementptr inbounds i8*, i8** %1, i64 2
%35 = load i8*, i8** %34
%36 = call i32 @atoi(i8* %35)
%37 = call i32 @htons(i32 %36)
%38 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
store i32 %37, i32* %38
%39 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%40 = call i32 @connect(i32 %22, %struct.sockaddr* %39, i32 12)
%41 = icmp eq i32 %40, -1
br i1 %41, label %42, label %46
42: ; preds = %19
%43 = load i32, i32* @stderr
%44 = call i32 (i32, i8*, ...) @fprintf(i32 %43, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
%45 = call i32 @exit(i32 1)
unreachable
46: ; preds = %19
%47 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%48 = call i32 @getsockname(i32 %22, %struct.sockaddr* %47, i32* %5)
%49 = icmp eq i32 %48, -1
br i1 %49, label %50, label %54
50: ; preds = %46
%51 = load i32, i32* @stderr
%52 = call i32 (i32, i8*, ...) @fprintf(i32 %51, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
%53 = call i32 @exit(i32 1)
unreachable
54: ; preds = %46
%55 = getelementptr inbounds i8*, i8** %1, i64 3
%56 = load i8*, i8** %55
%57 = call i32* @fopen(i8* %56, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%58 = getelementptr inbounds i8*, i8** %1, i64 4
%59 = load i8*, i8** %58
%60 = call i32* @fopen(i8* %59, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%61 = call i8* @getNextMessage(i32* %57)
%62 = call i8* @getNextMessage(i32* %60)
%63 = bitcast i8** %6 to i8*
store i8* null, i8** %6
%64 = getelementptr inbounds [512 x i8], [512 x i8]* %7, i64 0, i64 0
%65 = bitcast %struct.timeval* %8 to i8*
%66 = bitcast %struct.timeval* %9 to i8*
%67 = icmp ne i8* %61, null
%68 = icmp ne i8* %62, null
%69 = select i1 %67, i1 %68, i1 false
br i1 %69, label %70, label %115
70: ; preds = %54
%71 = getelementptr inbounds %struct.timeval, %struct.timeval* %9, i64 0, i32 0
%72 = getelementptr inbounds %struct.timeval, %struct.timeval* %8, i64 0, i32 0
%73 = getelementptr inbounds %struct.timeval, %struct.timeval* %9, i64 0, i32 1
%74 = getelementptr inbounds %struct.timeval, %struct.timeval* %8, i64 0, i32 1
br label %75
75: ; preds = %70, %94
%76 = phi i8* [ %61, %70 ], [ %110, %94 ]
%77 = phi i8* [ %62, %70 ], [ %111, %94 ]
%78 = call i32 @buildMessage(%struct.sockaddr_in* %4, i8* %76, i8* %77, i8** %6)
%79 = load i8*, i8** %6
%80 = call i32 @sendto(i32 %22, i8* %79, i32 %78, i32 0, %struct.sockaddr* %39, i32 12)
%81 = icmp eq i32 %80, -1
br i1 %81, label %82, label %86
82: ; preds = %75
%83 = load i32, i32* @stderr
%84 = call i32 (i32, i8*, ...) @fprintf(i32 %83, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0))
%85 = call i32 @exit(i32 1)
unreachable
86: ; preds = %75
%87 = call i32 @gettimeofday(%struct.timeval* %8, i32* null)
%88 = call i32 @recvfrom(i32 %22, i8* %64, i32 512, i32 0, i32* null, i32* null)
%89 = icmp eq i32 %88, -1
br i1 %89, label %90, label %94
90: ; preds = %86
%91 = load i32, i32* @stderr
%92 = call i32 (i32, i8*, ...) @fprintf(i32 %91, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0))
%93 = call i32 @exit(i32 1)
unreachable
94: ; preds = %86
%95 = call i32 @gettimeofday(%struct.timeval* %9, i32* null)
%96 = load i32, i32* %71
%97 = load i32, i32* %72
%98 = sub nsw i32 %96, %97
%99 = mul nsw i32 %98, 1000000
%100 = sext i32 %99 to i64
%101 = load i64, i64* %73
%102 = load i64, i64* %74
%103 = sub i64 %101, %102
%104 = add i64 %103, %100
%105 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.6, i64 0, i64 0), i32 %78, i64 %104)
%106 = call i32 @free(i8* %76)
%107 = call i32 @free(i8* %77)
%108 = load i8*, i8** %6
%109 = call i32 @free(i8* %108)
%110 = call i8* @getNextMessage(i32* %57)
%111 = call i8* @getNextMessage(i32* %60)
%112 = icmp ne i8* %110, null
%113 = icmp ne i8* %111, null
%114 = select i1 %112, i1 %113, i1 false
br i1 %114, label %75, label %115
115: ; preds = %94, %54
ret i32 0
}