#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 */
typedef char uint32_t;
struct timeval {
  int tv_sec;
  int tv_usec;
};
struct sockaddr_in {
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_addr;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
struct hostent {
  int /*<<< orphan*/ h_length;
  int /*<<< orphan*/ h_addr;
};
typedef int socklen_t;
typedef int /*<<< orphan*/ sin;
typedef int /*<<< orphan*/ encrypted_message;
typedef int /*<<< orphan*/ buf;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ PF_INET;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ bcopy(int /*<<< orphan*/, char *, int /*<<< orphan*/);
int /*<<< orphan*/ bzero(char *, int);
unsigned long checksum(char *);
char *decrypt(char *);
char *encrypt(char *, char *);
int /*<<< orphan*/ exit(int);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
char *getPubKey();
struct hostent *gethostbyname(char *);
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int /*<<< orphan*/ htons(int);
unsigned long ntohl(char);
int /*<<< orphan*/ perror(char *);
int recvfrom(int, char *, int, int /*<<< orphan*/, struct sockaddr *, int *);
int sendto(int, char *, int, int /*<<< orphan*/, struct sockaddr *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ sscanf(char *, char *, int *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
int /*<<< orphan*/ usage(char *, int);
int main(int argc, char *argv[]) {
  FILE *fp;
  struct hostent *hp;
  struct sockaddr_in sin;
  char *host;
  char buf[4096];
  int s, len;
  int SERVER_PORT;
  char message[4096];
  bool is_file = false;
  char *public_key = getPubKey();
  if (argc == 4) {
    host = argv[1];
    sscanf(argv[2], "%i", &SERVER_PORT);
    if ((fp = fopen(argv[3], "r+")) != NULL) {
      is_file = true;
    } else {
      strcpy(message, argv[3]);
    }
  } else {
    usage(argv[0], 1);
  }
  hp = gethostbyname(host);
  if (!hp) {
    fprintf(stderr, "client: unknown host %s\n", host);
    exit(1);
  }
  bzero((char *)&sin, sizeof(sin));
  sin.sin_family = AF_INET;
  bcopy(hp->h_addr, (char *)&sin.sin_addr, hp->h_length);
  sin.sin_port = htons(SERVER_PORT);
  if ((s = socket(PF_INET, SOCK_DGRAM, 0)) < 0) {
    perror("client: socket\n");
    exit(1);
  }
  len = strlen(public_key) + 1;
  if (sendto(s, public_key, len, 0, (struct sockaddr *)&sin,
             sizeof(struct sockaddr)) == -1) {
    perror("client: sendto\n");
    exit(1);
  }
  char encrypted_message[4096];
  socklen_t addr_len = sizeof(sin);
  if (recvfrom(s, encrypted_message, sizeof(encrypted_message), 0,
               (struct sockaddr *)&sin, &addr_len) == -1) {
    perror("Receive error!\n");
    exit(1);
  }
  char *decrypted_message = decrypt(encrypted_message);
  if (is_file) {
    while (fgets(buf, sizeof(buf), fp)) {
      strcat(message, buf);
    }
  }
  unsigned long sum = checksum(message);
  fprintf(stdout, "Checksum sent: %lu\n", sum);
  char *actual_message = encrypt(message, decrypted_message);
  len = strlen(actual_message) + 1;
  if (sendto(s, actual_message, len, 0, (struct sockaddr *)&sin,
             sizeof(struct sockaddr)) == -1) {
    perror("client: sendto\n");
    exit(1);
  }
  struct timeval time_struct;
  gettimeofday(&time_struct, NULL);
  long unsigned start_time = 1000000 * time_struct.tv_sec + time_struct.tv_usec;
  uint32_t received_sum;
  if (recvfrom(s, &received_sum, sizeof(uint32_t), 0, (struct sockaddr *)&sin,
               &addr_len) == -1) {
    perror("Receive error!\n");
    exit(1);
  }
  gettimeofday(&time_struct, NULL);
  long unsigned end_time = 1000000 * time_struct.tv_sec + time_struct.tv_usec;
  long unsigned RTT = end_time - start_time;
  unsigned long converted = ntohl(received_sum);
  if (converted != sum) {
    perror("client: checksum\n");
    exit(1);
  }
  fprintf(stdout, "Checksum received: %lu\n", converted);
  fprintf(stdout, "RTT: %lu microseconds\n", RTT);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30b0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x2054(%rbp)
mov    $0x0,%al
call   1180 <getPubKey@plt>
mov    %rax,-0x2060(%rbp)
cmpl   $0x4,-0x8(%rbp)
jne    131c <main+0xac>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xd3a(%rip),%rsi
lea    -0x104c(%rbp),%rdx
call   10f0 <sscanf@plt>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
lea    0xd22(%rip),%rsi
call   1120 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     1303 <main+0x93>
movl   $0x1,-0x2054(%rbp)
jmp    1317 <main+0xa7>
lea    -0x2050(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rsi
call   1040 <strcpy@plt>
jmp    132d <main+0xbd>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    $0x1,%esi
call   1110 <usage@plt>
mov    -0x38(%rbp),%rdi
call   10c0 <gethostbyname@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    136a <main+0xfa>
mov    0x2c84(%rip),%rax
mov    (%rax),%edi
mov    -0x38(%rbp),%rdx
lea    0xcad(%rip),%rsi
mov    $0x0,%al
call   10d0 <fprintf@plt>
mov    $0x1,%edi
call   1160 <exit@plt>
lea    -0x30(%rbp),%rdi
mov    $0xc,%esi
call   1140 <bzero@plt>
mov    0x2c69(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
mov    0x4(%rax),%edi
lea    -0x30(%rbp),%rsi
add    $0x4,%rsi
mov    -0x20(%rbp),%rax
mov    (%rax),%edx
call   1100 <bcopy@plt>
mov    -0x104c(%rbp),%edi
call   1060 <htons@plt>
mov    %eax,-0x30(%rbp)
mov    0x2c15(%rip),%rax
mov    (%rax),%edi
mov    0x2c24(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1190 <socket@plt>
mov    %eax,-0x1044(%rbp)
cmp    $0x0,%eax
jge    13ea <main+0x17a>
lea    0xc44(%rip),%rdi
call   1130 <perror@plt>
mov    $0x1,%edi
call   1160 <exit@plt>
mov    -0x2060(%rbp),%rdi
call   1050 <strlen@plt>
add    $0x1,%eax
mov    %eax,-0x1048(%rbp)
mov    -0x1044(%rbp),%edi
mov    -0x2060(%rbp),%rsi
mov    -0x1048(%rbp),%edx
lea    -0x30(%rbp),%r8
xor    %ecx,%ecx
mov    $0x4,%r9d
call   10a0 <sendto@plt>
cmp    $0xffffffff,%eax
jne    1442 <main+0x1d2>
lea    0xbfc(%rip),%rdi
call   1130 <perror@plt>
mov    $0x1,%edi
call   1160 <exit@plt>
movl   $0xc,-0x3064(%rbp)
mov    -0x1044(%rbp),%edi
lea    -0x3060(%rbp),%rsi
lea    -0x30(%rbp),%r8
mov    $0x1000,%edx
xor    %ecx,%ecx
lea    -0x3064(%rbp),%r9
call   10e0 <recvfrom@plt>
cmp    $0xffffffff,%eax
jne    148f <main+0x21f>
lea    0xbbf(%rip),%rdi
call   1130 <perror@plt>
mov    $0x1,%edi
call   1160 <exit@plt>
lea    -0x3060(%rbp),%rdi
call   1030 <decrypt@plt>
mov    %rax,-0x3070(%rbp)
cmpl   $0x0,-0x2054(%rbp)
je     14f0 <main+0x280>
jmp    14b4 <main+0x244>
lea    -0x1040(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x1000,%esi
call   10b0 <fgets@plt>
cmp    $0x0,%rax
je     14eb <main+0x27b>
lea    -0x2050(%rbp),%rdi
lea    -0x1040(%rbp),%rsi
call   1150 <strcat@plt>
jmp    14b4 <main+0x244>
jmp    14f0 <main+0x280>
lea    -0x2050(%rbp),%rdi
call   1080 <checksum@plt>
mov    %rax,-0x3078(%rbp)
mov    0x2ab6(%rip),%rax
mov    (%rax),%edi
mov    -0x3078(%rbp),%rdx
lea    0xb35(%rip),%rsi
mov    $0x0,%al
call   10d0 <fprintf@plt>
lea    -0x2050(%rbp),%rdi
mov    -0x3070(%rbp),%rsi
call   1070 <encrypt@plt>
mov    %rax,-0x3080(%rbp)
mov    -0x3080(%rbp),%rdi
call   1050 <strlen@plt>
add    $0x1,%eax
mov    %eax,-0x1048(%rbp)
mov    -0x1044(%rbp),%edi
mov    -0x3080(%rbp),%rsi
mov    -0x1048(%rbp),%edx
lea    -0x30(%rbp),%r8
xor    %ecx,%ecx
mov    $0x4,%r9d
call   10a0 <sendto@plt>
cmp    $0xffffffff,%eax
jne    1593 <main+0x323>
lea    0xaab(%rip),%rdi
call   1130 <perror@plt>
mov    $0x1,%edi
call   1160 <exit@plt>
lea    -0x3088(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1090 <gettimeofday@plt>
imul   $0xf4240,-0x3088(%rbp),%eax
add    -0x3084(%rbp),%eax
cltq
mov    %rax,-0x3090(%rbp)
mov    -0x1044(%rbp),%edi
lea    -0x30(%rbp),%r8
lea    -0x3091(%rbp),%rsi
mov    $0x1,%edx
xor    %ecx,%ecx
lea    -0x3064(%rbp),%r9
call   10e0 <recvfrom@plt>
cmp    $0xffffffff,%eax
jne    15ff <main+0x38f>
lea    0xa4f(%rip),%rdi
call   1130 <perror@plt>
mov    $0x1,%edi
call   1160 <exit@plt>
lea    -0x3088(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1090 <gettimeofday@plt>
imul   $0xf4240,-0x3088(%rbp),%eax
add    -0x3084(%rbp),%eax
cltq
mov    %rax,-0x30a0(%rbp)
mov    -0x30a0(%rbp),%rax
sub    -0x3090(%rbp),%rax
mov    %rax,-0x30a8(%rbp)
movsbl -0x3091(%rbp),%edi
call   1170 <ntohl@plt>
mov    %rax,-0x30b0(%rbp)
mov    -0x30b0(%rbp),%rax
cmp    -0x3078(%rbp),%rax
je     167a <main+0x40a>
lea    0x9f8(%rip),%rdi
call   1130 <perror@plt>
mov    $0x1,%edi
call   1160 <exit@plt>
mov    0x293f(%rip),%rax
mov    (%rax),%edi
mov    -0x30b0(%rbp),%rdx
lea    0x9e4(%rip),%rsi
mov    $0x0,%al
call   10d0 <fprintf@plt>
mov    0x2921(%rip),%rax
mov    (%rax),%edi
mov    -0x30a8(%rbp),%rdx
lea    0x9de(%rip),%rsi
mov    $0x0,%al
call   10d0 <fprintf@plt>
mov    -0x4(%rbp),%eax
add    $0x30b0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x3038,%rsp
mov    %rsi,%rbp
mov    %edi,%ebx
xor    %eax,%eax
call   1180 <getPubKey@plt>
mov    %rax,%r14
cmp    $0x4,%ebx
jne    12ca <main+0x5a>
mov    0x8(%rbp),%r15
mov    0x10(%rbp),%rdi
lea    0xd5c(%rip),%rsi
lea    0x2c(%rsp),%rdx
call   10f0 <sscanf@plt>
mov    0x18(%rbp),%rdi
lea    0xd4a(%rip),%rsi
call   1120 <fopen@plt>
test   %rax,%rax
je     12dd <main+0x6d>
mov    %rax,%r12
xor    %ebp,%ebp
jmp    12f1 <main+0x81>
mov    0x0(%rbp),%rdi
mov    $0x1,%esi
call   1110 <usage@plt>
mov    $0x1,%bpl
jmp    12f1 <main+0x81>
mov    0x18(%rbp),%rsi
lea    0x30(%rsp),%rdi
call   1040 <strcpy@plt>
mov    $0x1,%bpl
xor    %r12d,%r12d
mov    %r15,%rdi
call   10c0 <gethostbyname@plt>
test   %rax,%rax
je     1554 <main+0x2e4>
mov    %rax,%rbx
lea    0x20(%rsp),%rdi
mov    $0xc,%esi
call   1140 <bzero@plt>
mov    0x2ccd(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x28(%rsp)
mov    (%rbx),%edx
mov    0x4(%rbx),%edi
lea    0x24(%rsp),%rsi
call   1100 <bcopy@plt>
mov    0x2c(%rsp),%edi
call   1060 <htons@plt>
mov    %eax,0x20(%rsp)
mov    0x2c84(%rip),%rax
mov    (%rax),%edi
mov    0x2c93(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1190 <socket@plt>
test   %eax,%eax
js     1578 <main+0x308>
mov    %eax,%r15d
mov    %r14,%rdi
call   1050 <strlen@plt>
lea    0x1(%rax),%edx
lea    0x20(%rsp),%r8
mov    %r15d,%edi
mov    %r14,%rsi
xor    %ecx,%ecx
mov    $0x4,%r9d
call   10a0 <sendto@plt>
cmp    $0xffffffff,%eax
je     1542 <main+0x2d2>
movl   $0xc,0x1c(%rsp)
lea    0x1030(%rsp),%rsi
lea    0x20(%rsp),%r8
lea    0x1c(%rsp),%r9
mov    %r15d,%edi
mov    $0x1000,%edx
xor    %ecx,%ecx
call   10e0 <recvfrom@plt>
cmp    $0xffffffff,%eax
je     154b <main+0x2db>
lea    0x1030(%rsp),%rdi
call   1030 <decrypt@plt>
mov    %rax,%r14
test   %bpl,%bpl
jne    1420 <main+0x1b0>
lea    0x2030(%rsp),%rdi
mov    $0x1000,%esi
mov    %r12,%rdx
call   10b0 <fgets@plt>
test   %rax,%rax
je     1420 <main+0x1b0>
lea    0x30(%rsp),%rbp
lea    0x2030(%rsp),%rbx
nopl   0x0(%rax,%rax,1)
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1150 <strcat@plt>
mov    %rbx,%rdi
mov    $0x1000,%esi
mov    %r12,%rdx
call   10b0 <fgets@plt>
test   %rax,%rax
jne    1400 <main+0x190>
lea    0x30(%rsp),%rbp
mov    %rbp,%rdi
call   1080 <checksum@plt>
mov    %rax,%r12
mov    0x2b89(%rip),%rax
mov    (%rax),%edi
lea    0xc0f(%rip),%rsi
mov    %r12,%rdx
xor    %eax,%eax
call   10d0 <fprintf@plt>
mov    %rbp,%rdi
mov    %r14,%rsi
call   1070 <encrypt@plt>
mov    %rax,%rbp
mov    %rax,%rdi
call   1050 <strlen@plt>
lea    0x1(%rax),%edx
lea    0x20(%rsp),%r8
mov    %r15d,%edi
mov    %rbp,%rsi
xor    %ecx,%ecx
mov    $0x4,%r9d
call   10a0 <sendto@plt>
cmp    $0xffffffff,%eax
je     1542 <main+0x2d2>
lea    0x10(%rsp),%rdi
xor    %esi,%esi
call   1090 <gettimeofday@plt>
movslq 0x10(%rsp),%r13
movslq 0x14(%rsp),%r14
lea    0xf(%rsp),%rsi
lea    0x20(%rsp),%r8
lea    0x1c(%rsp),%r9
mov    %r15d,%edi
mov    $0x1,%edx
xor    %ecx,%ecx
call   10e0 <recvfrom@plt>
cmp    $0xffffffff,%eax
je     154b <main+0x2db>
lea    0x10(%rsp),%rdi
xor    %esi,%esi
call   1090 <gettimeofday@plt>
movslq 0x10(%rsp),%rbp
movslq 0x14(%rsp),%rbx
movsbl 0xf(%rsp),%edi
call   1170 <ntohl@plt>
cmp    %r12,%rax
jne    1581 <main+0x311>
imul   $0xf4240,%rbp,%rbp
add    %rbx,%rbp
imul   $0xf4240,%r13,%rax
add    %r14,%rax
sub    %rax,%rbp
mov    0x2ab8(%rip),%rbx
mov    (%rbx),%edi
lea    0xb64(%rip),%rsi
mov    %r12,%rdx
xor    %eax,%eax
call   10d0 <fprintf@plt>
mov    (%rbx),%edi
lea    0xb69(%rip),%rsi
mov    %rbp,%rdx
xor    %eax,%eax
call   10d0 <fprintf@plt>
xor    %eax,%eax
add    $0x3038,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xae6(%rip),%rdi
jmp    1588 <main+0x318>
lea    0xaed(%rip),%rdi
jmp    1588 <main+0x318>
mov    0x2a75(%rip),%rax
mov    (%rax),%edi
lea    0xaa2(%rip),%rsi
mov    %r15,%rdx
xor    %eax,%eax
call   10d0 <fprintf@plt>
mov    $0x1,%edi
call   1160 <exit@plt>
lea    0xaa0(%rip),%rdi
jmp    1588 <main+0x318>
lea    0xadb(%rip),%rdi
call   1130 <perror@plt>
mov    $0x1,%edi
call   1160 <exit@plt>

LLVM IR (-O0):
%struct.hostent = type { i32, i32 }
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.timeval = type { i32, i32 }
%struct.sockaddr = type { i32 }
@.str = [3 x i8] c"%i\00"
@.str.1 = [3 x i8] c"r+\00"
@stderr = global i32 0
@.str.2 = [25 x i8] c"client: unknown host %s\0A\00"
@AF_INET = global i32 0
@PF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str.3 = [16 x i8] c"client: socket\0A\00"
@.str.4 = [16 x i8] c"client: sendto\0A\00"
@.str.5 = [16 x i8] c"Receive error!\0A\00"
@stdout = global i32 0
@.str.6 = [20 x i8] c"Checksum sent: %lu\0A\00"
@.str.7 = [18 x i8] c"client: checksum\0A\00"
@.str.8 = [24 x i8] c"Checksum received: %lu\0A\00"
@.str.9 = [23 x i8] c"RTT: %lu microseconds\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca %struct.hostent*
%8 = alloca %struct.sockaddr_in
%9 = alloca i8*
%10 = alloca [4096 x i8]
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca [4096 x i8]
%15 = alloca i32
%16 = alloca i8*
%17 = alloca [4096 x i8]
%18 = alloca i32
%19 = alloca i8*
%20 = alloca i64
%21 = alloca i8*
%22 = alloca %struct.timeval
%23 = alloca i64
%24 = alloca i8
%25 = alloca i64
%26 = alloca i64
%27 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %15
%28 = call i8* (...) @getPubKey()
store i8* %28, i8** %16
%29 = load i32, i32* %4
%30 = icmp eq i32 %29, 4
br i1 %30, label %31, label %52
31: ; preds = %2
%32 = load i8**, i8*** %5
%33 = getelementptr inbounds i8*, i8** %32, i64 1
%34 = load i8*, i8** %33
store i8* %34, i8** %9
%35 = load i8**, i8*** %5
%36 = getelementptr inbounds i8*, i8** %35, i64 2
%37 = load i8*, i8** %36
%38 = call i32 @sscanf(i8* %37, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %13)
%39 = load i8**, i8*** %5
%40 = getelementptr inbounds i8*, i8** %39, i64 3
%41 = load i8*, i8** %40
%42 = call i32* @fopen(i8* %41, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %42, i32** %6
%43 = icmp ne i32* %42, null
br i1 %43, label %44, label %45
44: ; preds = %31
store i32 1, i32* %15
br label %51
45: ; preds = %31
%46 = getelementptr inbounds [4096 x i8], [4096 x i8]* %14, i64 0, i64 0
%47 = load i8**, i8*** %5
%48 = getelementptr inbounds i8*, i8** %47, i64 3
%49 = load i8*, i8** %48
%50 = call i32 @strcpy(i8* %46, i8* %49)
br label %51
51: ; preds = %45, %44
br label %57
52: ; preds = %2
%53 = load i8**, i8*** %5
%54 = getelementptr inbounds i8*, i8** %53, i64 0
%55 = load i8*, i8** %54
%56 = call i32 @usage(i8* %55, i32 1)
br label %57
57: ; preds = %52, %51
%58 = load i8*, i8** %9
%59 = call %struct.hostent* @gethostbyname(i8* %58)
store %struct.hostent* %59, %struct.hostent** %7
%60 = load %struct.hostent*, %struct.hostent** %7
%61 = icmp ne %struct.hostent* %60, null
br i1 %61, label %67, label %62
62: ; preds = %57
%63 = load i32, i32* @stderr
%64 = load i8*, i8** %9
%65 = call i32 (i32, i8*, ...) @fprintf(i32 %63, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i8* %64)
%66 = call i32 @exit(i32 1)
unreachable
67: ; preds = %57
%68 = bitcast %struct.sockaddr_in* %8 to i8*
%69 = call i32 @bzero(i8* %68, i32 12)
%70 = load i32, i32* @AF_INET
%71 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 2
store i32 %70, i32* %71
%72 = load %struct.hostent*, %struct.hostent** %7
%73 = getelementptr inbounds %struct.hostent, %struct.hostent* %72, i32 0, i32 1
%74 = load i32, i32* %73
%75 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 1
%76 = bitcast i32* %75 to i8*
%77 = load %struct.hostent*, %struct.hostent** %7
%78 = getelementptr inbounds %struct.hostent, %struct.hostent* %77, i32 0, i32 0
%79 = load i32, i32* %78
%80 = call i32 @bcopy(i32 %74, i8* %76, i32 %79)
%81 = load i32, i32* %13
%82 = call i32 @htons(i32 %81)
%83 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 0
store i32 %82, i32* %83
%84 = load i32, i32* @PF_INET
%85 = load i32, i32* @SOCK_DGRAM
%86 = call i32 @socket(i32 %84, i32 %85, i32 0)
store i32 %86, i32* %11
%87 = icmp slt i32 %86, 0
br i1 %87, label %88, label %91
88: ; preds = %67
%89 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
%90 = call i32 @exit(i32 1)
unreachable
91: ; preds = %67
%92 = load i8*, i8** %16
%93 = call i32 @strlen(i8* %92)
%94 = add nsw i32 %93, 1
store i32 %94, i32* %12
%95 = load i32, i32* %11
%96 = load i8*, i8** %16
%97 = load i32, i32* %12
%98 = bitcast %struct.sockaddr_in* %8 to %struct.sockaddr*
%99 = call i32 @sendto(i32 %95, i8* %96, i32 %97, i32 0, %struct.sockaddr* %98, i32 4)
%100 = icmp eq i32 %99, -1
br i1 %100, label %101, label %104
101: ; preds = %91
%102 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0))
%103 = call i32 @exit(i32 1)
unreachable
104: ; preds = %91
store i32 12, i32* %18
%105 = load i32, i32* %11
%106 = getelementptr inbounds [4096 x i8], [4096 x i8]* %17, i64 0, i64 0
%107 = bitcast %struct.sockaddr_in* %8 to %struct.sockaddr*
%108 = call i32 @recvfrom(i32 %105, i8* %106, i32 4096, i32 0, %struct.sockaddr* %107, i32* %18)
%109 = icmp eq i32 %108, -1
br i1 %109, label %110, label %113
110: ; preds = %104
%111 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0))
%112 = call i32 @exit(i32 1)
unreachable
113: ; preds = %104
%114 = getelementptr inbounds [4096 x i8], [4096 x i8]* %17, i64 0, i64 0
%115 = call i8* @decrypt(i8* %114)
store i8* %115, i8** %19
%116 = load i32, i32* %15
%117 = icmp ne i32 %116, 0
br i1 %117, label %118, label %129
118: ; preds = %113
br label %119
119: ; preds = %124, %118
%120 = getelementptr inbounds [4096 x i8], [4096 x i8]* %10, i64 0, i64 0
%121 = load i32*, i32** %6
%122 = call i64 @fgets(i8* %120, i32 4096, i32* %121)
%123 = icmp ne i64 %122, 0
br i1 %123, label %124, label %128
124: ; preds = %119
%125 = getelementptr inbounds [4096 x i8], [4096 x i8]* %14, i64 0, i64 0
%126 = getelementptr inbounds [4096 x i8], [4096 x i8]* %10, i64 0, i64 0
%127 = call i32 @strcat(i8* %125, i8* %126)
br label %119
128: ; preds = %119
br label %129
129: ; preds = %128, %113
%130 = getelementptr inbounds [4096 x i8], [4096 x i8]* %14, i64 0, i64 0
%131 = call i64 @checksum(i8* %130)
store i64 %131, i64* %20
%132 = load i32, i32* @stdout
%133 = load i64, i64* %20
%134 = call i32 (i32, i8*, ...) @fprintf(i32 %132, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.6, i64 0, i64 0), i64 %133)
%135 = getelementptr inbounds [4096 x i8], [4096 x i8]* %14, i64 0, i64 0
%136 = load i8*, i8** %19
%137 = call i8* @encrypt(i8* %135, i8* %136)
store i8* %137, i8** %21
%138 = load i8*, i8** %21
%139 = call i32 @strlen(i8* %138)
%140 = add nsw i32 %139, 1
store i32 %140, i32* %12
%141 = load i32, i32* %11
%142 = load i8*, i8** %21
%143 = load i32, i32* %12
%144 = bitcast %struct.sockaddr_in* %8 to %struct.sockaddr*
%145 = call i32 @sendto(i32 %141, i8* %142, i32 %143, i32 0, %struct.sockaddr* %144, i32 4)
%146 = icmp eq i32 %145, -1
br i1 %146, label %147, label %150
147: ; preds = %129
%148 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0))
%149 = call i32 @exit(i32 1)
unreachable
150: ; preds = %129
%151 = call i32 @gettimeofday(%struct.timeval* %22, i32* null)
%152 = getelementptr inbounds %struct.timeval, %struct.timeval* %22, i32 0, i32 0
%153 = load i32, i32* %152
%154 = mul nsw i32 1000000, %153
%155 = getelementptr inbounds %struct.timeval, %struct.timeval* %22, i32 0, i32 1
%156 = load i32, i32* %155
%157 = add nsw i32 %154, %156
%158 = sext i32 %157 to i64
store i64 %158, i64* %23
%159 = load i32, i32* %11
%160 = bitcast %struct.sockaddr_in* %8 to %struct.sockaddr*
%161 = call i32 @recvfrom(i32 %159, i8* %24, i32 1, i32 0, %struct.sockaddr* %160, i32* %18)
%162 = icmp eq i32 %161, -1
br i1 %162, label %163, label %166
163: ; preds = %150
%164 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0))
%165 = call i32 @exit(i32 1)
unreachable
166: ; preds = %150
%167 = call i32 @gettimeofday(%struct.timeval* %22, i32* null)
%168 = getelementptr inbounds %struct.timeval, %struct.timeval* %22, i32 0, i32 0
%169 = load i32, i32* %168
%170 = mul nsw i32 1000000, %169
%171 = getelementptr inbounds %struct.timeval, %struct.timeval* %22, i32 0, i32 1
%172 = load i32, i32* %171
%173 = add nsw i32 %170, %172
%174 = sext i32 %173 to i64
store i64 %174, i64* %25
%175 = load i64, i64* %25
%176 = load i64, i64* %23
%177 = sub i64 %175, %176
store i64 %177, i64* %26
%178 = load i8, i8* %24
%179 = call i64 @ntohl(i8 signext %178)
store i64 %179, i64* %27
%180 = load i64, i64* %27
%181 = load i64, i64* %20
%182 = icmp ne i64 %180, %181
br i1 %182, label %183, label %186
183: ; preds = %166
%184 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.7, i64 0, i64 0))
%185 = call i32 @exit(i32 1)
unreachable
186: ; preds = %166
%187 = load i32, i32* @stdout
%188 = load i64, i64* %27
%189 = call i32 (i32, i8*, ...) @fprintf(i32 %187, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.8, i64 0, i64 0), i64 %188)
%190 = load i32, i32* @stdout
%191 = load i64, i64* %26
%192 = call i32 (i32, i8*, ...) @fprintf(i32 %190, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.9, i64 0, i64 0), i64 %191)
%193 = load i32, i32* %3
ret i32 %193
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.timeval = type { i32, i32 }
%struct.hostent = type { i32, i32 }
%struct.sockaddr = type { i32 }
@.str = [3 x i8] c"%i\00"
@.str.1 = [3 x i8] c"r+\00"
@stderr = global i32 0
@.str.2 = [25 x i8] c"client: unknown host %s\0A\00"
@AF_INET = global i32 0
@PF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str.3 = [16 x i8] c"client: socket\0A\00"
@.str.4 = [16 x i8] c"client: sendto\0A\00"
@.str.5 = [16 x i8] c"Receive error!\0A\00"
@stdout = global i32 0
@.str.6 = [20 x i8] c"Checksum sent: %lu\0A\00"
@.str.7 = [18 x i8] c"client: checksum\0A\00"
@.str.8 = [24 x i8] c"Checksum received: %lu\0A\00"
@.str.9 = [23 x i8] c"RTT: %lu microseconds\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca [4096 x i8]
%5 = alloca i32
%6 = alloca [4096 x i8]
%7 = alloca [4096 x i8]
%8 = alloca i32
%9 = alloca %struct.timeval
%10 = alloca i8
%11 = bitcast %struct.sockaddr_in* %3 to i8*
%12 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 0
%13 = bitcast i32* %5 to i8*
%14 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%15 = tail call i8* (...) @getPubKey()
%16 = icmp eq i32 %0, 4
br i1 %16, label %17, label %30
17: ; preds = %2
%18 = getelementptr inbounds i8*, i8** %1, i64 1
%19 = load i8*, i8** %18
%20 = getelementptr inbounds i8*, i8** %1, i64 2
%21 = load i8*, i8** %20
%22 = call i32 @sscanf(i8* %21, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %5)
%23 = getelementptr inbounds i8*, i8** %1, i64 3
%24 = load i8*, i8** %23
%25 = call i32* @fopen(i8* %24, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%26 = icmp eq i32* %25, null
br i1 %26, label %27, label %33
27: ; preds = %17
%28 = load i8*, i8** %23
%29 = call i32 @strcpy(i8* %14, i8* %28)
br label %33
30: ; preds = %2
%31 = load i8*, i8** %1
%32 = tail call i32 @usage(i8* %31, i32 1)
br label %33
33: ; preds = %17, %27, %30
%34 = phi i1 [ true, %27 ], [ true, %30 ], [ false, %17 ]
%35 = phi i8* [ %19, %27 ], [ undef, %30 ], [ %19, %17 ]
%36 = phi i32* [ null, %27 ], [ undef, %30 ], [ %25, %17 ]
%37 = call %struct.hostent* @gethostbyname(i8* %35)
%38 = icmp eq %struct.hostent* %37, null
br i1 %38, label %39, label %43
39: ; preds = %33
%40 = load i32, i32* @stderr
%41 = call i32 (i32, i8*, ...) @fprintf(i32 %40, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i8* %35)
%42 = call i32 @exit(i32 1)
unreachable
43: ; preds = %33
%44 = call i32 @bzero(i8* %11, i32 12)
%45 = load i32, i32* @AF_INET
%46 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %45, i32* %46
%47 = getelementptr inbounds %struct.hostent, %struct.hostent* %37, i64 0, i32 1
%48 = load i32, i32* %47
%49 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1
%50 = bitcast i32* %49 to i8*
%51 = getelementptr inbounds %struct.hostent, %struct.hostent* %37, i64 0, i32 0
%52 = load i32, i32* %51
%53 = call i32 @bcopy(i32 %48, i8* %50, i32 %52)
%54 = load i32, i32* %5
%55 = call i32 @htons(i32 %54)
%56 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
store i32 %55, i32* %56
%57 = load i32, i32* @PF_INET
%58 = load i32, i32* @SOCK_DGRAM
%59 = call i32 @socket(i32 %57, i32 %58, i32 0)
%60 = icmp slt i32 %59, 0
br i1 %60, label %61, label %64
61: ; preds = %43
%62 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
%63 = call i32 @exit(i32 1)
unreachable
64: ; preds = %43
%65 = call i32 @strlen(i8* %15)
%66 = add nsw i32 %65, 1
%67 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%68 = call i32 @sendto(i32 %59, i8* %15, i32 %66, i32 0, %struct.sockaddr* %67, i32 4)
%69 = icmp eq i32 %68, -1
br i1 %69, label %70, label %73
70: ; preds = %64
%71 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0))
%72 = call i32 @exit(i32 1)
unreachable
73: ; preds = %64
%74 = getelementptr inbounds [4096 x i8], [4096 x i8]* %7, i64 0, i64 0
%75 = bitcast i32* %8 to i8*
store i32 12, i32* %8
%76 = call i32 @recvfrom(i32 %59, i8* %74, i32 4096, i32 0, %struct.sockaddr* %67, i32* %8)
%77 = icmp eq i32 %76, -1
br i1 %77, label %78, label %81
78: ; preds = %73
%79 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0))
%80 = call i32 @exit(i32 1)
unreachable
81: ; preds = %73
%82 = call i8* @decrypt(i8* %74)
br i1 %34, label %90, label %83
83: ; preds = %81
%84 = call i64 @fgets(i8* %12, i32 4096, i32* %36)
%85 = icmp eq i64 %84, 0
br i1 %85, label %90, label %86
86: ; preds = %83, %86
%87 = call i32 @strcat(i8* %14, i8* %12)
%88 = call i64 @fgets(i8* %12, i32 4096, i32* %36)
%89 = icmp eq i64 %88, 0
br i1 %89, label %90, label %86
90: ; preds = %86, %83, %81
%91 = call i64 @checksum(i8* %14)
%92 = load i32, i32* @stdout
%93 = call i32 (i32, i8*, ...) @fprintf(i32 %92, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.6, i64 0, i64 0), i64 %91)
%94 = call i8* @encrypt(i8* %14, i8* %82)
%95 = call i32 @strlen(i8* %94)
%96 = add nsw i32 %95, 1
%97 = call i32 @sendto(i32 %59, i8* %94, i32 %96, i32 0, %struct.sockaddr* %67, i32 4)
%98 = icmp eq i32 %97, -1
br i1 %98, label %99, label %102
99: ; preds = %90
%100 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0))
%101 = call i32 @exit(i32 1)
unreachable
102: ; preds = %90
%103 = bitcast %struct.timeval* %9 to i8*
%104 = call i32 @gettimeofday(%struct.timeval* %9, i32* null)
%105 = getelementptr inbounds %struct.timeval, %struct.timeval* %9, i64 0, i32 0
%106 = load i32, i32* %105
%107 = getelementptr inbounds %struct.timeval, %struct.timeval* %9, i64 0, i32 1
%108 = load i32, i32* %107
%109 = call i32 @recvfrom(i32 %59, i8* %10, i32 1, i32 0, %struct.sockaddr* %67, i32* %8)
%110 = icmp eq i32 %109, -1
br i1 %110, label %111, label %114
111: ; preds = %102
%112 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0))
%113 = call i32 @exit(i32 1)
unreachable
114: ; preds = %102
%115 = call i32 @gettimeofday(%struct.timeval* %9, i32* null)
%116 = load i32, i32* %105
%117 = load i32, i32* %107
%118 = load i8, i8* %10
%119 = call i64 @ntohl(i8 signext %118)
%120 = icmp eq i64 %119, %91
br i1 %120, label %124, label %121
121: ; preds = %114
%122 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.7, i64 0, i64 0))
%123 = call i32 @exit(i32 1)
unreachable
124: ; preds = %114
%125 = mul nsw i32 %116, 1000000
%126 = add nsw i32 %125, %117
%127 = sext i32 %126 to i64
%128 = mul nsw i32 %106, 1000000
%129 = add nsw i32 %128, %108
%130 = sext i32 %129 to i64
%131 = sub nsw i64 %127, %130
%132 = load i32, i32* @stdout
%133 = call i32 (i32, i8*, ...) @fprintf(i32 %132, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.8, i64 0, i64 0), i64 %91)
%134 = load i32, i32* @stdout
%135 = call i32 (i32, i8*, ...) @fprintf(i32 %134, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.9, i64 0, i64 0), i64 %131)
ret i32 0
}