#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 char_to_num(char *);
int /*<<< orphan*/ printf(char *);
int get_port(int argc, char *argv[]) {
  int port = 33333;
  switch (argc) {
  case 3:
    port = char_to_num(argv[2]);
    if (-1 == port) {
      printf("port invalid\n");
      return -1;
    } else if (port > 65535) {
      printf("port too large\n");
      return -1;
    }
    break;
  case 1:
    break;
  default:
    printf("Usage: uniqd -l port\n");
    return -1;
  }
  return port;
}


x86 assembly (clang, -O0):
<get_port>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x8235,-0x14(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x18(%rbp)
sub    $0x1,%eax
je     11c0 <get_port+0xa0>
jmp    114a <get_port+0x2a>
mov    -0x18(%rbp),%eax
sub    $0x3,%eax
jne    11c5 <get_port+0xa5>
jmp    115b <get_port+0x3b>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1030 <char_to_num@plt>
mov    %eax,-0x14(%rbp)
mov    $0xffffffff,%eax
cmp    -0x14(%rbp),%eax
jne    1191 <get_port+0x71>
lea    0xe80(%rip),%rdi
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11e3 <get_port+0xc3>
cmpl   $0xffff,-0x14(%rbp)
jle    11b6 <get_port+0x96>
lea    0xe69(%rip),%rdi
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11e3 <get_port+0xc3>
jmp    11bb <get_port+0x9b>
jmp    11dd <get_port+0xbd>
jmp    11dd <get_port+0xbd>
lea    0xe52(%rip),%rdi
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11e3 <get_port+0xc3>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_port>:
push   %rax
cmp    $0x1,%edi
je     1149 <get_port+0x29>
cmp    $0x3,%edi
jne    1150 <get_port+0x30>
mov    0x10(%rsi),%rdi
call   1030 <char_to_num@plt>
cmp    $0xffffffff,%eax
je     1159 <get_port+0x39>
cmp    $0x10000,%eax
jl     116a <get_port+0x4a>
lea    0xeb9(%rip),%rdi
jmp    1160 <get_port+0x40>
mov    $0x8235,%eax
pop    %rcx
ret
lea    0xec5(%rip),%rdi
jmp    1160 <get_port+0x40>
lea    0xeaf(%rip),%rdi
call   1040 <puts@plt>
mov    $0xffffffff,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [14 x i8] c"port invalid\0A\00"
@.str.1 = [16 x i8] c"port too large\0A\00"
@.str.2 = [22 x i8] c"Usage: uniqd -l port\0A\00"
define i32 @get_port(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 33333, i32* %6
%7 = load i32, i32* %4
switch i32 %7, label %25 [
i32 3, label %8
i32 1, label %24
]
8: ; preds = %2
%9 = load i8**, i8*** %5
%10 = getelementptr inbounds i8*, i8** %9, i64 2
%11 = load i8*, i8** %10
%12 = call i32 @char_to_num(i8* %11)
store i32 %12, i32* %6
%13 = load i32, i32* %6
%14 = icmp eq i32 -1, %13
br i1 %14, label %15, label %17
15: ; preds = %8
%16 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %29
17: ; preds = %8
%18 = load i32, i32* %6
%19 = icmp sgt i32 %18, 65535
br i1 %19, label %20, label %22
20: ; preds = %17
%21 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %3
br label %29
22: ; preds = %17
br label %23
23: ; preds = %22
br label %27
24: ; preds = %2
br label %27
25: ; preds = %2
%26 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %3
br label %29
27: ; preds = %24, %23
%28 = load i32, i32* %6
store i32 %28, i32* %3
br label %29
29: ; preds = %27, %25, %20, %15
%30 = load i32, i32* %3
ret i32 %30
}

LLVM IR (-O2):
@str = [15 x i8] c"port too large\00"
@str.3 = [13 x i8] c"port invalid\00"
@str.4 = [21 x i8] c"Usage: uniqd -l port\00"
define i32 @get_port(i32 %0, i8** nocapture %1) {
switch i32 %0, label %10 [
i32 3, label %3
i32 1, label %13
]
3: ; preds = %2
%4 = getelementptr inbounds i8*, i8** %1, i64 2
%5 = load i8*, i8** %4
%6 = tail call i32 @char_to_num(i8* %5)
%7 = icmp eq i32 %6, -1
br i1 %7, label %10, label %8
8: ; preds = %3
%9 = icmp sgt i32 %6, 65535
br i1 %9, label %10, label %13
10: ; preds = %2, %8, %3
%11 = phi i8* [ getelementptr inbounds ([13 x i8], [13 x i8]* @str.3, i64 0, i64 0), %3 ], [ getelementptr inbounds ([15 x i8], [15 x i8]* @str, i64 0, i64 0), %8 ], [ getelementptr inbounds ([21 x i8], [21 x i8]* @str.4, i64 0, i64 0), %2 ]
%12 = tail call i32 @puts(i8* dereferenceable(1) %11)
br label %13
13: ; preds = %10, %2, %8
%14 = phi i32 [ 33333, %2 ], [ %6, %8 ], [ -1, %10 ]
ret i32 %14
}