#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 getnetwork(char *string, char *host, int length, char *protocol) {
  char *stringp = string;
  char *pos, *pos2;
  char strPort[10];
  stringp = strstr(string, "=");
  if (stringp != (char *)NULL) {
    stringp++;
    if (strlen(stringp)) {
      pos = strstr(stringp, ":");
      if (pos != (char *)NULL) {
        *pos = '\0';
        pos++;
        strncpy(host, stringp, length - 1);
        pos2 = strstr(pos, ":");
        if (pos2 != (char *)NULL) {
          *pos2 = '\0';
          pos2++;
          if (strlen(pos2))
            strncpy(protocol, pos2, 10);
        }
        if (strlen(pos)) {
          strncpy(strPort, pos, 10);
          return (atoi((char *)strPort));
        } else
          return (6162);
      } else {
        strncpy(host, stringp, length - 1);
        return (6162);
      }
    } else {
      return (0);
    }
  } else {
    return (0);
  }
}


x86 assembly (clang, -O0):
<getnetwork>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe96(%rip),%rsi
call   1060 <strstr@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     12ab <getnetwork+0x16b>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x0,%rax
je     129f <getnetwork+0x15f>
mov    -0x30(%rbp),%rdi
lea    0xe5a(%rip),%rsi
call   1060 <strstr@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
je     1280 <getnetwork+0x140>
mov    -0x38(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x1c(%rbp),%edx
sub    $0x1,%edx
call   1030 <strncpy@plt>
mov    -0x38(%rbp),%rdi
lea    0xe15(%rip),%rsi
call   1060 <strstr@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
je     123e <getnetwork+0xfe>
mov    -0x40(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x40(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x0,%rax
je     1239 <getnetwork+0xf9>
mov    -0x28(%rbp),%rdi
mov    -0x40(%rbp),%rsi
mov    $0xa,%edx
call   1030 <strncpy@plt>
jmp    123e <getnetwork+0xfe>
mov    -0x38(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x0,%rax
je     1274 <getnetwork+0x134>
lea    -0x4a(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    $0xa,%edx
call   1030 <strncpy@plt>
lea    -0x4a(%rbp),%rdi
call   1050 <atoi@plt>
mov    %eax,-0x4(%rbp)
jmp    12b2 <getnetwork+0x172>
movl   $0x1812,-0x4(%rbp)
jmp    12b2 <getnetwork+0x172>
mov    -0x18(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x1c(%rbp),%edx
sub    $0x1,%edx
call   1030 <strncpy@plt>
movl   $0x1812,-0x4(%rbp)
jmp    12b2 <getnetwork+0x172>
movl   $0x0,-0x4(%rbp)
jmp    12b2 <getnetwork+0x172>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getnetwork>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rcx,%r14
mov    %edx,%r13d
mov    %rsi,%r15
mov    $0x3d,%esi
call   1050 <strchr@plt>
xor    %ebp,%ebp
test   %rax,%rax
je     1234 <getnetwork+0xf4>
mov    %rax,%rbx
add    $0x1,%rbx
mov    %rbx,%rdi
call   1040 <strlen@plt>
test   %rax,%rax
je     1234 <getnetwork+0xf4>
mov    %rbx,%rdi
mov    $0x3a,%esi
call   1050 <strchr@plt>
test   %rax,%rax
je     121d <getnetwork+0xdd>
mov    %rax,%r12
movb   $0x0,(%rax)
add    $0x1,%r12
add    $0xffffffff,%r13d
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %r13d,%edx
call   1030 <strncpy@plt>
mov    %r12,%rdi
mov    $0x3a,%esi
call   1050 <strchr@plt>
test   %rax,%rax
je     11ef <getnetwork+0xaf>
mov    %rax,%rbx
movb   $0x0,(%rax)
add    $0x1,%rbx
mov    %rbx,%rdi
call   1040 <strlen@plt>
test   %rax,%rax
je     11ef <getnetwork+0xaf>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    $0xa,%edx
call   1030 <strncpy@plt>
mov    %r12,%rdi
call   1040 <strlen@plt>
test   %rax,%rax
je     122f <getnetwork+0xef>
lea    0xe(%rsp),%rbx
mov    %rbx,%rdi
mov    %r12,%rsi
mov    $0xa,%edx
call   1030 <strncpy@plt>
mov    %rbx,%rdi
call   1060 <atoi@plt>
mov    %eax,%ebp
jmp    1234 <getnetwork+0xf4>
add    $0xffffffff,%r13d
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %r13d,%edx
call   1030 <strncpy@plt>
mov    $0x1812,%ebp
mov    %ebp,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"=\00"
@.str.1 = [2 x i8] c":\00"
define i32 @getnetwork(i8* %0, i8* %1, i32 %2, i8* %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca [10 x i8]
store i8* %0, i8** %6
store i8* %1, i8** %7
store i32 %2, i32* %8
store i8* %3, i8** %9
%14 = load i8*, i8** %6
store i8* %14, i8** %10
%15 = load i8*, i8** %6
%16 = call i8* @strstr(i8* %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %16, i8** %10
%17 = load i8*, i8** %10
%18 = icmp ne i8* %17, null
br i1 %18, label %19, label %73
19: ; preds = %4
%20 = load i8*, i8** %10
%21 = getelementptr inbounds i8, i8* %20, i32 1
store i8* %21, i8** %10
%22 = load i8*, i8** %10
%23 = call i64 @strlen(i8* %22)
%24 = icmp ne i64 %23, 0
br i1 %24, label %25, label %72
25: ; preds = %19
%26 = load i8*, i8** %10
%27 = call i8* @strstr(i8* %26, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i8* %27, i8** %11
%28 = load i8*, i8** %11
%29 = icmp ne i8* %28, null
br i1 %29, label %30, label %66
30: ; preds = %25
%31 = load i8*, i8** %11
store i8 0, i8* %31
%32 = load i8*, i8** %11
%33 = getelementptr inbounds i8, i8* %32, i32 1
store i8* %33, i8** %11
%34 = load i8*, i8** %7
%35 = load i8*, i8** %10
%36 = load i32, i32* %8
%37 = sub nsw i32 %36, 1
%38 = call i32 @strncpy(i8* %34, i8* %35, i32 %37)
%39 = load i8*, i8** %11
%40 = call i8* @strstr(i8* %39, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i8* %40, i8** %12
%41 = load i8*, i8** %12
%42 = icmp ne i8* %41, null
br i1 %42, label %43, label %55
43: ; preds = %30
%44 = load i8*, i8** %12
store i8 0, i8* %44
%45 = load i8*, i8** %12
%46 = getelementptr inbounds i8, i8* %45, i32 1
store i8* %46, i8** %12
%47 = load i8*, i8** %12
%48 = call i64 @strlen(i8* %47)
%49 = icmp ne i64 %48, 0
br i1 %49, label %50, label %54
50: ; preds = %43
%51 = load i8*, i8** %9
%52 = load i8*, i8** %12
%53 = call i32 @strncpy(i8* %51, i8* %52, i32 10)
br label %54
54: ; preds = %50, %43
br label %55
55: ; preds = %54, %30
%56 = load i8*, i8** %11
%57 = call i64 @strlen(i8* %56)
%58 = icmp ne i64 %57, 0
br i1 %58, label %59, label %65
59: ; preds = %55
%60 = getelementptr inbounds [10 x i8], [10 x i8]* %13, i64 0, i64 0
%61 = load i8*, i8** %11
%62 = call i32 @strncpy(i8* %60, i8* %61, i32 10)
%63 = getelementptr inbounds [10 x i8], [10 x i8]* %13, i64 0, i64 0
%64 = call i32 @atoi(i8* %63)
store i32 %64, i32* %5
br label %74
65: ; preds = %55
store i32 6162, i32* %5
br label %74
66: ; preds = %25
%67 = load i8*, i8** %7
%68 = load i8*, i8** %10
%69 = load i32, i32* %8
%70 = sub nsw i32 %69, 1
%71 = call i32 @strncpy(i8* %67, i8* %68, i32 %70)
store i32 6162, i32* %5
br label %74
72: ; preds = %19
store i32 0, i32* %5
br label %74
73: ; preds = %4
store i32 0, i32* %5
br label %74
74: ; preds = %73, %72, %66, %65, %59
%75 = load i32, i32* %5
ret i32 %75
}

LLVM IR (-O2):
define i32 @getnetwork(i8* %0, i8* %1, i32 %2, i8* %3) {
%5 = alloca [10 x i8]
%6 = getelementptr inbounds [10 x i8], [10 x i8]* %5, i64 0, i64 0
%7 = tail call i8* @strchr(i8* dereferenceable(1) %0, i32 61)
%8 = icmp eq i8* %7, null
br i1 %8, label %37, label %9
9: ; preds = %4
%10 = getelementptr inbounds i8, i8* %7, i64 1
%11 = tail call i64 @strlen(i8* %10)
%12 = icmp eq i64 %11, 0
br i1 %12, label %37, label %13
13: ; preds = %9
%14 = tail call i8* @strchr(i8* %10, i32 58)
%15 = icmp eq i8* %14, null
br i1 %15, label %34, label %16
16: ; preds = %13
store i8 0, i8* %14
%17 = getelementptr inbounds i8, i8* %14, i64 1
%18 = add nsw i32 %2, -1
%19 = tail call i32 @strncpy(i8* %1, i8* %10, i32 %18)
%20 = tail call i8* @strchr(i8* %17, i32 58)
%21 = icmp eq i8* %20, null
br i1 %21, label %28, label %22
22: ; preds = %16
store i8 0, i8* %20
%23 = getelementptr inbounds i8, i8* %20, i64 1
%24 = tail call i64 @strlen(i8* %23)
%25 = icmp eq i64 %24, 0
br i1 %25, label %28, label %26
26: ; preds = %22
%27 = tail call i32 @strncpy(i8* %3, i8* %23, i32 10)
br label %28
28: ; preds = %22, %26, %16
%29 = tail call i64 @strlen(i8* %17)
%30 = icmp eq i64 %29, 0
br i1 %30, label %37, label %31
31: ; preds = %28
%32 = call i32 @strncpy(i8* %6, i8* %17, i32 10)
%33 = call i32 @atoi(i8* %6)
br label %37
34: ; preds = %13
%35 = add nsw i32 %2, -1
%36 = tail call i32 @strncpy(i8* %1, i8* %10, i32 %35)
br label %37
37: ; preds = %4, %9, %28, %34, %31
%38 = phi i32 [ %33, %31 ], [ 6162, %34 ], [ 6162, %28 ], [ 0, %9 ], [ 0, %4 ]
ret i32 %38
}