#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 atoi(char *);
int /*<<< orphan*/ client_main(int, char *);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char);
int getopt(int, char **, char *);
char *optarg;
char optopt;
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sleep(int);
int socket_connect_helper(char *, char *);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  int o;
  char *server_port = "1234";
  char *server_ip = "127.0.0.1";
  char *message = "Hello World";
  int sockfd;
  int iterations = 1;
  while ((o = getopt(argc, argv, "p:h:m:i:")) != -1) {
    switch (o) {
    case 'p':
      server_port = optarg;
      break;
    case 'h':
      server_ip = optarg;
      break;
    case 'm':
      message = optarg;
      break;
    case 'i':
      iterations = atoi(optarg);
      break;
    case '?':
      if (optopt == 'p' || optopt == 'h') {
        fprintf(stderr, "Option %c requires an argument.\n", optopt);
      } else {
        fprintf(stderr, "Unknown argument: %c.\n", optopt);
      }
      break;
    }
  }
  printf("server_ip: %s   port: %s\n", server_ip, server_port);
  sockfd = socket_connect_helper(server_ip, server_port);
  while (iterations > 0) {
    client_main(sockfd, message);
    printf(".");
    sleep(1);
    iterations--;
  }
out:
  close(sockfd);
  printf("Done.\n");
  return 0;
}


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)
lea    0xf2b(%rip),%rax
mov    %rax,-0x20(%rbp)
lea    0xf25(%rip),%rax
mov    %rax,-0x28(%rbp)
lea    0xf24(%rip),%rax
mov    %rax,-0x30(%rbp)
movl   $0x1,-0x38(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xf17(%rip),%rdx
call   1080 <getopt@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
je     12c9 <main+0x149>
mov    -0x14(%rbp),%eax
add    $0xffffffc1,%eax
mov    %eax,%ecx
mov    %rcx,-0x40(%rbp)
sub    $0x31,%eax
ja     12c4 <main+0x144>
mov    -0x40(%rbp),%rax
lea    0xe03(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    0x2deb(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
jmp    12c4 <main+0x144>
mov    0x2dd8(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
jmp    12c4 <main+0x144>
mov    0x2dc5(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x30(%rbp)
jmp    12c4 <main+0x144>
mov    0x2db2(%rip),%rax
mov    (%rax),%rdi
call   1090 <atoi@plt>
mov    %eax,-0x38(%rbp)
jmp    12c4 <main+0x144>
mov    0x2d83(%rip),%rax
movsbl (%rax),%eax
cmp    $0x70,%eax
je     127c <main+0xfc>
mov    0x2d70(%rip),%rax
movsbl (%rax),%eax
cmp    $0x68,%eax
jne    12a0 <main+0x120>
mov    0x2d4d(%rip),%rax
mov    (%rax),%edi
lea    0xe60(%rip),%rsi
mov    0x2d4d(%rip),%rax
movsbl (%rax),%edx
call   1060 <fprintf@plt>
jmp    12bf <main+0x13f>
mov    0x2d29(%rip),%rax
mov    (%rax),%edi
lea    0xe5d(%rip),%rsi
mov    0x2d29(%rip),%rax
movsbl (%rax),%edx
call   1060 <fprintf@plt>
jmp    12c4 <main+0x144>
jmp    11be <main+0x3e>
mov    -0x28(%rbp),%rsi
mov    -0x20(%rbp),%rdx
lea    0xe4c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1070 <socket_connect_helper@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x38(%rbp)
jle    132b <main+0x1ab>
mov    -0x34(%rbp),%edi
mov    -0x30(%rbp),%rsi
call   1040 <client_main@plt>
lea    0xe32(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1,%edi
call   10a0 <sleep@plt>
mov    -0x38(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x38(%rbp)
jmp    12ef <main+0x16f>
jmp    1330 <main+0x1b0>
mov    -0x34(%rbp),%edi
call   1050 <close@plt>
lea    0xe01(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
mov    $0x1,%r13d
lea    0xf08(%rip),%rax
mov    %rax,0x8(%rsp)
lea    0xf0b(%rip),%rax
mov    %rax,0x10(%rsp)
lea    0xef5(%rip),%rax
mov    %rax,(%rsp)
lea    0xf00(%rip),%r14
lea    0xe16(%rip),%r12
mov    0x2ddf(%rip),%r15
jmp    1212 <main+0x72>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    (%r15),%edi
movsbl %al,%edx
lea    0xedf(%rip),%rsi
call   1080 <fprintf@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r14,%rdx
call   10a0 <getopt@plt>
lea    -0x3f(%rax),%ecx
cmp    $0x31,%ecx
ja     1260 <main+0xc0>
movslq (%r12,%rcx,4),%rax
add    %r12,%rax
jmp    *%rax
mov    0x2da9(%rip),%rax
movzbl (%rax),%eax
cmp    $0x70,%al
je     1200 <main+0x60>
cmp    $0x68,%al
je     1200 <main+0x60>
mov    (%r15),%edi
movsbl %al,%edx
lea    0xebe(%rip),%rsi
call   1080 <fprintf@plt>
jmp    1212 <main+0x72>
cs nopw 0x0(%rax,%rax,1)
cmp    $0xffffffff,%eax
jne    1212 <main+0x72>
jmp    12b3 <main+0x113>
mov    0x2d8a(%rip),%rax
mov    (%rax),%rax
mov    %rax,(%rsp)
jmp    1212 <main+0x72>
mov    0x2d7a(%rip),%rax
mov    (%rax),%rdi
call   10b0 <atoi@plt>
mov    %eax,%r13d
jmp    1212 <main+0x72>
mov    0x2d66(%rip),%rax
mov    (%rax),%rax
mov    %rax,0x10(%rsp)
jmp    1212 <main+0x72>
mov    0x2d52(%rip),%rax
mov    (%rax),%rax
mov    %rax,0x8(%rsp)
jmp    1212 <main+0x72>
lea    0xe6a(%rip),%rdi
mov    (%rsp),%rbp
mov    %rbp,%rsi
mov    0x8(%rsp),%rbx
mov    %rbx,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1090 <socket_connect_helper@plt>
mov    %eax,%ebx
test   %r13d,%r13d
mov    0x10(%rsp),%rbp
jle    1318 <main+0x178>
add    $0x1,%r13d
nopl   0x0(%rax,%rax,1)
mov    %ebx,%edi
mov    %rbp,%rsi
call   1060 <client_main@plt>
mov    $0x2e,%edi
call   1030 <putchar@plt>
mov    $0x1,%edi
call   10c0 <sleep@plt>
add    $0xffffffff,%r13d
cmp    $0x1,%r13d
ja     12f0 <main+0x150>
mov    %ebx,%edi
call   1070 <close@plt>
lea    0xe18(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"1234\00"
@.str.1 = [10 x i8] c"127.0.0.1\00"
@.str.2 = [12 x i8] c"Hello World\00"
@.str.3 = [9 x i8] c"p:h:m:i:\00"
@optarg = global i8* null
@optopt = global i8 0
@stderr = global i32 0
@.str.4 = [33 x i8] c"Option %c requires an argument.\0A\00"
@.str.5 = [23 x i8] c"Unknown argument: %c.\0A\00"
@.str.6 = [26 x i8] c"server_ip: %s port: %s\0A\00"
@.str.7 = [2 x i8] c".\00"
@.str.8 = [7 x i8] c"Done.\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8** %7
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8** %8
store i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i8** %9
store i32 1, i32* %11
br label %12
12: ; preds = %45, %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.3, i64 0, i64 0))
store i32 %15, i32* %6
%16 = icmp ne i32 %15, -1
br i1 %16, label %17, label %46
17: ; preds = %12
%18 = load i32, i32* %6
switch i32 %18, label %45 [
i32 112, label %19
i32 104, label %21
i32 109, label %23
i32 105, label %25
i32 63, label %28
]
19: ; preds = %17
%20 = load i8*, i8** @optarg
store i8* %20, i8** %7
br label %45
21: ; preds = %17
%22 = load i8*, i8** @optarg
store i8* %22, i8** %8
br label %45
23: ; preds = %17
%24 = load i8*, i8** @optarg
store i8* %24, i8** %9
br label %45
25: ; preds = %17
%26 = load i8*, i8** @optarg
%27 = call i32 @atoi(i8* %26)
store i32 %27, i32* %11
br label %45
28: ; preds = %17
%29 = load i8, i8* @optopt
%30 = sext i8 %29 to i32
%31 = icmp eq i32 %30, 112
br i1 %31, label %36, label %32
32: ; preds = %28
%33 = load i8, i8* @optopt
%34 = sext i8 %33 to i32
%35 = icmp eq i32 %34, 104
br i1 %35, label %36, label %40
36: ; preds = %32, %28
%37 = load i32, i32* @stderr
%38 = load i8, i8* @optopt
%39 = call i32 @fprintf(i32 %37, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0), i8 signext %38)
br label %44
40: ; preds = %32
%41 = load i32, i32* @stderr
%42 = load i8, i8* @optopt
%43 = call i32 @fprintf(i32 %41, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0), i8 signext %42)
br label %44
44: ; preds = %40, %36
br label %45
45: ; preds = %17, %44, %25, %23, %21, %19
br label %12
46: ; preds = %12
%47 = load i8*, i8** %8
%48 = load i8*, i8** %7
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.6, i64 0, i64 0), i8* %47, i8* %48)
%50 = load i8*, i8** %8
%51 = load i8*, i8** %7
%52 = call i32 @socket_connect_helper(i8* %50, i8* %51)
store i32 %52, i32* %10
br label %53
53: ; preds = %56, %46
%54 = load i32, i32* %11
%55 = icmp sgt i32 %54, 0
br i1 %55, label %56, label %64
56: ; preds = %53
%57 = load i32, i32* %10
%58 = load i8*, i8** %9
%59 = call i32 @client_main(i32 %57, i8* %58)
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
%61 = call i32 @sleep(i32 1)
%62 = load i32, i32* %11
%63 = add nsw i32 %62, -1
store i32 %63, i32* %11
br label %53
64: ; preds = %53
br label %65
65: ; preds = %64
%66 = load i32, i32* %10
%67 = call i32 @close(i32 %66)
%68 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.8, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str = [5 x i8] c"1234\00"
@.str.1 = [10 x i8] c"127.0.0.1\00"
@.str.2 = [12 x i8] c"Hello World\00"
@.str.3 = [9 x i8] c"p:h:m:i:\00"
@optarg = global i8* null
@optopt = global i8 0
@stderr = global i32 0
@.str.4 = [33 x i8] c"Option %c requires an argument.\0A\00"
@.str.5 = [23 x i8] c"Unknown argument: %c.\0A\00"
@.str.6 = [26 x i8] c"server_ip: %s port: %s\0A\00"
@str = [6 x i8] c"Done.\00"
define i32 @main(i32 %0, i8** %1) {
br label %3
3: ; preds = %22, %2
%4 = phi i8* [ %23, %22 ], [ getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), %2 ]
%5 = phi i8* [ %9, %22 ], [ getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), %2 ]
%6 = phi i8* [ %13, %22 ], [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), %2 ]
%7 = phi i32 [ %16, %22 ], [ 1, %2 ]
br label %8
8: ; preds = %3, %24
%9 = phi i8* [ %5, %3 ], [ %25, %24 ]
%10 = phi i8* [ %6, %3 ], [ %13, %24 ]
%11 = phi i32 [ %7, %3 ], [ %16, %24 ]
br label %12
12: ; preds = %8, %20
%13 = phi i8* [ %10, %8 ], [ %21, %20 ]
%14 = phi i32 [ %11, %8 ], [ %16, %20 ]
br label %15
15: ; preds = %12, %26
%16 = phi i32 [ %14, %12 ], [ %28, %26 ]
br label %17
17: ; preds = %19, %15
%18 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
switch i32 %18, label %19 [
i32 -1, label %37
i32 112, label %20
i32 104, label %22
i32 109, label %24
i32 105, label %26
i32 63, label %29
]
19: ; preds = %17, %31, %34
br label %17
20: ; preds = %17
%21 = load i8*, i8** @optarg
br label %12
22: ; preds = %17
%23 = load i8*, i8** @optarg
br label %3
24: ; preds = %17
%25 = load i8*, i8** @optarg
br label %8
26: ; preds = %17
%27 = load i8*, i8** @optarg
%28 = tail call i32 @atoi(i8* %27)
br label %15
29: ; preds = %17
%30 = load i8, i8* @optopt
switch i8 %30, label %34 [
i8 112, label %31
i8 104, label %31
]
31: ; preds = %29, %29
%32 = load i32, i32* @stderr
%33 = tail call i32 @fprintf(i32 %32, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0), i8 signext %30)
br label %19
34: ; preds = %29
%35 = load i32, i32* @stderr
%36 = tail call i32 @fprintf(i32 %35, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0), i8 signext %30)
br label %19
37: ; preds = %17
%38 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.6, i64 0, i64 0), i8* %4, i8* %13)
%39 = tail call i32 @socket_connect_helper(i8* %4, i8* %13)
%40 = icmp sgt i32 %16, 0
br i1 %40, label %41, label %48
41: ; preds = %37, %41
%42 = phi i32 [ %46, %41 ], [ %16, %37 ]
%43 = tail call i32 @client_main(i32 %39, i8* %9)
%44 = tail call i32 @putchar(i32 46)
%45 = tail call i32 @sleep(i32 1)
%46 = add nsw i32 %42, -1
%47 = icmp ugt i32 %42, 1
br i1 %47, label %41, label %48
48: ; preds = %41, %37
%49 = tail call i32 @close(i32 %39)
%50 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @str, i64 0, i64 0))
ret i32 0
}