#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 atoi(char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ htxcmd_display_usage(char *);
int /*<<< orphan*/ strlen(char *);
scalar_t__ strncmp(char *, char *, int /*<<< orphan*/);
int htxcmd_get_daemon_port_number(int argument_count, char *argument_vector[],
                                  int *daemon_port_number) {
  int i;
  for (i = 1; i < argument_count; i++) {
    if ((strncmp("-port", argument_vector[i], strlen("-port"))) == 0) {
      i++;
      if (i >= argument_count) {
        htxcmd_display_usage("Error : Invalid daemon port number");
        exit(1);
      }
      if (argument_vector[i][0] != '-') {
        *daemon_port_number = atoi(argument_vector[i]);
        break;
      } else {
        htxcmd_display_usage("Error : Invalid daemon port number");
        exit(1);
      }
    }
  }
  return *daemon_port_number;
}


x86 assembly (clang, -O0):
<htxcmd_get_daemon_port_number>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x1,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    1238 <htxcmd_get_daemon_port_number+0xe8>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x28(%rbp)
lea    0xe73(%rip),%rdi
call   1040 <strlen@plt>
mov    -0x28(%rbp),%rsi
mov    %eax,%edx
lea    0xe61(%rip),%rdi
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    1225 <htxcmd_get_daemon_port_number+0xd5>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x4(%rbp),%eax
jl     11d9 <htxcmd_get_daemon_port_number+0x89>
lea    0xe3c(%rip),%rdi
call   1050 <htxcmd_display_usage@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movsbl (%rax),%eax
cmp    $0x2d,%eax
je     120f <htxcmd_get_daemon_port_number+0xbf>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1060 <atoi@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
jmp    1238 <htxcmd_get_daemon_port_number+0xe8>
lea    0xdf0(%rip),%rdi
call   1050 <htxcmd_display_usage@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
jmp    122a <htxcmd_get_daemon_port_number+0xda>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    116a <htxcmd_get_daemon_port_number+0x1a>
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<htxcmd_get_daemon_port_number>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,(%rsp)
cmp    $0x2,%edi
jl     11dc <htxcmd_get_daemon_port_number+0x8c>
mov    %rsi,%r12
mov    %edi,%r15d
mov    %edi,%eax
mov    $0x1,%r14d
sub    %rax,%r14
mov    $0x2,%ebp
lea    0xe7f(%rip),%r13
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    -0x8(%r12,%rbp,8),%rbx
mov    %r13,%rdi
call   1040 <strlen@plt>
mov    %r13,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     11c3 <htxcmd_get_daemon_port_number+0x73>
lea    (%r14,%rbp,1),%rax
add    $0x1,%rax
add    $0x1,%rbp
cmp    $0x2,%rax
jne    1190 <htxcmd_get_daemon_port_number+0x40>
jmp    11dc <htxcmd_get_daemon_port_number+0x8c>
cmp    %r15d,%ebp
jge    11f1 <htxcmd_get_daemon_port_number+0xa1>
mov    (%r12,%rbp,8),%rdi
cmpb   $0x2d,(%rdi)
je     11f1 <htxcmd_get_daemon_port_number+0xa1>
call   1060 <atoi@plt>
mov    (%rsp),%rcx
mov    %eax,(%rcx)
mov    (%rsp),%rax
mov    (%rax),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe0e(%rip),%rdi
call   1050 <htxcmd_display_usage@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [6 x i8] c"-port\00"
@.str.1 = [35 x i8] c"Error : Invalid daemon port number\00"
define i32 @htxcmd_get_daemon_port_number(i32 %0, i8** %1, i32* %2) {
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32* %2, i32** %6
store i32 1, i32* %7
br label %8
8: ; preds = %52, %3
%9 = load i32, i32* %7
%10 = load i32, i32* %4
%11 = icmp slt i32 %9, %10
br i1 %11, label %12, label %55
12: ; preds = %8
%13 = load i8**, i8*** %5
%14 = load i32, i32* %7
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i8*, i8** %13, i64 %15
%17 = load i8*, i8** %16
%18 = call i32 @strlen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%19 = call i64 @strncmp(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %17, i32 %18)
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %51
21: ; preds = %12
%22 = load i32, i32* %7
%23 = add nsw i32 %22, 1
store i32 %23, i32* %7
%24 = load i32, i32* %7
%25 = load i32, i32* %4
%26 = icmp sge i32 %24, %25
br i1 %26, label %27, label %30
27: ; preds = %21
%28 = call i32 @htxcmd_display_usage(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0))
%29 = call i32 @exit(i32 1)
unreachable
30: ; preds = %21
%31 = load i8**, i8*** %5
%32 = load i32, i32* %7
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8*, i8** %31, i64 %33
%35 = load i8*, i8** %34
%36 = getelementptr inbounds i8, i8* %35, i64 0
%37 = load i8, i8* %36
%38 = sext i8 %37 to i32
%39 = icmp ne i32 %38, 45
br i1 %39, label %40, label %48
40: ; preds = %30
%41 = load i8**, i8*** %5
%42 = load i32, i32* %7
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds i8*, i8** %41, i64 %43
%45 = load i8*, i8** %44
%46 = call i32 @atoi(i8* %45)
%47 = load i32*, i32** %6
store i32 %46, i32* %47
br label %55
48: ; preds = %30
%49 = call i32 @htxcmd_display_usage(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0))
%50 = call i32 @exit(i32 1)
unreachable
51: ; preds = %12
br label %52
52: ; preds = %51
%53 = load i32, i32* %7
%54 = add nsw i32 %53, 1
store i32 %54, i32* %7
br label %8
55: ; preds = %40, %8
%56 = load i32*, i32** %6
%57 = load i32, i32* %56
ret i32 %57
}

LLVM IR (-O2):
@.str = [6 x i8] c"-port\00"
@.str.1 = [35 x i8] c"Error : Invalid daemon port number\00"
define i32 @htxcmd_get_daemon_port_number(i32 %0, i8** nocapture %1, i32* nocapture %2) {
%4 = icmp sgt i32 %0, 1
br i1 %4, label %5, label %35
5: ; preds = %3
%6 = zext i32 %0 to i64
br label %7
7: ; preds = %5, %32
%8 = phi i64 [ 1, %5 ], [ %33, %32 ]
%9 = getelementptr inbounds i8*, i8** %1, i64 %8
%10 = load i8*, i8** %9
%11 = tail call i32 @strlen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%12 = tail call i64 @strncmp(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %10, i32 %11)
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %32
14: ; preds = %7
%15 = trunc i64 %8 to i32
%16 = add nuw nsw i32 %15, 1
%17 = icmp slt i32 %16, %0
br i1 %17, label %21, label %18
18: ; preds = %14
%19 = tail call i32 @htxcmd_display_usage(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0))
%20 = tail call i32 @exit(i32 1)
unreachable
21: ; preds = %14
%22 = zext i32 %16 to i64
%23 = getelementptr inbounds i8*, i8** %1, i64 %22
%24 = load i8*, i8** %23
%25 = load i8, i8* %24
%26 = icmp eq i8 %25, 45
br i1 %26, label %29, label %27
27: ; preds = %21
%28 = tail call i32 @atoi(i8* %24)
store i32 %28, i32* %2
br label %35
29: ; preds = %21
%30 = tail call i32 @htxcmd_display_usage(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0))
%31 = tail call i32 @exit(i32 1)
unreachable
32: ; preds = %7
%33 = add nuw nsw i64 %8, 1
%34 = icmp eq i64 %33, %6
br i1 %34, label %35, label %7
35: ; preds = %32, %3, %27
%36 = load i32, i32* %2
ret i32 %36
}