#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ log_msg(int /*<<< orphan*/ *, char *);
int /*<<< orphan*/ log_msg_arg1(int /*<<< orphan*/ *, char *, long);
scalar_t__ strcmp(char *, char *);
long strtol(char *, int /*<<< orphan*/ *, int /*<<< orphan*/);
long check_args(FILE *f, int argc, char *argv[]) {
  long local_port = 0;
  if (argc != 3) {
    log_msg(f, "usage: server -p <port> (not enough or too many args)\n");
    exit(-1);
  }
  if (strcmp(argv[1], "-p") != 0) {
    log_msg(f, "usage: server -p <port> (first argument must be: -p\n");
    exit(-1);
  }
  if ((local_port = strtol(argv[2], NULL, 0)) == 0) {
    log_msg(f, "usage: server -p <port> (second argument must be numeric)\n");
    exit(-1);
  }
  if (local_port < 1025) {
    log_msg_arg1(f, "usage: server -p <port> (%ld must be > 1024)\n",
                 local_port);
    exit(-1);
  }
  if (local_port > 9999) {
    log_msg_arg1(f, "usage: server -p <port> (%ld must be < 10000 )\n",
                 local_port);
    exit(-1);
  }
  return local_port;
}


x86 assembly (clang, -O0):
<check_args>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
cmpl   $0x3,-0xc(%rbp)
je     118f <check_args+0x3f>
mov    -0x8(%rbp),%rdi
lea    0xe80(%rip),%rsi
call   1060 <log_msg@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe99(%rip),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%rax
je     11c7 <check_args+0x77>
mov    -0x8(%rbp),%rdi
lea    0xe82(%rip),%rsi
call   1060 <log_msg@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>
mov    -0x18(%rbp),%rax
mov    0x10(%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1050 <strtol@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    1202 <check_args+0xb2>
mov    -0x8(%rbp),%rdi
lea    0xe7c(%rip),%rsi
call   1060 <log_msg@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>
cmpq   $0x401,-0x20(%rbp)
jge    122e <check_args+0xde>
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rdx
lea    0xe8b(%rip),%rsi
call   1040 <log_msg_arg1@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>
cmpq   $0x270f,-0x20(%rbp)
jle    125a <check_args+0x10a>
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rdx
lea    0xe8d(%rip),%rsi
call   1040 <log_msg_arg1@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>
mov    -0x20(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_args>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
cmp    $0x3,%esi
jne    119e <check_args+0x4e>
mov    %rdx,%rbx
mov    0x8(%rdx),%rdi
lea    0xecd(%rip),%rsi
call   1030 <strcmp@plt>
test   %rax,%rax
jne    11a7 <check_args+0x57>
mov    0x10(%rbx),%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1050 <strtol@plt>
test   %rax,%rax
je     11b0 <check_args+0x60>
cmp    $0x400,%rax
jle    11c9 <check_args+0x79>
cmp    $0x2710,%rax
jae    11d2 <check_args+0x82>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe5b(%rip),%rsi
jmp    11b7 <check_args+0x67>
lea    0xe8c(%rip),%rsi
jmp    11b7 <check_args+0x67>
lea    0xeb8(%rip),%rsi
mov    %r14,%rdi
call   1060 <log_msg@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>
lea    0xeda(%rip),%rsi
jmp    11d9 <check_args+0x89>
lea    0xeff(%rip),%rsi
mov    %r14,%rdi
mov    %rax,%rdx
call   1040 <log_msg_arg1@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [55 x i8] c"usage: server -p <port> (not enough or too many args)\0A\00"
@.str.1 = [3 x i8] c"-p\00"
@.str.2 = [53 x i8] c"usage: server -p <port> (first argument must be: -p\0A\00"
@.str.3 = [59 x i8] c"usage: server -p <port> (second argument must be numeric)\0A\00"
@.str.4 = [46 x i8] c"usage: server -p <port> (%ld must be > 1024)\0A\00"
@.str.5 = [48 x i8] c"usage: server -p <port> (%ld must be < 10000 )\0A\00"
define i64 @check_args(i32* %0, i32 %1, i8** %2) {
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i8**
%7 = alloca i64
store i32* %0, i32** %4
store i32 %1, i32* %5
store i8** %2, i8*** %6
store i64 0, i64* %7
%8 = load i32, i32* %5
%9 = icmp ne i32 %8, 3
br i1 %9, label %10, label %14
10: ; preds = %3
%11 = load i32*, i32** %4
%12 = call i32 @log_msg(i32* %11, i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0))
%13 = call i32 @exit(i32 -1)
unreachable
14: ; preds = %3
%15 = load i8**, i8*** %6
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = load i8*, i8** %16
%18 = call i64 @strcmp(i8* %17, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%19 = icmp ne i64 %18, 0
br i1 %19, label %20, label %24
20: ; preds = %14
%21 = load i32*, i32** %4
%22 = call i32 @log_msg(i32* %21, i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.2, i64 0, i64 0))
%23 = call i32 @exit(i32 -1)
unreachable
24: ; preds = %14
%25 = load i8**, i8*** %6
%26 = getelementptr inbounds i8*, i8** %25, i64 2
%27 = load i8*, i8** %26
%28 = call i64 @strtol(i8* %27, i32* null, i32 0)
store i64 %28, i64* %7
%29 = icmp eq i64 %28, 0
br i1 %29, label %30, label %34
30: ; preds = %24
%31 = load i32*, i32** %4
%32 = call i32 @log_msg(i32* %31, i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.3, i64 0, i64 0))
%33 = call i32 @exit(i32 -1)
unreachable
34: ; preds = %24
%35 = load i64, i64* %7
%36 = icmp slt i64 %35, 1025
br i1 %36, label %37, label %42
37: ; preds = %34
%38 = load i32*, i32** %4
%39 = load i64, i64* %7
%40 = call i32 @log_msg_arg1(i32* %38, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.4, i64 0, i64 0), i64 %39)
%41 = call i32 @exit(i32 -1)
unreachable
42: ; preds = %34
%43 = load i64, i64* %7
%44 = icmp sgt i64 %43, 9999
br i1 %44, label %45, label %50
45: ; preds = %42
%46 = load i32*, i32** %4
%47 = load i64, i64* %7
%48 = call i32 @log_msg_arg1(i32* %46, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.5, i64 0, i64 0), i64 %47)
%49 = call i32 @exit(i32 -1)
unreachable
50: ; preds = %42
%51 = load i64, i64* %7
ret i64 %51
}

LLVM IR (-O2):
@.str = [55 x i8] c"usage: server -p <port> (not enough or too many args)\0A\00"
@.str.1 = [3 x i8] c"-p\00"
@.str.2 = [53 x i8] c"usage: server -p <port> (first argument must be: -p\0A\00"
@.str.3 = [59 x i8] c"usage: server -p <port> (second argument must be numeric)\0A\00"
@.str.4 = [46 x i8] c"usage: server -p <port> (%ld must be > 1024)\0A\00"
@.str.5 = [48 x i8] c"usage: server -p <port> (%ld must be < 10000 )\0A\00"
define i64 @check_args(i32* %0, i32 %1, i8** nocapture %2) {
%4 = icmp eq i32 %1, 3
br i1 %4, label %8, label %5
5: ; preds = %3
%6 = tail call i32 @log_msg(i32* %0, i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0))
%7 = tail call i32 @exit(i32 -1)
unreachable
8: ; preds = %3
%9 = getelementptr inbounds i8*, i8** %2, i64 1
%10 = load i8*, i8** %9
%11 = tail call i64 @strcmp(i8* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%12 = icmp eq i64 %11, 0
br i1 %12, label %16, label %13
13: ; preds = %8
%14 = tail call i32 @log_msg(i32* %0, i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.2, i64 0, i64 0))
%15 = tail call i32 @exit(i32 -1)
unreachable
16: ; preds = %8
%17 = getelementptr inbounds i8*, i8** %2, i64 2
%18 = load i8*, i8** %17
%19 = tail call i64 @strtol(i8* nocapture %18, i32* null, i32 0)
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %16
%22 = tail call i32 @log_msg(i32* %0, i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.3, i64 0, i64 0))
%23 = tail call i32 @exit(i32 -1)
unreachable
24: ; preds = %16
%25 = icmp slt i64 %19, 1025
br i1 %25, label %26, label %29
26: ; preds = %24
%27 = tail call i32 @log_msg_arg1(i32* %0, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.4, i64 0, i64 0), i64 %19)
%28 = tail call i32 @exit(i32 -1)
unreachable
29: ; preds = %24
%30 = icmp ugt i64 %19, 9999
br i1 %30, label %31, label %34
31: ; preds = %29
%32 = tail call i32 @log_msg_arg1(i32* %0, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.5, i64 0, i64 0), i64 %19)
%33 = tail call i32 @exit(i32 -1)
unreachable
34: ; preds = %29
ret i64 %19
}