#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 */
unsigned short atoi(char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int getopt(int, char **, char *);
char *optarg;
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
int main(int argc, char **argv) {
  int option_char = 0;
  char *hostname = "localhost";
  unsigned short portno = 8888;
  char *filename = "foo.txt";
  while ((option_char = getopt(argc, argv, "s:p:o:h")) != -1) {
    switch (option_char) {
    case 's':
      hostname = optarg;
      break;
    case 'p':
      portno = atoi(optarg);
      break;
    case 'o':
      filename = optarg;
      break;
    case 'h':
      fprintf(stdout, "%s",
              "usage:\n"
              "  transferclient [options]\n"
              "options:\n"
              "  -s                  Server (Default: localhost)\n"
              "  -p                  Port (Default: 8888)\n"
              "  -o                  Output file (Default foo.txt)\n"
              "  -h                  Show this help message\n");
      exit(0);
      break;
    default:
      fprintf(stderr, "%s",
              "usage:\n"
              "  transferclient [options]\n"
              "options:\n"
              "  -s                  Server (Default: localhost)\n"
              "  -p                  Port (Default: 8888)\n"
              "  -o                  Output file (Default foo.txt)\n"
              "  -h                  Show this help message\n");
      exit(1);
    }
  }
}


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   $0x0,-0x14(%rbp)
lea    0xecc(%rip),%rax
mov    %rax,-0x20(%rbp)
movw   $0x22b8,-0x22(%rbp)
lea    0xec5(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xebb(%rip),%rdx
call   1040 <getopt@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
je     124d <main+0x10d>
mov    -0x14(%rbp),%eax
add    $0xffffff98,%eax
mov    %eax,%ecx
mov    %rcx,-0x38(%rbp)
sub    $0xb,%eax
ja     1222 <main+0xe2>
mov    -0x38(%rbp),%rax
lea    0xe48(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    0x2e30(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
jmp    1248 <main+0x108>
mov    0x2e1d(%rip),%rax
mov    (%rax),%rdi
call   1050 <atoi@plt>
mov    %ax,-0x22(%rbp)
jmp    1248 <main+0x108>
mov    0x2e05(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x30(%rbp)
jmp    1248 <main+0x108>
mov    0x2dca(%rip),%rax
mov    (%rax),%edi
lea    0xe3b(%rip),%rsi
lea    0xe37(%rip),%rdx
call   1030 <fprintf@plt>
xor    %edi,%edi
call   1060 <exit@plt>
mov    0x2daf(%rip),%rax
mov    (%rax),%edi
lea    0xe18(%rip),%rsi
lea    0xe14(%rip),%rdx
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
jmp    1179 <main+0x39>
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%rbx
mov    %edi,%ebp
lea    0xec0(%rip),%r14
jmp    1155 <main+0x25>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
cmp    $0x73,%eax
jne    11a3 <main+0x73>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r14,%rdx
call   1040 <getopt@plt>
cmp    $0x72,%eax
jg     1150 <main+0x20>
lea    -0x6f(%rax),%ecx
cmp    $0x2,%ecx
jb     1155 <main+0x25>
cmp    $0xffffffff,%eax
jne    117b <main+0x4b>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
cmp    $0x68,%eax
jne    11a3 <main+0x73>
mov    0x2e51(%rip),%rax
mov    (%rax),%edi
lea    0xe78(%rip),%rsi
lea    0xe74(%rip),%rdx
call   1030 <fprintf@plt>
xor    %edi,%edi
call   1050 <exit@plt>
mov    0x2e36(%rip),%rax
mov    (%rax),%edi
lea    0xe55(%rip),%rsi
lea    0xe51(%rip),%rdx
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@.str = [10 x i8] c"localhost\00"
@.str.1 = [8 x i8] c"foo.txt\00"
@.str.2 = [8 x i8] c"s:p:o:h\00"
@optarg = global i8* null
@stdout = global i32 0
@.str.3 = [3 x i8] c"%s\00"
@.str.4 = [234 x i8] c"usage:\0A transferclient [options]\0Aoptions:\0A -s Server (Default: localhost)\0A -p Port (Default: 8888)\0A -o Output file (Default foo.txt)\0A -h Show this help message\0A\00"
@stderr = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i16
%9 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8** %7
store i16 8888, i16* %8
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8** %9
br label %10
10: ; preds = %32, %2
%11 = load i32, i32* %4
%12 = load i8**, i8*** %5
%13 = call i32 @getopt(i32 %11, i8** %12, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
store i32 %13, i32* %6
%14 = icmp ne i32 %13, -1
br i1 %14, label %15, label %33
15: ; preds = %10
%16 = load i32, i32* %6
switch i32 %16, label %28 [
i32 115, label %17
i32 112, label %19
i32 111, label %22
i32 104, label %24
]
17: ; preds = %15
%18 = load i8*, i8** @optarg
store i8* %18, i8** %7
br label %32
19: ; preds = %15
%20 = load i8*, i8** @optarg
%21 = call zeroext i16 @atoi(i8* %20)
store i16 %21, i16* %8
br label %32
22: ; preds = %15
%23 = load i8*, i8** @optarg
store i8* %23, i8** %9
br label %32
24: ; preds = %15
%25 = load i32, i32* @stdout
%26 = call i32 @fprintf(i32 %25, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([234 x i8], [234 x i8]* @.str.4, i64 0, i64 0))
%27 = call i32 @exit(i32 0)
unreachable
28: ; preds = %15
%29 = load i32, i32* @stderr
%30 = call i32 @fprintf(i32 %29, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([234 x i8], [234 x i8]* @.str.4, i64 0, i64 0))
%31 = call i32 @exit(i32 1)
unreachable
32: ; preds = %22, %19, %17
br label %10
33: ; preds = %10
%34 = load i32, i32* %3
ret i32 %34
}

LLVM IR (-O2):
@.str.2 = [8 x i8] c"s:p:o:h\00"
@optarg = global i8* null
@stdout = global i32 0
@.str.3 = [3 x i8] c"%s\00"
@.str.4 = [234 x i8] c"usage:\0A transferclient [options]\0Aoptions:\0A -s Server (Default: localhost)\0A -p Port (Default: 8888)\0A -o Output file (Default foo.txt)\0A -h Show this help message\0A\00"
@stderr = global i32 0
define i32 @main(i32 %0, i8** %1) {
br label %3
3: ; preds = %5, %2
%4 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
switch i32 %4, label %10 [
i32 -1, label %14
i32 115, label %5
i32 112, label %5
i32 111, label %5
i32 104, label %6
]
5: ; preds = %3, %3, %3
br label %3
6: ; preds = %3
%7 = load i32, i32* @stdout
%8 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([234 x i8], [234 x i8]* @.str.4, i64 0, i64 0))
%9 = tail call i32 @exit(i32 0)
unreachable
10: ; preds = %3
%11 = load i32, i32* @stderr
%12 = tail call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([234 x i8], [234 x i8]* @.str.4, i64 0, i64 0))
%13 = tail call i32 @exit(i32 1)
unreachable
14: ; preds = %3
ret i32 0
}