#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__ strcmp(char *, char *);
scalar_t__ strtol(char *, char **, int);
unsigned int get_udp_load_balancer_port(int argc, char **argv) {
  char *port_as_string;
  unsigned int port;
  unsigned int i;
  for (i = 0; i < argc; ++i) {
    if (strcmp(argv[i], "-p") == 0 || strcmp(argv[i], "--port") == 0) {
      port_as_string = argv[i + 1];
      port = (unsigned int)strtol(port_as_string, (char **)NULL, 10);
      if (port < 1 || port > 65535) {
        return 0;
      }
      return port;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<get_udp_load_balancer_port>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x8(%rbp),%eax
jae    11ee <get_udp_load_balancer_port+0xce>
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%ecx
mov    (%rax,%rcx,8),%rdi
lea    0xeac(%rip),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%rax
je     1184 <get_udp_load_balancer_port+0x64>
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%ecx
mov    (%rax,%rcx,8),%rdi
lea    0xe8e(%rip),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%rax
jne    11db <get_udp_load_balancer_port+0xbb>
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%ecx
add    $0x1,%ecx
mov    %ecx,%ecx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1040 <strtol@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x1,-0x1c(%rbp)
jb     11c4 <get_udp_load_balancer_port+0xa4>
cmpl   $0xffff,-0x1c(%rbp)
jbe    11d0 <get_udp_load_balancer_port+0xb0>
movl   $0x0,-0x4(%rbp)
jmp    11f5 <get_udp_load_balancer_port+0xd5>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11f5 <get_udp_load_balancer_port+0xd5>
jmp    11e0 <get_udp_load_balancer_port+0xc0>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1136 <get_udp_load_balancer_port+0x16>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_udp_load_balancer_port>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
test   %edi,%edi
je     117d <get_udp_load_balancer_port+0x5d>
mov    %rsi,%r13
mov    %edi,%r12d
xor    %ebx,%ebx
lea    0xec4(%rip),%r14
lea    0xec0(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    0x0(%r13,%rbx,8),%rdi
mov    %r14,%rsi
call   1030 <strcmp@plt>
test   %rax,%rax
je     1181 <get_udp_load_balancer_port+0x61>
mov    0x0(%r13,%rbx,8),%rdi
mov    %r15,%rsi
call   1030 <strcmp@plt>
test   %rax,%rax
je     1181 <get_udp_load_balancer_port+0x61>
add    $0x1,%rbx
cmp    %rbx,%r12
jne    1150 <get_udp_load_balancer_port+0x30>
xor    %eax,%eax
jmp    11a3 <get_udp_load_balancer_port+0x83>
mov    0x8(%r13,%rbx,8),%rdi
xor    %ebx,%ebx
xor    %esi,%esi
mov    $0xa,%edx
call   1040 <strtol@plt>
lea    -0x10000(%rax),%ecx
cmp    $0xffff0001,%ecx
cmovb  %ebx,%eax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [3 x i8] c"-p\00"
@.str.1 = [7 x i8] c"--port\00"
define i32 @get_udp_load_balancer_port(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %8
br label %9
9: ; preds = %48, %2
%10 = load i32, i32* %8
%11 = load i32, i32* %4
%12 = icmp ult i32 %10, %11
br i1 %12, label %13, label %51
13: ; preds = %9
%14 = load i8**, i8*** %5
%15 = load i32, i32* %8
%16 = zext i32 %15 to i64
%17 = getelementptr inbounds i8*, i8** %14, i64 %16
%18 = load i8*, i8** %17
%19 = call i64 @strcmp(i8* %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%20 = icmp eq i64 %19, 0
br i1 %20, label %29, label %21
21: ; preds = %13
%22 = load i8**, i8*** %5
%23 = load i32, i32* %8
%24 = zext i32 %23 to i64
%25 = getelementptr inbounds i8*, i8** %22, i64 %24
%26 = load i8*, i8** %25
%27 = call i64 @strcmp(i8* %26, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%28 = icmp eq i64 %27, 0
br i1 %28, label %29, label %47
29: ; preds = %21, %13
%30 = load i8**, i8*** %5
%31 = load i32, i32* %8
%32 = add i32 %31, 1
%33 = zext i32 %32 to i64
%34 = getelementptr inbounds i8*, i8** %30, i64 %33
%35 = load i8*, i8** %34
store i8* %35, i8** %6
%36 = load i8*, i8** %6
%37 = call i64 @strtol(i8* %36, i8** null, i32 10)
%38 = trunc i64 %37 to i32
store i32 %38, i32* %7
%39 = load i32, i32* %7
%40 = icmp ult i32 %39, 1
br i1 %40, label %44, label %41
41: ; preds = %29
%42 = load i32, i32* %7
%43 = icmp ugt i32 %42, 65535
br i1 %43, label %44, label %45
44: ; preds = %41, %29
store i32 0, i32* %3
br label %52
45: ; preds = %41
%46 = load i32, i32* %7
store i32 %46, i32* %3
br label %52
47: ; preds = %21
br label %48
48: ; preds = %47
%49 = load i32, i32* %8
%50 = add i32 %49, 1
store i32 %50, i32* %8
br label %9
51: ; preds = %9
store i32 0, i32* %3
br label %52
52: ; preds = %51, %45, %44
%53 = load i32, i32* %3
ret i32 %53
}

LLVM IR (-O2):
@.str = [3 x i8] c"-p\00"
@.str.1 = [7 x i8] c"--port\00"
define i32 @get_udp_load_balancer_port(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 0
br i1 %3, label %29, label %4
4: ; preds = %2
%5 = zext i32 %0 to i64
br label %6
6: ; preds = %4, %26
%7 = phi i64 [ 0, %4 ], [ %27, %26 ]
%8 = getelementptr inbounds i8*, i8** %1, i64 %7
%9 = load i8*, i8** %8
%10 = tail call i64 @strcmp(i8* %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%11 = icmp eq i64 %10, 0
br i1 %11, label %16, label %12
12: ; preds = %6
%13 = load i8*, i8** %8
%14 = tail call i64 @strcmp(i8* %13, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %26
16: ; preds = %12, %6
%17 = add nuw i64 %7, 1
%18 = and i64 %17, 4294967295
%19 = getelementptr inbounds i8*, i8** %1, i64 %18
%20 = load i8*, i8** %19
%21 = tail call i64 @strtol(i8* nocapture %20, i8** null, i32 10)
%22 = trunc i64 %21 to i32
%23 = add i32 %22, -65536
%24 = icmp ult i32 %23, -65535
%25 = select i1 %24, i32 0, i32 %22
br label %29
26: ; preds = %12
%27 = add nuw nsw i64 %7, 1
%28 = icmp eq i64 %27, %5
br i1 %28, label %29, label %6
29: ; preds = %26, %2, %16
%30 = phi i32 [ %25, %16 ], [ 0, %2 ], [ 0, %26 ]
ret i32 %30
}