#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*/ conn(char *, int);
int /*<<< orphan*/ disconn();
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int getopt(int, char **, char *);
int /*<<< orphan*/ printf(char *, char *, int);
int /*<<< orphan*/ stderr;
main(int argc, char **argv) {
  extern char *optarg;
  extern int optind;
  int c, err = 0;
  char *prompt = 0;
  int port = 21234;
  char *host = "localhost";
  static char usage[] = "usage: %s [-d] [-h serverhost] [-p port]\n";
  while ((c = getopt(argc, argv, "dh:p:")) != -1)
    switch (c) {
    case 'h':
      host = optarg;
      break;
    case 'p':
      port = atoi(optarg);
      if (port < 1024 || port > 65535) {
        fprintf(stderr, "invalid port number: %s\n", optarg);
        err = 1;
      }
      break;
    case '?':
      err = 1;
      break;
    }
  if (err || (optind < argc)) {
    fprintf(stderr, usage, argv[0]);
    exit(1);
  }
  printf("connecting to %s, port %d\n", host, port);
  if (!conn(host, port))
    exit(1);
  disconn();
  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)
movl   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movl   $0x52f2,-0x24(%rbp)
lea    0xe5d(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe55(%rip),%rdx
call   1070 <getopt@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
je     1272 <main+0x102>
mov    -0x14(%rbp),%eax
mov    %eax,-0x34(%rbp)
sub    $0x3f,%eax
je     1266 <main+0xf6>
jmp    11da <main+0x6a>
mov    -0x34(%rbp),%eax
sub    $0x68,%eax
je     11fc <main+0x8c>
jmp    11eb <main+0x7b>
mov    -0x34(%rbp),%eax
sub    $0x70,%eax
je     120f <main+0x9f>
jmp    126d <main+0xfd>
mov    0x2ddd(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x30(%rbp)
jmp    126d <main+0xfd>
mov    0x2dca(%rip),%rax
mov    (%rax),%rdi
call   1080 <atoi@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x400,-0x24(%rbp)
jl     123b <main+0xcb>
cmpl   $0xffff,-0x24(%rbp)
jle    1261 <main+0xf1>
mov    0x2d96(%rip),%rax
mov    (%rax),%edi
mov    0x2d95(%rip),%rax
mov    (%rax),%rdx
lea    0xdbb(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0x1,-0x18(%rbp)
jmp    126d <main+0xfd>
movl   $0x1,-0x18(%rbp)
jmp    11a7 <main+0x37>
cmpl   $0x0,-0x18(%rbp)
jne    128e <main+0x11e>
mov    0x2d4d(%rip),%rax
mov    (%rax),%eax
cmp    -0x8(%rbp),%eax
jge    12b4 <main+0x144>
mov    0x2d43(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0x2dbb(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x30(%rbp),%rsi
mov    -0x24(%rbp),%edx
lea    0xd67(%rip),%rdi
call   1050 <printf@plt>
mov    -0x30(%rbp),%rdi
mov    -0x24(%rbp),%esi
call   1040 <conn@plt>
cmp    $0x0,%eax
jne    12e6 <main+0x176>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    $0x0,%al
call   1030 <disconn@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
push   %rax
mov    %rsi,%rbx
mov    %edi,%ebp
lea    0xe79(%rip),%rax
mov    %rax,(%rsp)
mov    $0x52f2,%r15d
xor    %r14d,%r14d
lea    0xe6f(%rip),%r12
jmp    11c0 <main+0x50>
mov    0x2e34(%rip),%rax
mov    (%rax),%edi
lea    0xe63(%rip),%rsi
mov    %r13,%rdx
call   1060 <fprintf@plt>
mov    $0x1,%r14b
nopl   0x0(%rax,%rax,1)
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r12,%rdx
call   1070 <getopt@plt>
cmp    $0x67,%eax
jg     11e0 <main+0x70>
cmp    $0xffffffff,%eax
je     121d <main+0xad>
cmp    $0x3f,%eax
jne    11c0 <main+0x50>
jmp    11b5 <main+0x45>
xchg   %ax,%ax
cmp    $0x70,%eax
je     11fa <main+0x8a>
cmp    $0x68,%eax
jne    11c0 <main+0x50>
mov    0x2def(%rip),%rax
mov    (%rax),%rax
mov    %rax,(%rsp)
jmp    11c0 <main+0x50>
mov    0x2ddf(%rip),%rax
mov    (%rax),%r13
mov    %r13,%rdi
call   1080 <atoi@plt>
mov    %eax,%r15d
add    $0xffff0000,%eax
cmp    $0xffff03ff,%eax
ja     11c0 <main+0x50>
jmp    119d <main+0x2d>
mov    0x2dac(%rip),%rax
cmp    %ebp,(%rax)
setl   %al
or     %al,%r14b
test   $0x1,%r14b
jne    126f <main+0xff>
lea    0xdf0(%rip),%rdi
mov    (%rsp),%rbx
mov    %rbx,%rsi
mov    %r15d,%edx
call   1050 <printf@plt>
mov    %rbx,%rdi
mov    %r15d,%esi
call   1040 <conn@plt>
test   %eax,%eax
je     1287 <main+0x117>
xor    %eax,%eax
call   1030 <disconn@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d62(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0x2dde(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [10 x i8] c"localhost\00"
@main.usage = internal global [42 x i8] c"usage: %s [-d] [-h serverhost] [-p port]\0A\00"
@.str.1 = [6 x i8] c"dh:p:\00"
@optarg = external global i8*
@stderr = global i32 0
@.str.2 = [25 x i8] c"invalid port number: %s\0A\00"
@optind = external global i32
@.str.3 = [27 x i8] c"connecting to %s, port %d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %7
store i8* null, i8** %8
store i32 21234, i32* %9
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8** %10
br label %11
11: ; preds = %34, %2
%12 = load i32, i32* %4
%13 = load i8**, i8*** %5
%14 = call i32 @getopt(i32 %12, i8** %13, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
store i32 %14, i32* %6
%15 = icmp ne i32 %14, -1
br i1 %15, label %16, label %35
16: ; preds = %11
%17 = load i32, i32* %6
switch i32 %17, label %34 [
i32 104, label %18
i32 112, label %20
i32 63, label %33
]
18: ; preds = %16
%19 = load i8*, i8** @optarg
store i8* %19, i8** %10
br label %34
20: ; preds = %16
%21 = load i8*, i8** @optarg
%22 = call i32 @atoi(i8* %21)
store i32 %22, i32* %9
%23 = load i32, i32* %9
%24 = icmp slt i32 %23, 1024
br i1 %24, label %28, label %25
25: ; preds = %20
%26 = load i32, i32* %9
%27 = icmp sgt i32 %26, 65535
br i1 %27, label %28, label %32
28: ; preds = %25, %20
%29 = load i32, i32* @stderr
%30 = load i8*, i8** @optarg
%31 = call i32 @fprintf(i32 %29, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i8* %30)
store i32 1, i32* %7
br label %32
32: ; preds = %28, %25
br label %34
33: ; preds = %16
store i32 1, i32* %7
br label %34
34: ; preds = %16, %33, %32, %18
br label %11
35: ; preds = %11
%36 = load i32, i32* %7
%37 = icmp ne i32 %36, 0
br i1 %37, label %42, label %38
38: ; preds = %35
%39 = load i32, i32* @optind
%40 = load i32, i32* %4
%41 = icmp slt i32 %39, %40
br i1 %41, label %42, label %49
42: ; preds = %38, %35
%43 = load i32, i32* @stderr
%44 = load i8**, i8*** %5
%45 = getelementptr inbounds i8*, i8** %44, i64 0
%46 = load i8*, i8** %45
%47 = call i32 @fprintf(i32 %43, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @main.usage, i64 0, i64 0), i8* %46)
%48 = call i32 @exit(i32 1)
unreachable
49: ; preds = %38
%50 = load i8*, i8** %10
%51 = load i32, i32* %9
%52 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0), i8* %50, i32 %51)
%53 = load i8*, i8** %10
%54 = load i32, i32* %9
%55 = call i32 @conn(i8* %53, i32 %54)
%56 = icmp ne i32 %55, 0
br i1 %56, label %59, label %57
57: ; preds = %49
%58 = call i32 @exit(i32 1)
unreachable
59: ; preds = %49
%60 = call i32 (...) @disconn()
ret i32 0
}

LLVM IR (-O2):
@.str = [10 x i8] c"localhost\00"
@main.usage = internal global [42 x i8] c"usage: %s [-d] [-h serverhost] [-p port]\0A\00"
@.str.1 = [6 x i8] c"dh:p:\00"
@optarg = external global i8*
@stderr = global i32 0
@.str.2 = [25 x i8] c"invalid port number: %s\0A\00"
@optind = external global i32
@.str.3 = [27 x i8] c"connecting to %s, port %d\0A\00"
define i32 @main(i32 %0, i8** %1) {
br label %3
3: ; preds = %24, %2
%4 = phi i1 [ true, %24 ], [ false, %2 ]
%5 = phi i32 [ %25, %24 ], [ 21234, %2 ]
%6 = phi i8* [ %11, %24 ], [ getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), %2 ]
br label %7
7: ; preds = %3, %16
%8 = phi i32 [ %5, %3 ], [ %18, %16 ]
%9 = phi i8* [ %6, %3 ], [ %11, %16 ]
br label %10
10: ; preds = %7, %14
%11 = phi i8* [ %9, %7 ], [ %15, %14 ]
br label %12
12: ; preds = %10, %12
%13 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
switch i32 %13, label %12 [
i32 -1, label %26
i32 104, label %14
i32 112, label %16
i32 63, label %24
]
14: ; preds = %12
%15 = load i8*, i8** @optarg
br label %10
16: ; preds = %12
%17 = load i8*, i8** @optarg
%18 = tail call i32 @atoi(i8* %17)
%19 = add i32 %18, -65536
%20 = icmp ult i32 %19, -64512
br i1 %20, label %21, label %7
21: ; preds = %16
%22 = load i32, i32* @stderr
%23 = tail call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i8* %17)
br label %24
24: ; preds = %12, %21
%25 = phi i32 [ %18, %21 ], [ %8, %12 ]
br label %3
26: ; preds = %12
%27 = load i32, i32* @optind
%28 = icmp slt i32 %27, %0
%29 = select i1 %4, i1 true, i1 %28
br i1 %29, label %30, label %35
30: ; preds = %26
%31 = load i32, i32* @stderr
%32 = load i8*, i8** %1
%33 = tail call i32 @fprintf(i32 %31, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @main.usage, i64 0, i64 0), i8* %32)
%34 = tail call i32 @exit(i32 1)
unreachable
35: ; preds = %26
%36 = tail call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0), i8* %11, i32 %8)
%37 = tail call i32 @conn(i8* %11, i32 %8)
%38 = icmp eq i32 %37, 0
br i1 %38, label %39, label %41
39: ; preds = %35
%40 = tail call i32 @exit(i32 1)
unreachable
41: ; preds = %35
%42 = tail call i32 (...) @disconn()
ret i32 0
}