#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*/ client_request(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 sh_client(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;
  while ((o = getopt(argc, argv, "p:h:m:")) != -1) {
    switch (o) {
    case 'p':
      server_port = optarg;
      break;
    case 'h':
      server_ip = optarg;
      break;
    case 'm':
      message = 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 = sh_client(server_ip, server_port);
  client_request(sockfd, message);
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    0xe83(%rip),%rax
mov    %rax,-0x20(%rbp)
lea    0xe7d(%rip),%rax
mov    %rax,-0x28(%rbp)
lea    0xe7c(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe76(%rip),%rdx
call   1080 <getopt@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
je     12a9 <main+0x149>
mov    -0x14(%rbp),%eax
mov    %eax,-0x38(%rbp)
sub    $0x3f,%eax
je     1236 <main+0xd6>
jmp    11ca <main+0x6a>
mov    -0x38(%rbp),%eax
sub    $0x68,%eax
je     1210 <main+0xb0>
jmp    11db <main+0x7b>
mov    -0x38(%rbp),%eax
sub    $0x6d,%eax
je     1223 <main+0xc3>
jmp    11ec <main+0x8c>
mov    -0x38(%rbp),%eax
sub    $0x70,%eax
jne    12a4 <main+0x144>
jmp    11fd <main+0x9d>
mov    0x2df4(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
jmp    12a4 <main+0x144>
mov    0x2de1(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
jmp    12a4 <main+0x144>
mov    0x2dce(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x30(%rbp)
jmp    12a4 <main+0x144>
mov    0x2da3(%rip),%rax
movsbl (%rax),%eax
cmp    $0x70,%eax
je     125c <main+0xfc>
mov    0x2d90(%rip),%rax
movsbl (%rax),%eax
cmp    $0x68,%eax
jne    1280 <main+0x120>
mov    0x2d6d(%rip),%rax
mov    (%rax),%edi
lea    0xdb6(%rip),%rsi
mov    0x2d6d(%rip),%rax
movsbl (%rax),%edx
call   1060 <fprintf@plt>
jmp    129f <main+0x13f>
mov    0x2d49(%rip),%rax
mov    (%rax),%edi
lea    0xdb3(%rip),%rsi
mov    0x2d49(%rip),%rax
movsbl (%rax),%edx
call   1060 <fprintf@plt>
jmp    12a4 <main+0x144>
jmp    1197 <main+0x37>
mov    -0x28(%rbp),%rsi
mov    -0x20(%rbp),%rdx
lea    0xda2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1050 <sh_client@plt>
mov    %eax,-0x34(%rbp)
mov    -0x34(%rbp),%edi
mov    -0x30(%rbp),%rsi
call   1070 <client_request@plt>
mov    -0x34(%rbp),%edi
call   1040 <close@plt>
lea    0xd8a(%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
lea    0xe76(%rip),%rax
mov    %rax,0x8(%rsp)
lea    0xe79(%rip),%rax
mov    %rax,0x10(%rsp)
lea    0xe63(%rip),%rax
mov    %rax,(%rsp)
lea    0xe6e(%rip),%r13
mov    0x2e2c(%rip),%r12
mov    0x2e15(%rip),%r15
lea    0xe60(%rip),%r14
jmp    11de <main+0x6e>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    (%r15),%edi
movsbl %al,%edx
mov    %r14,%rsi
call   1070 <fprintf@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r13,%rdx
call   1090 <getopt@plt>
cmp    $0x67,%eax
jg     1220 <main+0xb0>
cmp    $0x3f,%eax
jne    1240 <main+0xd0>
movzbl (%r12),%eax
cmp    $0x70,%al
je     11d0 <main+0x60>
cmp    $0x68,%al
je     11d0 <main+0x60>
mov    (%r15),%edi
movsbl %al,%edx
lea    0xe34(%rip),%rsi
call   1070 <fprintf@plt>
jmp    11de <main+0x6e>
cs nopw 0x0(%rax,%rax,1)
cmp    $0x68,%eax
je     1247 <main+0xd7>
cmp    $0x6d,%eax
je     1257 <main+0xe7>
cmp    $0x70,%eax
jne    11de <main+0x6e>
mov    0x2dc2(%rip),%rax
mov    (%rax),%rax
mov    %rax,0x8(%rsp)
jmp    11de <main+0x6e>
cmp    $0xffffffff,%eax
jne    11de <main+0x6e>
jmp    126b <main+0xfb>
mov    0x2daa(%rip),%rax
mov    (%rax),%rax
mov    %rax,(%rsp)
jmp    11de <main+0x6e>
mov    0x2d9a(%rip),%rax
mov    (%rax),%rax
mov    %rax,0x10(%rsp)
jmp    11de <main+0x6e>
lea    0xde8(%rip),%rdi
mov    (%rsp),%rbp
mov    %rbp,%rsi
mov    0x8(%rsp),%rbx
mov    %rbx,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1060 <sh_client@plt>
mov    %eax,%ebx
mov    %eax,%edi
mov    0x10(%rsp),%rsi
call   1080 <client_request@plt>
mov    %ebx,%edi
call   1050 <close@plt>
lea    0xdc5(%rip),%rdi
call   1030 <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 = [7 x i8] c"p:h:m:\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 = [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
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
br label %11
11: ; preds = %41, %2
%12 = load i32, i32* %4
%13 = load i8**, i8*** %5
%14 = call i32 @getopt(i32 %12, i8** %13, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
store i32 %14, i32* %6
%15 = icmp ne i32 %14, -1
br i1 %15, label %16, label %42
16: ; preds = %11
%17 = load i32, i32* %6
switch i32 %17, label %41 [
i32 112, label %18
i32 104, label %20
i32 109, label %22
i32 63, label %24
]
18: ; preds = %16
%19 = load i8*, i8** @optarg
store i8* %19, i8** %7
br label %41
20: ; preds = %16
%21 = load i8*, i8** @optarg
store i8* %21, i8** %8
br label %41
22: ; preds = %16
%23 = load i8*, i8** @optarg
store i8* %23, i8** %9
br label %41
24: ; preds = %16
%25 = load i8, i8* @optopt
%26 = sext i8 %25 to i32
%27 = icmp eq i32 %26, 112
br i1 %27, label %32, label %28
28: ; preds = %24
%29 = load i8, i8* @optopt
%30 = sext i8 %29 to i32
%31 = icmp eq i32 %30, 104
br i1 %31, label %32, label %36
32: ; preds = %28, %24
%33 = load i32, i32* @stderr
%34 = load i8, i8* @optopt
%35 = call i32 @fprintf(i32 %33, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0), i8 signext %34)
br label %40
36: ; preds = %28
%37 = load i32, i32* @stderr
%38 = load i8, i8* @optopt
%39 = call i32 @fprintf(i32 %37, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0), i8 signext %38)
br label %40
40: ; preds = %36, %32
br label %41
41: ; preds = %16, %40, %22, %20, %18
br label %11
42: ; preds = %11
%43 = load i8*, i8** %8
%44 = load i8*, i8** %7
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.6, i64 0, i64 0), i8* %43, i8* %44)
%46 = load i8*, i8** %8
%47 = load i8*, i8** %7
%48 = call i32 @sh_client(i8* %46, i8* %47)
store i32 %48, i32* %10
%49 = load i32, i32* %10
%50 = load i8*, i8** %9
%51 = call i32 @client_request(i32 %49, i8* %50)
br label %52
52: ; preds = %42
%53 = load i32, i32* %10
%54 = call i32 @close(i32 %53)
%55 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, 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 = [7 x i8] c"p:h:m:\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 = %17, %2
%4 = phi i8* [ %18, %17 ], [ getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), %2 ]
%5 = phi i8* [ %8, %17 ], [ getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), %2 ]
%6 = phi i8* [ %11, %17 ], [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), %2 ]
br label %7
7: ; preds = %3, %19
%8 = phi i8* [ %5, %3 ], [ %20, %19 ]
%9 = phi i8* [ %6, %3 ], [ %11, %19 ]
br label %10
10: ; preds = %7, %15
%11 = phi i8* [ %9, %7 ], [ %16, %15 ]
br label %12
12: ; preds = %14, %10
%13 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
switch i32 %13, label %14 [
i32 -1, label %29
i32 112, label %15
i32 104, label %17
i32 109, label %19
i32 63, label %21
]
14: ; preds = %12, %23, %26
br label %12
15: ; preds = %12
%16 = load i8*, i8** @optarg
br label %10
17: ; preds = %12
%18 = load i8*, i8** @optarg
br label %3
19: ; preds = %12
%20 = load i8*, i8** @optarg
br label %7
21: ; preds = %12
%22 = load i8, i8* @optopt
switch i8 %22, label %26 [
i8 112, label %23
i8 104, label %23
]
23: ; preds = %21, %21
%24 = load i32, i32* @stderr
%25 = tail call i32 @fprintf(i32 %24, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0), i8 signext %22)
br label %14
26: ; preds = %21
%27 = load i32, i32* @stderr
%28 = tail call i32 @fprintf(i32 %27, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0), i8 signext %22)
br label %14
29: ; preds = %12
%30 = 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* %11)
%31 = tail call i32 @sh_client(i8* %4, i8* %11)
%32 = tail call i32 @client_request(i32 %31, i8* %8)
%33 = tail call i32 @close(i32 %31)
%34 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @str, i64 0, i64 0))
ret i32 0
}