#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 int /*<<< orphan*/ commandline;

/* Variables and functions */
int create_connect(int, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
char getopt(int, char **, char *);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
char *optarg;
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ task_pid_recv(int);
int /*<<< orphan*/ task_send(int, char *);
int /*<<< orphan*/ usage(char *);
int main(int argc, char *argv[]) {
  char ch = 0;
  char *ipaddr = NULL;
  char commandline[4096];
  int sockfd = 0;
  if (argc < 3) {
    usage(argv[0]);
  }
  while ((ch = getopt(argc, argv, "hc:a:")) != -1) {
    switch (ch) {
    case 'c':
      memset(commandline, 0, sizeof(commandline));
      strncpy(commandline, optarg, strlen(optarg));
      fprintf(stdout, "the command line = [%s]\n", commandline);
      break;
    case 'a':
      ipaddr = optarg;
      fprintf(stdout, "ipaddr = [%s]\n", ipaddr);
      break;
    case '?':
    case 'h':
    default:
      usage(argv[0]);
      break;
    }
  }
  sockfd = create_connect(sockfd, ipaddr);
  task_send(sockfd, commandline);
  task_pid_recv(sockfd);
  sleep(1);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1040,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movb   $0x0,-0x11(%rbp)
movq   $0x0,-0x20(%rbp)
movl   $0x0,-0x1024(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    11e5 <main+0x45>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   10a0 <usage@plt>
jmp    11ea <main+0x4a>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe08(%rip),%rdx
call   10b0 <getopt@plt>
mov    %al,-0x11(%rbp)
movsbl %al,%eax
cmp    $0xffffffff,%eax
je     1319 <main+0x179>
movsbl -0x11(%rbp),%eax
mov    %eax,-0x1028(%rbp)
sub    $0x3f,%eax
je     1303 <main+0x163>
jmp    1224 <main+0x84>
mov    -0x1028(%rbp),%eax
sub    $0x61,%eax
je     12d7 <main+0x137>
jmp    1238 <main+0x98>
mov    -0x1028(%rbp),%eax
sub    $0x63,%eax
je     1260 <main+0xc0>
jmp    124c <main+0xac>
mov    -0x1028(%rbp),%eax
sub    $0x68,%eax
je     1303 <main+0x163>
jmp    1308 <main+0x168>
lea    -0x1020(%rbp),%rdi
xor    %esi,%esi
mov    $0x1000,%edx
call   1060 <memset@plt>
lea    -0x1020(%rbp),%rax
mov    %rax,-0x1038(%rbp)
mov    0x2d70(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x1030(%rbp)
mov    0x2d5f(%rip),%rax
mov    (%rax),%rdi
call   1050 <strlen@plt>
mov    -0x1038(%rbp),%rdi
mov    -0x1030(%rbp),%rsi
mov    %eax,%edx
call   1030 <strncpy@plt>
mov    0x2d1b(%rip),%rax
mov    (%rax),%edi
lea    -0x1020(%rbp),%rdx
lea    0xd39(%rip),%rsi
call   1080 <fprintf@plt>
jmp    1314 <main+0x174>
mov    0x2d1a(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
mov    0x2cec(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rdx
lea    0xd26(%rip),%rsi
call   1080 <fprintf@plt>
jmp    1314 <main+0x174>
jmp    1308 <main+0x168>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   10a0 <usage@plt>
jmp    11ea <main+0x4a>
mov    -0x1024(%rbp),%edi
mov    -0x20(%rbp),%rsi
call   1040 <create_connect@plt>
mov    %eax,-0x1024(%rbp)
mov    -0x1024(%rbp),%edi
lea    -0x1020(%rbp),%rsi
call   1090 <task_send@plt>
mov    -0x1024(%rbp),%edi
call   1070 <task_pid_recv@plt>
mov    $0x1,%edi
call   10c0 <sleep@plt>
xor    %eax,%eax
add    $0x1040,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1018,%rsp
mov    %rsi,%r12
mov    %edi,%r13d
cmp    $0x2,%edi
jg     11c5 <main+0x25>
mov    (%r12),%rdi
call   10a0 <usage@plt>
lea    0xe34(%rip),%rdx
mov    %r13d,%edi
mov    %r12,%rsi
call   10b0 <getopt@plt>
cmp    $0xff,%al
je     12ab <main+0x10b>
xor    %ecx,%ecx
mov    %rcx,(%rsp)
mov    0x2e0c(%rip),%rbp
mov    0x2de5(%rip),%rbx
lea    0xe06(%rip),%r15
mov    %r12,0x8(%rsp)
jmp    122f <main+0x8f>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    (%r12),%rdi
call   10a0 <usage@plt>
mov    %r13d,%edi
mov    %r12,%rsi
mov    %r15,%rdx
call   10b0 <getopt@plt>
cmp    $0xff,%al
je     12b1 <main+0x111>
movsbl %al,%eax
cmp    $0x61,%eax
je     1290 <main+0xf0>
cmp    $0x63,%eax
jne    1210 <main+0x70>
lea    0x10(%rsp),%r12
mov    %r12,%rdi
xor    %esi,%esi
mov    $0x1000,%edx
call   1060 <memset@plt>
mov    %r15,%r14
mov    0x0(%rbp),%r15
mov    %r15,%rdi
call   1050 <strlen@plt>
mov    %r12,%rdi
mov    %r15,%rsi
mov    %r14,%r15
mov    %eax,%edx
call   1030 <strncpy@plt>
mov    (%rbx),%edi
lea    0xd8e(%rip),%rsi
mov    %r12,%rdx
mov    0x8(%rsp),%r12
call   1080 <fprintf@plt>
jmp    1219 <main+0x79>
nopw   0x0(%rax,%rax,1)
mov    0x0(%rbp),%rdx
mov    (%rbx),%edi
lea    0xd82(%rip),%rsi
mov    %rdx,(%rsp)
call   1080 <fprintf@plt>
jmp    1219 <main+0x79>
xor    %eax,%eax
mov    %rax,(%rsp)
xor    %edi,%edi
mov    (%rsp),%rsi
call   1040 <create_connect@plt>
mov    %eax,%ebx
lea    0x10(%rsp),%rsi
mov    %eax,%edi
call   1090 <task_send@plt>
mov    %ebx,%edi
call   1070 <task_pid_recv@plt>
mov    $0x1,%edi
call   10c0 <sleep@plt>
xor    %eax,%eax
add    $0x1018,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [6 x i8] c"hc:a:\00"
@optarg = global i8* null
@stdout = global i32 0
@.str.1 = [25 x i8] c"the command line = [%s]\0A\00"
@.str.2 = [15 x i8] c"ipaddr = [%s]\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8
%7 = alloca i8*
%8 = alloca [4096 x i8]
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8 0, i8* %6
store i8* null, i8** %7
store i32 0, i32* %9
%10 = load i32, i32* %4
%11 = icmp slt i32 %10, 3
br i1 %11, label %12, label %17
12: ; preds = %2
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 0
%15 = load i8*, i8** %14
%16 = call i32 @usage(i8* %15)
br label %17
17: ; preds = %12, %2
br label %18
18: ; preds = %49, %17
%19 = load i32, i32* %4
%20 = load i8**, i8*** %5
%21 = call signext i8 @getopt(i32 %19, i8** %20, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
store i8 %21, i8* %6
%22 = sext i8 %21 to i32
%23 = icmp ne i32 %22, -1
br i1 %23, label %24, label %50
24: ; preds = %18
%25 = load i8, i8* %6
%26 = sext i8 %25 to i32
switch i32 %26, label %44 [
i32 99, label %27
i32 97, label %38
i32 63, label %43
i32 104, label %43
]
27: ; preds = %24
%28 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 0
%29 = call i32 @memset(i8* %28, i32 0, i32 4096)
%30 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 0
%31 = load i8*, i8** @optarg
%32 = load i8*, i8** @optarg
%33 = call i32 @strlen(i8* %32)
%34 = call i32 @strncpy(i8* %30, i8* %31, i32 %33)
%35 = load i32, i32* @stdout
%36 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 0
%37 = call i32 @fprintf(i32 %35, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i8* %36)
br label %49
38: ; preds = %24
%39 = load i8*, i8** @optarg
store i8* %39, i8** %7
%40 = load i32, i32* @stdout
%41 = load i8*, i8** %7
%42 = call i32 @fprintf(i32 %40, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i8* %41)
br label %49
43: ; preds = %24, %24
br label %44
44: ; preds = %24, %43
%45 = load i8**, i8*** %5
%46 = getelementptr inbounds i8*, i8** %45, i64 0
%47 = load i8*, i8** %46
%48 = call i32 @usage(i8* %47)
br label %49
49: ; preds = %44, %38, %27
br label %18
50: ; preds = %18
%51 = load i32, i32* %9
%52 = load i8*, i8** %7
%53 = call i32 @create_connect(i32 %51, i8* %52)
store i32 %53, i32* %9
%54 = load i32, i32* %9
%55 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 0
%56 = call i32 @task_send(i32 %54, i8* %55)
%57 = load i32, i32* %9
%58 = call i32 @task_pid_recv(i32 %57)
%59 = call i32 @sleep(i32 1)
ret i32 0
}

LLVM IR (-O2):
@.str = [6 x i8] c"hc:a:\00"
@optarg = global i8* null
@stdout = global i32 0
@.str.1 = [25 x i8] c"the command line = [%s]\0A\00"
@.str.2 = [15 x i8] c"ipaddr = [%s]\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca [4096 x i8]
%4 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
%5 = icmp slt i32 %0, 3
br i1 %5, label %6, label %9
6: ; preds = %2
%7 = load i8*, i8** %1
%8 = tail call i32 @usage(i8* %7)
br label %9
9: ; preds = %6, %2
%10 = call signext i8 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%11 = icmp eq i8 %10, -1
br i1 %11, label %34, label %12
12: ; preds = %9, %30
%13 = phi i8 [ %32, %30 ], [ %10, %9 ]
%14 = phi i8* [ %31, %30 ], [ null, %9 ]
%15 = sext i8 %13 to i32
switch i32 %15, label %27 [
i32 99, label %16
i32 97, label %23
]
16: ; preds = %12
%17 = call i32 @memset(i8* %4, i32 0, i32 4096)
%18 = load i8*, i8** @optarg
%19 = call i32 @strlen(i8* %18)
%20 = call i32 @strncpy(i8* %4, i8* %18, i32 %19)
%21 = load i32, i32* @stdout
%22 = call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i8* %4)
br label %30
23: ; preds = %12
%24 = load i8*, i8** @optarg
%25 = load i32, i32* @stdout
%26 = call i32 @fprintf(i32 %25, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i8* %24)
br label %30
27: ; preds = %12
%28 = load i8*, i8** %1
%29 = call i32 @usage(i8* %28)
br label %30
30: ; preds = %27, %23, %16
%31 = phi i8* [ %14, %27 ], [ %24, %23 ], [ %14, %16 ]
%32 = call signext i8 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%33 = icmp eq i8 %32, -1
br i1 %33, label %34, label %12
34: ; preds = %30, %9
%35 = phi i8* [ null, %9 ], [ %31, %30 ]
%36 = call i32 @create_connect(i32 0, i8* %35)
%37 = call i32 @task_send(i32 %36, i8* %4)
%38 = call i32 @task_pid_recv(i32 %36)
%39 = call i32 @sleep(i32 1)
ret i32 0
}