#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 /*<<< orphan*/ die(char *);
short strtol(char *, char **, int /*<<< orphan*/);
short get_port(int argc, char *argv[]) {
  short port;
  char *end;
  if (argc != 2) {
    die("Invalid arguments");
  }
  port = strtol(argv[1], &end, 0);
  if (*end) {
    die("Invalid port number");
  }
  return port;
}


x86 assembly (clang, -O0):
<get_port>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x4(%rbp)
je     1145 <get_port+0x25>
lea    0xec0(%rip),%rdi
call   1040 <die@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x20(%rbp),%rsi
xor    %edx,%edx
call   1030 <strtol@plt>
mov    %ax,-0x12(%rbp)
mov    -0x20(%rbp),%rax
cmpb   $0x0,(%rax)
je     1175 <get_port+0x55>
lea    0xea2(%rip),%rdi
call   1040 <die@plt>
movswl -0x12(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_port>:
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
cmp    $0x2,%edi
je     1139 <get_port+0x19>
lea    0xecc(%rip),%rdi
call   1040 <die@plt>
mov    0x8(%rbx),%rdi
lea    0x8(%rsp),%rsi
xor    %edx,%edx
call   1030 <strtol@plt>
mov    %eax,%ebx
mov    0x8(%rsp),%rax
cmpb   $0x0,(%rax)
je     1161 <get_port+0x41>
lea    0xeb6(%rip),%rdi
call   1040 <die@plt>
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [18 x i8] c"Invalid arguments\00"
@.str.1 = [20 x i8] c"Invalid port number\00"
define signext i16 @get_port(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i16
%6 = alloca i8*
store i32 %0, i32* %3
store i8** %1, i8*** %4
%7 = load i32, i32* %3
%8 = icmp ne i32 %7, 2
br i1 %8, label %9, label %11
9: ; preds = %2
%10 = call i32 @die(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
br label %11
11: ; preds = %9, %2
%12 = load i8**, i8*** %4
%13 = getelementptr inbounds i8*, i8** %12, i64 1
%14 = load i8*, i8** %13
%15 = call signext i16 @strtol(i8* %14, i8** %6, i32 0)
store i16 %15, i16* %5
%16 = load i8*, i8** %6
%17 = load i8, i8* %16
%18 = icmp ne i8 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %11
%20 = call i32 @die(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
br label %21
21: ; preds = %19, %11
%22 = load i16, i16* %5
ret i16 %22
}

LLVM IR (-O2):
@.str = [18 x i8] c"Invalid arguments\00"
@.str.1 = [20 x i8] c"Invalid port number\00"
define signext i16 @get_port(i32 %0, i8** nocapture %1) {
%3 = alloca i8*
%4 = bitcast i8** %3 to i8*
%5 = icmp eq i32 %0, 2
br i1 %5, label %8, label %6
6: ; preds = %2
%7 = tail call i32 @die(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
br label %8
8: ; preds = %6, %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = call signext i16 @strtol(i8* %10, i8** %3, i32 0)
%12 = load i8*, i8** %3
%13 = load i8, i8* %12
%14 = icmp eq i8 %13, 0
br i1 %14, label %17, label %15
15: ; preds = %8
%16 = tail call i32 @die(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
br label %17
17: ; preds = %15, %8
ret i16 %11
}