#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 *);
scalar_t__ strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
char *strstr(char *, char *);
int getport(char *string) {
  char *stringp = string;
  char strPort[10];
  stringp = strstr(string, "=");
  if (stringp != (char *)NULL) {
    stringp++;
    if (strlen(stringp)) {
      strncpy(strPort, stringp, 10);
      return (atoi((char *)strPort));
    } else {
      return (0);
    }
  } else {
    return (0);
  }
}


x86 assembly (clang, -O0):
<getport>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xea1(%rip),%rsi
call   1060 <strstr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11c1 <getport+0x81>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x0,%rax
je     11b5 <getport+0x75>
lea    -0x22(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    $0xa,%edx
call   1030 <strncpy@plt>
lea    -0x22(%rbp),%rdi
call   1050 <atoi@plt>
mov    %eax,-0x4(%rbp)
jmp    11c8 <getport+0x88>
movl   $0x0,-0x4(%rbp)
jmp    11c8 <getport+0x88>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getport>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
mov    $0x3d,%esi
call   1050 <strchr@plt>
xor    %ebp,%ebp
test   %rax,%rax
je     118a <getport+0x4a>
mov    %rax,%rbx
add    $0x1,%rbx
mov    %rbx,%rdi
call   1040 <strlen@plt>
test   %rax,%rax
je     118a <getport+0x4a>
lea    0xe(%rsp),%rbp
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    $0xa,%edx
call   1030 <strncpy@plt>
mov    %rbp,%rdi
call   1060 <atoi@plt>
mov    %eax,%ebp
mov    %ebp,%eax
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"=\00"
define i32 @getport(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca [10 x i8]
store i8* %0, i8** %3
%6 = load i8*, i8** %3
store i8* %6, i8** %4
%7 = load i8*, i8** %3
%8 = call i8* @strstr(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %8, i8** %4
%9 = load i8*, i8** %4
%10 = icmp ne i8* %9, null
br i1 %10, label %11, label %24
11: ; preds = %1
%12 = load i8*, i8** %4
%13 = getelementptr inbounds i8, i8* %12, i32 1
store i8* %13, i8** %4
%14 = load i8*, i8** %4
%15 = call i64 @strlen(i8* %14)
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %23
17: ; preds = %11
%18 = getelementptr inbounds [10 x i8], [10 x i8]* %5, i64 0, i64 0
%19 = load i8*, i8** %4
%20 = call i32 @strncpy(i8* %18, i8* %19, i32 10)
%21 = getelementptr inbounds [10 x i8], [10 x i8]* %5, i64 0, i64 0
%22 = call i32 @atoi(i8* %21)
store i32 %22, i32* %2
br label %25
23: ; preds = %11
store i32 0, i32* %2
br label %25
24: ; preds = %1
store i32 0, i32* %2
br label %25
25: ; preds = %24, %23, %17
%26 = load i32, i32* %2
ret i32 %26
}

LLVM IR (-O2):
define i32 @getport(i8* %0) {
%2 = alloca [10 x i8]
%3 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%4 = tail call i8* @strchr(i8* dereferenceable(1) %0, i32 61)
%5 = icmp eq i8* %4, null
br i1 %5, label %13, label %6
6: ; preds = %1
%7 = getelementptr inbounds i8, i8* %4, i64 1
%8 = tail call i64 @strlen(i8* %7)
%9 = icmp eq i64 %8, 0
br i1 %9, label %13, label %10
10: ; preds = %6
%11 = call i32 @strncpy(i8* %3, i8* %7, i32 10)
%12 = call i32 @atoi(i8* %3)
br label %13
13: ; preds = %1, %6, %10
%14 = phi i32 [ %12, %10 ], [ 0, %6 ], [ 0, %1 ]
ret i32 %14
}