#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 */
struct chat_state {
  int dummy;
};

/* Variables and functions */
scalar_t__ chat_begin_listen(struct chat_state *, unsigned int);
unsigned int strtol(char *, char **, int /*<<< orphan*/);
unsigned command_listen(struct chat_state *state, int argc, char **argv) {
  unsigned port = 14137;
  if (argc == 1) {
    char *port_end = NULL;
    port = strtol(argv[0], &port_end, 0);
    if (port <= 0 || port >= (1 << 16) || *port_end != 0) {
      return 2;
    }
  } else if (argc != 0) {
    return 2;
  }
  if (chat_begin_listen(state, port)) {
    return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<command_listen>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
movl   $0x3739,-0x24(%rbp)
cmpl   $0x1,-0x14(%rbp)
jne    1199 <command_listen+0x79>
movq   $0x0,-0x30(%rbp)
mov    -0x20(%rbp),%rax
mov    (%rax),%rdi
lea    -0x30(%rbp),%rsi
xor    %edx,%edx
call   1030 <strtol@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jbe    1188 <command_listen+0x68>
cmpl   $0x10000,-0x24(%rbp)
jae    1188 <command_listen+0x68>
mov    -0x30(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1194 <command_listen+0x74>
movl   $0x2,-0x4(%rbp)
jmp    11dd <command_listen+0xbd>
jmp    11b4 <command_listen+0x94>
cmpl   $0x0,-0x14(%rbp)
je     11af <command_listen+0x8f>
movl   $0x2,-0x4(%rbp)
jmp    11dd <command_listen+0xbd>
jmp    11b4 <command_listen+0x94>
mov    -0x10(%rbp),%rdi
mov    -0x24(%rbp),%esi
call   1040 <chat_begin_listen@plt>
cmp    $0x0,%rax
je     11d6 <command_listen+0xb6>
movl   $0x1,-0x4(%rbp)
jmp    11dd <command_listen+0xbd>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<command_listen>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
test   %esi,%esi
je     1163 <command_listen+0x43>
mov    $0x2,%ebp
cmp    $0x1,%esi
jne    1179 <command_listen+0x59>
movq   $0x0,(%rsp)
mov    (%rdx),%rdi
mov    %rsp,%rsi
xor    %edx,%edx
call   1030 <strtol@plt>
mov    %eax,%esi
lea    -0x10000(%rsi),%eax
cmp    $0xffff0001,%eax
jb     1179 <command_listen+0x59>
mov    (%rsp),%rax
cmpb   $0x0,(%rax)
jne    1179 <command_listen+0x59>
jmp    1168 <command_listen+0x48>
mov    $0x3739,%esi
mov    %rbx,%rdi
call   1040 <chat_begin_listen@plt>
xor    %ebp,%ebp
test   %rax,%rax
setne  %bpl
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.chat_state = type { i32 }
define i32 @command_listen(%struct.chat_state* %0, i32 %1, i8** %2) {
%4 = alloca i32
%5 = alloca %struct.chat_state*
%6 = alloca i32
%7 = alloca i8**
%8 = alloca i32
%9 = alloca i8*
store %struct.chat_state* %0, %struct.chat_state** %5
store i32 %1, i32* %6
store i8** %2, i8*** %7
store i32 14137, i32* %8
%10 = load i32, i32* %6
%11 = icmp eq i32 %10, 1
br i1 %11, label %12, label %29
12: ; preds = %3
store i8* null, i8** %9
%13 = load i8**, i8*** %7
%14 = getelementptr inbounds i8*, i8** %13, i64 0
%15 = load i8*, i8** %14
%16 = call i32 @strtol(i8* %15, i8** %9, i32 0)
store i32 %16, i32* %8
%17 = load i32, i32* %8
%18 = icmp ule i32 %17, 0
br i1 %18, label %27, label %19
19: ; preds = %12
%20 = load i32, i32* %8
%21 = icmp uge i32 %20, 65536
br i1 %21, label %27, label %22
22: ; preds = %19
%23 = load i8*, i8** %9
%24 = load i8, i8* %23
%25 = sext i8 %24 to i32
%26 = icmp ne i32 %25, 0
br i1 %26, label %27, label %28
27: ; preds = %22, %19, %12
store i32 2, i32* %4
br label %41
28: ; preds = %22
br label %34
29: ; preds = %3
%30 = load i32, i32* %6
%31 = icmp ne i32 %30, 0
br i1 %31, label %32, label %33
32: ; preds = %29
store i32 2, i32* %4
br label %41
33: ; preds = %29
br label %34
34: ; preds = %33, %28
%35 = load %struct.chat_state*, %struct.chat_state** %5
%36 = load i32, i32* %8
%37 = call i64 @chat_begin_listen(%struct.chat_state* %35, i32 %36)
%38 = icmp ne i64 %37, 0
br i1 %38, label %39, label %40
39: ; preds = %34
store i32 1, i32* %4
br label %41
40: ; preds = %34
store i32 0, i32* %4
br label %41
41: ; preds = %40, %39, %32, %27
%42 = load i32, i32* %4
ret i32 %42
}

LLVM IR (-O2):
%struct.chat_state = type { i32 }
define i32 @command_listen(%struct.chat_state* %0, i32 %1, i8** nocapture %2) {
%4 = alloca i8*
switch i32 %1, label %22 [
i32 1, label %5
i32 0, label %17
]
5: ; preds = %3
%6 = bitcast i8** %4 to i8*
store i8* null, i8** %4
%7 = load i8*, i8** %2
%8 = call i32 @strtol(i8* %7, i8** %4, i32 0)
%9 = add i32 %8, -65536
%10 = icmp ult i32 %9, -65535
br i1 %10, label %16, label %11
11: ; preds = %5
%12 = load i8*, i8** %4
%13 = load i8, i8* %12
%14 = icmp eq i8 %13, 0
br i1 %14, label %15, label %16
15: ; preds = %11
br label %17
16: ; preds = %5, %11
br label %22
17: ; preds = %3, %15
%18 = phi i32 [ %8, %15 ], [ 14137, %3 ]
%19 = tail call i64 @chat_begin_listen(%struct.chat_state* %0, i32 %18)
%20 = icmp ne i64 %19, 0
%21 = zext i1 %20 to i32
br label %22
22: ; preds = %17, %3, %16
%23 = phi i32 [ 2, %16 ], [ 2, %3 ], [ %21, %17 ]
ret i32 %23
}