#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 */
scalar_t__ EINVAL;
int /*<<< orphan*/ EXIT_FAILURE;
int control_loop(int);
scalar_t__ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stderr;
int strtol(char *, int /*<<< orphan*/ *, int);
int main(int argc, char *argv[]) {
  int port;
  if (argc != 2) {
    fprintf(stderr, "USAGE: %s port\n", argv[0]);
    exit(EXIT_FAILURE);
  }
  port = strtol(argv[1], NULL, 10);
  if (port == 0 && errno == EINVAL) {
    perror("Bad port number");
    exit(EXIT_FAILURE);
  }
  return control_loop(port);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     119a <main+0x4a>
mov    0x2e69(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe79(%rip),%rsi
call   1030 <fprintf@plt>
mov    0x2e3d(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1040 <strtol@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    11f1 <main+0xa1>
mov    0x2e14(%rip),%rax
mov    (%rax),%rax
mov    0x2dfa(%rip),%rcx
cmp    (%rcx),%rax
jne    11f1 <main+0xa1>
lea    0xe32(%rip),%rdi
call   1060 <perror@plt>
mov    0x2de6(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    -0x14(%rbp),%edi
call   1050 <control_loop@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
cmp    $0x2,%edi
jne    1188 <main+0x38>
mov    0x8(%rsi),%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1040 <strtol@plt>
test   %eax,%eax
jne    1180 <main+0x30>
mov    0x2e67(%rip),%rcx
mov    (%rcx),%rcx
mov    0x2e4d(%rip),%rdx
cmp    (%rdx),%rcx
je     11a2 <main+0x52>
mov    %eax,%edi
pop    %rax
jmp    1050 <control_loop@plt>
mov    0x2e51(%rip),%rax
mov    (%rax),%edi
mov    (%rsi),%rdx
lea    0xe65(%rip),%rsi
call   1030 <fprintf@plt>
jmp    11ae <main+0x5e>
lea    0xe67(%rip),%rdi
call   1060 <perror@plt>
mov    0x2e1b(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [16 x i8] c"USAGE: %s port\0A\00"
@EXIT_FAILURE = global i32 0
@errno = global i64 0
@EINVAL = global i64 0
@.str.1 = [16 x i8] c"Bad port number\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = load i32, i32* %4
%8 = icmp ne i32 %7, 2
br i1 %8, label %9, label %17
9: ; preds = %2
%10 = load i32, i32* @stderr
%11 = load i8**, i8*** %5
%12 = getelementptr inbounds i8*, i8** %11, i64 0
%13 = load i8*, i8** %12
%14 = call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %13)
%15 = load i32, i32* @EXIT_FAILURE
%16 = call i32 @exit(i32 %15)
unreachable
17: ; preds = %2
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = call i32 @strtol(i8* %20, i32* null, i32 10)
store i32 %21, i32* %6
%22 = load i32, i32* %6
%23 = icmp eq i32 %22, 0
br i1 %23, label %24, label %32
24: ; preds = %17
%25 = load i64, i64* @errno
%26 = load i64, i64* @EINVAL
%27 = icmp eq i64 %25, %26
br i1 %27, label %28, label %32
28: ; preds = %24
%29 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
%30 = load i32, i32* @EXIT_FAILURE
%31 = call i32 @exit(i32 %30)
unreachable
32: ; preds = %24, %17
%33 = load i32, i32* %6
%34 = call i32 @control_loop(i32 %33)
ret i32 %34
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [16 x i8] c"USAGE: %s port\0A\00"
@EXIT_FAILURE = global i32 0
@errno = global i64 0
@EINVAL = global i64 0
@.str.1 = [16 x i8] c"Bad port number\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %10, label %4
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = load i8*, i8** %1
%7 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %6)
%8 = load i32, i32* @EXIT_FAILURE
%9 = tail call i32 @exit(i32 %8)
unreachable
10: ; preds = %2
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = tail call i32 @strtol(i8* nocapture %12, i32* null, i32 10)
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %23
15: ; preds = %10
%16 = load i64, i64* @errno
%17 = load i64, i64* @EINVAL
%18 = icmp eq i64 %16, %17
br i1 %18, label %19, label %23
19: ; preds = %15
%20 = tail call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
%21 = load i32, i32* @EXIT_FAILURE
%22 = tail call i32 @exit(i32 %21)
unreachable
23: ; preds = %15, %10
%24 = tail call i32 @control_loop(i32 %13)
ret i32 %24
}