#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 *);
char *strchr(char *, char);
int strlen(char *);
scalar_t__ strn_casecmp(char *, char *, int);
int has_client_port(char *inp, int *port) {
  int l;
  char *p;
  l = strlen(inp);
  if (l < 23)
    return 0;
  if (strn_casecmp(inp, "transport", 9) != 0)
    return 0;
  p = inp;
  while (p) {
    p = strchr(p, '=');
    if (p - 11 < inp) {
      p++;
      continue;
    }
    if (strn_casecmp(p - 11, "client_port=", 12) != 0) {
      p++;
      continue;
    }
    *port = atoi(p + 1);
    *++p = '\0';
    return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<has_client_port>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x17,-0x1c(%rbp)
jge    1172 <has_client_port+0x32>
movl   $0x0,-0x4(%rbp)
jmp    1254 <has_client_port+0x114>
mov    -0x10(%rbp),%rdi
lea    0xe83(%rip),%rsi
mov    $0x9,%edx
call   1030 <strn_casecmp@plt>
cmp    $0x0,%rax
je     119d <has_client_port+0x5d>
movl   $0x0,-0x4(%rbp)
jmp    1254 <has_client_port+0x114>
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     124d <has_client_port+0x10d>
mov    -0x28(%rbp),%rdi
mov    $0x3d,%esi
call   1050 <strchr@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
add    $0xfffffffffffffff5,%rax
cmp    -0x10(%rbp),%rax
jae    11e5 <has_client_port+0xa5>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    11a5 <has_client_port+0x65>
mov    -0x28(%rbp),%rdi
add    $0xfffffffffffffff5,%rdi
lea    0xe16(%rip),%rsi
mov    $0xc,%edx
call   1030 <strn_casecmp@plt>
cmp    $0x0,%rax
je     1219 <has_client_port+0xd9>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    11a5 <has_client_port+0x65>
mov    -0x28(%rbp),%rdi
add    $0x1,%rdi
call   1060 <atoi@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x28(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x28(%rbp)
movb   $0x0,0x1(%rax)
movl   $0x1,-0x4(%rbp)
jmp    1254 <has_client_port+0x114>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<has_client_port>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
call   1040 <strlen@plt>
xor    %ebx,%ebx
cmp    $0x17,%eax
jl     11d7 <has_client_port+0x97>
lea    0xe9f(%rip),%rsi
mov    %r15,%rdi
mov    $0x9,%edx
call   1030 <strn_casecmp@plt>
test   %rax,%rax
jne    11d7 <has_client_port+0x97>
test   %r15,%r15
je     11d7 <has_client_port+0x97>
lea    0xe8b(%rip),%r12
mov    %r15,%rbx
jmp    1194 <has_client_port+0x54>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
add    $0x1,%rbx
mov    %rbx,%rdi
mov    $0x3d,%esi
call   1050 <strchr@plt>
mov    %rax,%rbx
lea    -0xb(%rax),%rdi
cmp    %r15,%rdi
jb     1190 <has_client_port+0x50>
mov    %r12,%rsi
mov    $0xc,%edx
call   1030 <strn_casecmp@plt>
test   %rax,%rax
jne    1190 <has_client_port+0x50>
mov    %rbx,%rdi
add    $0x1,%rdi
call   1060 <atoi@plt>
mov    %eax,(%r14)
movb   $0x0,0x1(%rbx)
mov    $0x1,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [10 x i8] c"transport\00"
@.str.1 = [13 x i8] c"client_port=\00"
define i32 @has_client_port(i8* %0, i32* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i8*
store i8* %0, i8** %4
store i32* %1, i32** %5
%8 = load i8*, i8** %4
%9 = call i32 @strlen(i8* %8)
store i32 %9, i32* %6
%10 = load i32, i32* %6
%11 = icmp slt i32 %10, 23
br i1 %11, label %12, label %13
12: ; preds = %2
store i32 0, i32* %3
br label %49
13: ; preds = %2
%14 = load i8*, i8** %4
%15 = call i64 @strn_casecmp(i8* %14, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 9)
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %18
17: ; preds = %13
store i32 0, i32* %3
br label %49
18: ; preds = %13
%19 = load i8*, i8** %4
store i8* %19, i8** %7
br label %20
20: ; preds = %38, %30, %18
%21 = load i8*, i8** %7
%22 = icmp ne i8* %21, null
br i1 %22, label %23, label %48
23: ; preds = %20
%24 = load i8*, i8** %7
%25 = call i8* @strchr(i8* %24, i8 signext 61)
store i8* %25, i8** %7
%26 = load i8*, i8** %7
%27 = getelementptr inbounds i8, i8* %26, i64 -11
%28 = load i8*, i8** %4
%29 = icmp ult i8* %27, %28
br i1 %29, label %30, label %33
30: ; preds = %23
%31 = load i8*, i8** %7
%32 = getelementptr inbounds i8, i8* %31, i32 1
store i8* %32, i8** %7
br label %20
33: ; preds = %23
%34 = load i8*, i8** %7
%35 = getelementptr inbounds i8, i8* %34, i64 -11
%36 = call i64 @strn_casecmp(i8* %35, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 12)
%37 = icmp ne i64 %36, 0
br i1 %37, label %38, label %41
38: ; preds = %33
%39 = load i8*, i8** %7
%40 = getelementptr inbounds i8, i8* %39, i32 1
store i8* %40, i8** %7
br label %20
41: ; preds = %33
%42 = load i8*, i8** %7
%43 = getelementptr inbounds i8, i8* %42, i64 1
%44 = call i32 @atoi(i8* %43)
%45 = load i32*, i32** %5
store i32 %44, i32* %45
%46 = load i8*, i8** %7
%47 = getelementptr inbounds i8, i8* %46, i32 1
store i8* %47, i8** %7
store i8 0, i8* %47
store i32 1, i32* %3
br label %49
48: ; preds = %20
store i32 0, i32* %3
br label %49
49: ; preds = %48, %41, %17, %12
%50 = load i32, i32* %3
ret i32 %50
}

LLVM IR (-O2):
@.str = [10 x i8] c"transport\00"
@.str.1 = [13 x i8] c"client_port=\00"
define i32 @has_client_port(i8* %0, i32* nocapture writeonly %1) {
%3 = tail call i32 @strlen(i8* %0)
%4 = icmp slt i32 %3, 23
br i1 %4, label %23, label %5
5: ; preds = %2
%6 = tail call i64 @strn_casecmp(i8* %0, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 9)
%7 = icmp ne i64 %6, 0
%8 = icmp eq i8* %0, null
%9 = or i1 %7, %8
br i1 %9, label %23, label %10
10: ; preds = %5, %15
%11 = phi i8* [ %16, %15 ], [ %0, %5 ]
%12 = tail call i8* @strchr(i8* %11, i8 signext 61)
%13 = getelementptr inbounds i8, i8* %12, i64 -11
%14 = icmp ult i8* %13, %0
br i1 %14, label %15, label %17
15: ; preds = %17, %10
%16 = getelementptr inbounds i8, i8* %12, i64 1
br label %10
17: ; preds = %10
%18 = tail call i64 @strn_casecmp(i8* %13, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 12)
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %15
20: ; preds = %17
%21 = getelementptr inbounds i8, i8* %12, i64 1
%22 = tail call i32 @atoi(i8* %21)
store i32 %22, i32* %1
store i8 0, i8* %21
br label %23
23: ; preds = %5, %2, %20
%24 = phi i32 [ 1, %20 ], [ 0, %2 ], [ 0, %5 ]
ret i32 %24
}