#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ EXIT_SUCCESS;
int atoi(char *);
int /*<<< orphan*/ close(int);
int connect_server(char const *, char const *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int getopt(int, char **, char *);
int /*<<< orphan*/ handle_connect(int, int, int);
char *optarg;
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int main(int argc, char *argv[]) {
  int opt, sfd;
  int random = 1, run = 10;
  const char *server = "127.0.0.1", *port = "12345";
  while ((opt = getopt(argc, argv, "hur:s:p:")) != -1) {
    switch (opt) {
    case 'u':
      random = 0;
      break;
    case 'r':
      run = atoi(optarg);
      break;
    case 's':
      server = optarg;
      break;
    case 'p':
      port = optarg;
      break;
    default:
      fprintf(stderr,
              "Usage: %s [-u] [-r run] [-s server] [-p port]\n"
              "  -u: create request by user input, default: random generation\n"
              "  -r run: how many request to send\n"
              "  -s server: specify the server name or address, default: "
              "127.0.0.1\n"
              "  -p port: specify the server port, default: 12345\n",
              argv[0]);
      exit(EXIT_FAILURE);
    }
  }
  srand(time(NULL));
  sfd = connect_server(server, port);
  handle_connect(sfd, run, random);
  close(sfd);
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x1,-0x1c(%rbp)
movl   $0xa,-0x20(%rbp)
lea    0xe5d(%rip),%rax
mov    %rax,-0x28(%rbp)
lea    0xe5c(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe50(%rip),%rdx
call   1090 <getopt@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
je     128a <main+0xfa>
mov    -0x14(%rbp),%eax
add    $0xffffff90,%eax
mov    %eax,%ecx
mov    %rcx,-0x38(%rbp)
sub    $0x5,%eax
ja     125b <main+0xcb>
mov    -0x38(%rbp),%rax
lea    0xdf7(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movl   $0x0,-0x1c(%rbp)
jmp    1285 <main+0xf5>
mov    0x2dd3(%rip),%rax
mov    (%rax),%rdi
call   10a0 <atoi@plt>
mov    %eax,-0x20(%rbp)
jmp    1285 <main+0xf5>
mov    0x2dbc(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
jmp    1285 <main+0xf5>
mov    0x2da9(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x30(%rbp)
jmp    1285 <main+0xf5>
mov    0x2d76(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xdbf(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x2d52(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>
jmp    11ca <main+0x3a>
xor    %eax,%eax
mov    %eax,%edi
call   1070 <time@plt>
mov    %eax,%edi
call   1050 <srand@plt>
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1030 <connect_server@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%edi
mov    -0x20(%rbp),%esi
mov    -0x1c(%rbp),%edx
call   1080 <handle_connect@plt>
mov    -0x18(%rbp),%edi
call   1040 <close@plt>
mov    0x2d01(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbp
mov    %edi,%ebx
lea    0xe63(%rip),%r13
lea    0xe52(%rip),%r12
movl   $0xa,(%rsp)
movl   $0x1,0x4(%rsp)
lea    0xe4c(%rip),%r14
mov    0x2e2d(%rip),%r15
jmp    11d3 <main+0x43>
nopl   (%rax)
mov    (%r15),%r13
mov    %ebx,%edi
mov    %rbp,%rsi
mov    %r14,%rdx
call   1090 <getopt@plt>
cmp    $0x70,%eax
je     11d0 <main+0x40>
cmp    $0x72,%eax
jle    11fe <main+0x6e>
cmp    $0x73,%eax
je     120d <main+0x7d>
cmp    $0x75,%eax
jne    1255 <main+0xc5>
movl   $0x0,0x4(%rsp)
jmp    11d3 <main+0x43>
jne    1212 <main+0x82>
mov    (%r15),%rdi
call   10a0 <atoi@plt>
mov    %eax,(%rsp)
jmp    11d3 <main+0x43>
mov    (%r15),%r12
jmp    11d3 <main+0x43>
cmp    $0xffffffff,%eax
jne    1255 <main+0xc5>
xor    %edi,%edi
call   1070 <time@plt>
mov    %eax,%edi
call   1050 <srand@plt>
mov    %r12,%rdi
mov    %r13,%rsi
call   1030 <connect_server@plt>
mov    %eax,%ebx
mov    %eax,%edi
mov    (%rsp),%esi
mov    0x4(%rsp),%edx
call   1080 <handle_connect@plt>
mov    %ebx,%edi
call   1040 <close@plt>
mov    0x2d7a(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>
mov    0x2d7c(%rip),%rax
mov    (%rax),%edi
mov    0x0(%rbp),%rdx
lea    0xdb0(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x2d5b(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@.str = [10 x i8] c"127.0.0.1\00"
@.str.1 = [6 x i8] c"12345\00"
@.str.2 = [9 x i8] c"hur:s:p:\00"
@optarg = global i8* null
@stderr = global i32 0
@.str.3 = [264 x i8] c"Usage: %s [-u] [-r run] [-s server] [-p port]\0A -u: create request by user input, default: random generation\0A -r run: how many request to send\0A -s server: specify the server name or address, default: 127.0.0.1\0A -p port: specify the server port, default: 12345\0A\00"
@EXIT_FAILURE = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 1, i32* %8
store i32 10, i32* %9
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8** %10
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8** %11
br label %12
12: ; preds = %35, %2
%13 = load i32, i32* %4
%14 = load i8**, i8*** %5
%15 = call i32 @getopt(i32 %13, i8** %14, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
store i32 %15, i32* %6
%16 = icmp ne i32 %15, -1
br i1 %16, label %17, label %36
17: ; preds = %12
%18 = load i32, i32* %6
switch i32 %18, label %27 [
i32 117, label %19
i32 114, label %20
i32 115, label %23
i32 112, label %25
]
19: ; preds = %17
store i32 0, i32* %8
br label %35
20: ; preds = %17
%21 = load i8*, i8** @optarg
%22 = call i32 @atoi(i8* %21)
store i32 %22, i32* %9
br label %35
23: ; preds = %17
%24 = load i8*, i8** @optarg
store i8* %24, i8** %10
br label %35
25: ; preds = %17
%26 = load i8*, i8** @optarg
store i8* %26, i8** %11
br label %35
27: ; preds = %17
%28 = load i32, i32* @stderr
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 0
%31 = load i8*, i8** %30
%32 = call i32 @fprintf(i32 %28, i8* getelementptr inbounds ([264 x i8], [264 x i8]* @.str.3, i64 0, i64 0), i8* %31)
%33 = load i32, i32* @EXIT_FAILURE
%34 = call i32 @exit(i32 %33)
unreachable
35: ; preds = %25, %23, %20, %19
br label %12
36: ; preds = %12
%37 = call i32 @time(i32* null)
%38 = call i32 @srand(i32 %37)
%39 = load i8*, i8** %10
%40 = load i8*, i8** %11
%41 = call i32 @connect_server(i8* %39, i8* %40)
store i32 %41, i32* %7
%42 = load i32, i32* %7
%43 = load i32, i32* %9
%44 = load i32, i32* %8
%45 = call i32 @handle_connect(i32 %42, i32 %43, i32 %44)
%46 = load i32, i32* %7
%47 = call i32 @close(i32 %46)
%48 = load i32, i32* @EXIT_SUCCESS
%49 = call i32 @exit(i32 %48)
unreachable
}

LLVM IR (-O2):
@.str = [10 x i8] c"127.0.0.1\00"
@.str.1 = [6 x i8] c"12345\00"
@.str.2 = [9 x i8] c"hur:s:p:\00"
@optarg = global i8* null
@stderr = global i32 0
@.str.3 = [264 x i8] c"Usage: %s [-u] [-r run] [-s server] [-p port]\0A -u: create request by user input, default: random generation\0A -r run: how many request to send\0A -s server: specify the server name or address, default: 127.0.0.1\0A -p port: specify the server port, default: 12345\0A\00"
@EXIT_FAILURE = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
br label %3
3: ; preds = %15, %2
%4 = phi i32 [ 1, %2 ], [ 0, %15 ]
%5 = phi i32 [ 10, %2 ], [ %9, %15 ]
%6 = phi i8* [ getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), %2 ], [ %13, %15 ]
%7 = phi i8* [ getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), %2 ], [ %16, %15 ]
br label %8
8: ; preds = %3, %18
%9 = phi i32 [ %5, %3 ], [ %20, %18 ]
%10 = phi i8* [ %6, %3 ], [ %13, %18 ]
%11 = phi i8* [ %7, %3 ], [ %16, %18 ]
br label %12
12: ; preds = %8, %21
%13 = phi i8* [ %10, %8 ], [ %22, %21 ]
%14 = phi i8* [ %11, %8 ], [ %16, %21 ]
br label %15
15: ; preds = %12, %23
%16 = phi i8* [ %24, %23 ], [ %14, %12 ]
%17 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
switch i32 %17, label %25 [
i32 -1, label %31
i32 117, label %3
i32 114, label %18
i32 115, label %21
i32 112, label %23
]
18: ; preds = %15
%19 = load i8*, i8** @optarg
%20 = tail call i32 @atoi(i8* %19)
br label %8
21: ; preds = %15
%22 = load i8*, i8** @optarg
br label %12
23: ; preds = %15
%24 = load i8*, i8** @optarg
br label %15
25: ; preds = %15
%26 = load i32, i32* @stderr
%27 = load i8*, i8** %1
%28 = tail call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([264 x i8], [264 x i8]* @.str.3, i64 0, i64 0), i8* %27)
%29 = load i32, i32* @EXIT_FAILURE
%30 = tail call i32 @exit(i32 %29)
unreachable
31: ; preds = %15
%32 = tail call i32 @time(i32* null)
%33 = tail call i32 @srand(i32 %32)
%34 = tail call i32 @connect_server(i8* %13, i8* %16)
%35 = tail call i32 @handle_connect(i32 %34, i32 %9, i32 %4)
%36 = tail call i32 @close(i32 %34)
%37 = load i32, i32* @EXIT_SUCCESS
%38 = tail call i32 @exit(i32 %37)
unreachable
}