#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 connect_addr(char *, int);
int /*<<< orphan*/ docomm(int);
int /*<<< orphan*/ errx(char *, char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int getopt(int, char **, char *);
char *optarg;
scalar_t__ optind;
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ usage();
int main(int argc, char **argv) {
  int ch;
  int sock;
  int connport = 0;
  char *connaddr = NULL;
  while ((ch = getopt(argc, argv, "c:C:")) != -1) {
    switch (ch) {
    case 'c':
      connaddr = optarg;
      break;
    case 'C':
      if ((connport = atoi(optarg)) == 0)
        errx("Invalid argument '%s'", optarg);
      break;
    default:
      fprintf(stderr, "foo\n");
      return 0;
      break;
    }
  }
  argc -= optind;
  argv += optind;
  if (connport == 0 || connaddr == NULL)
    usage();
  if ((sock = connect_addr(connaddr, connport)) == -1) {
    perror("connect_addr");
    exit(1);
  }
  docomm(sock);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x1c(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe3d(%rip),%rdx
call   1080 <getopt@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
je     1268 <main+0xd8>
mov    -0x14(%rbp),%eax
mov    %eax,-0x2c(%rbp)
sub    $0x43,%eax
je     120c <main+0x7c>
jmp    11e8 <main+0x58>
mov    -0x2c(%rbp),%eax
sub    $0x63,%eax
jne    1242 <main+0xb2>
jmp    11f9 <main+0x69>
mov    0x2df8(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
jmp    1263 <main+0xd3>
mov    0x2de5(%rip),%rax
mov    (%rax),%rdi
call   1090 <atoi@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jne    123d <main+0xad>
mov    0x2dca(%rip),%rax
mov    (%rax),%rsi
lea    0xdcd(%rip),%rdi
call   1030 <errx@plt>
jmp    1263 <main+0xd3>
mov    0x2d87(%rip),%rax
mov    (%rax),%edi
lea    0xdc9(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    12eb <main+0x15b>
jmp    11b5 <main+0x25>
mov    0x2d71(%rip),%rax
mov    (%rax),%rcx
movslq -0x8(%rbp),%rax
sub    %rcx,%rax
mov    %eax,-0x8(%rbp)
mov    0x2d5d(%rip),%rax
mov    (%rax),%rax
shl    $0x3,%rax
add    -0x10(%rbp),%rax
mov    %rax,-0x10(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     12a7 <main+0x117>
cmpq   $0x0,-0x28(%rbp)
jne    12ae <main+0x11e>
mov    $0x0,%al
call   1060 <usage@plt>
mov    -0x28(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   10a0 <connect_addr@plt>
mov    %eax,-0x18(%rbp)
cmp    $0xffffffff,%eax
jne    12dc <main+0x14c>
lea    0xd53(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x18(%rbp),%edi
call   1050 <docomm@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%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
xor    %r15d,%r15d
lea    0xe56(%rip),%r12
mov    0x2e47(%rip),%r13
xor    %r14d,%r14d
jmp    11c4 <main+0x34>
cs nopw 0x0(%rax,%rax,1)
mov    0x0(%r13),%r14
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r12,%rdx
call   1080 <getopt@plt>
cmp    $0x63,%eax
je     11c0 <main+0x30>
cmp    $0xffffffff,%eax
je     1209 <main+0x79>
cmp    $0x43,%eax
jne    1233 <main+0xa3>
mov    0x0(%r13),%rdi
mov    %rdi,(%rsp)
call   1090 <atoi@plt>
mov    %eax,%r15d
test   %eax,%eax
jne    11c4 <main+0x34>
lea    0xe0a(%rip),%rdi
mov    (%rsp),%rsi
call   1030 <errx@plt>
xor    %r15d,%r15d
jmp    11c4 <main+0x34>
test   %r15d,%r15d
je     1213 <main+0x83>
test   %r14,%r14
jne    121a <main+0x8a>
xor    %eax,%eax
call   1060 <usage@plt>
mov    %r14,%rdi
mov    %r15d,%esi
call   10a0 <connect_addr@plt>
cmp    $0xffffffff,%eax
je     1259 <main+0xc9>
mov    %eax,%edi
call   1050 <docomm@plt>
jmp    1248 <main+0xb8>
mov    0x2d9e(%rip),%rax
mov    (%rax),%edi
lea    0xdd8(%rip),%rsi
call   1040 <fprintf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xdc0(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@.str = [5 x i8] c"c:C:\00"
@optarg = global i8* null
@.str.1 = [22 x i8] c"Invalid argument '%s'\00"
@stderr = global i32 0
@.str.2 = [5 x i8] c"foo\0A\00"
@optind = global i64 0
@.str.3 = [13 x i8] c"connect_addr\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 i32
%9 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %8
store i8* null, i8** %9
br label %10
10: ; preds = %30, %2
%11 = load i32, i32* %4
%12 = load i8**, i8*** %5
%13 = call i32 @getopt(i32 %11, i8** %12, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
store i32 %13, i32* %6
%14 = icmp ne i32 %13, -1
br i1 %14, label %15, label %31
15: ; preds = %10
%16 = load i32, i32* %6
switch i32 %16, label %27 [
i32 99, label %17
i32 67, label %19
]
17: ; preds = %15
%18 = load i8*, i8** @optarg
store i8* %18, i8** %9
br label %30
19: ; preds = %15
%20 = load i8*, i8** @optarg
%21 = call i32 @atoi(i8* %20)
store i32 %21, i32* %8
%22 = icmp eq i32 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %19
%24 = load i8*, i8** @optarg
%25 = call i32 @errx(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8* %24)
br label %26
26: ; preds = %23, %19
br label %30
27: ; preds = %15
%28 = load i32, i32* @stderr
%29 = call i32 @fprintf(i32 %28, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %3
br label %58
30: ; preds = %26, %17
br label %10
31: ; preds = %10
%32 = load i64, i64* @optind
%33 = load i32, i32* %4
%34 = sext i32 %33 to i64
%35 = sub nsw i64 %34, %32
%36 = trunc i64 %35 to i32
store i32 %36, i32* %4
%37 = load i64, i64* @optind
%38 = load i8**, i8*** %5
%39 = getelementptr inbounds i8*, i8** %38, i64 %37
store i8** %39, i8*** %5
%40 = load i32, i32* %8
%41 = icmp eq i32 %40, 0
br i1 %41, label %45, label %42
42: ; preds = %31
%43 = load i8*, i8** %9
%44 = icmp eq i8* %43, null
br i1 %44, label %45, label %47
45: ; preds = %42, %31
%46 = call i32 (...) @usage()
br label %47
47: ; preds = %45, %42
%48 = load i8*, i8** %9
%49 = load i32, i32* %8
%50 = call i32 @connect_addr(i8* %48, i32 %49)
store i32 %50, i32* %7
%51 = icmp eq i32 %50, -1
br i1 %51, label %52, label %55
52: ; preds = %47
%53 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
%54 = call i32 @exit(i32 1)
unreachable
55: ; preds = %47
%56 = load i32, i32* %7
%57 = call i32 @docomm(i32 %56)
store i32 0, i32* %3
br label %58
58: ; preds = %55, %27
%59 = load i32, i32* %3
ret i32 %59
}

LLVM IR (-O2):
@.str = [5 x i8] c"c:C:\00"
@optarg = global i8* null
@.str.1 = [22 x i8] c"Invalid argument '%s'\00"
@stderr = global i32 0
@.str.2 = [5 x i8] c"foo\0A\00"
@optind = global i64 0
@.str.3 = [13 x i8] c"connect_addr\00"
define i32 @main(i32 %0, i8** %1) {
br label %3
3: ; preds = %17, %2
%4 = phi i32 [ 0, %2 ], [ %18, %17 ]
%5 = phi i8* [ null, %2 ], [ %7, %17 ]
br label %6
6: ; preds = %3, %9
%7 = phi i8* [ %10, %9 ], [ %5, %3 ]
%8 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
switch i32 %8, label %19 [
i32 -1, label %22
i32 99, label %9
i32 67, label %11
]
9: ; preds = %6
%10 = load i8*, i8** @optarg
br label %6
11: ; preds = %6
%12 = load i8*, i8** @optarg
%13 = tail call i32 @atoi(i8* %12)
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %11
%16 = tail call i32 @errx(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8* %12)
br label %17
17: ; preds = %15, %11
%18 = phi i32 [ %13, %11 ], [ 0, %15 ]
br label %3
19: ; preds = %6
%20 = load i32, i32* @stderr
%21 = tail call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
br label %36
22: ; preds = %6
%23 = icmp eq i32 %4, 0
%24 = icmp eq i8* %7, null
%25 = select i1 %23, i1 true, i1 %24
br i1 %25, label %26, label %28
26: ; preds = %22
%27 = tail call i32 (...) @usage()
br label %28
28: ; preds = %22, %26
%29 = tail call i32 @connect_addr(i8* %7, i32 %4)
%30 = icmp eq i32 %29, -1
br i1 %30, label %31, label %34
31: ; preds = %28
%32 = tail call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
%33 = tail call i32 @exit(i32 1)
unreachable
34: ; preds = %28
%35 = tail call i32 @docomm(i32 %29)
br label %36
36: ; preds = %34, %19
ret i32 0
}