#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 IPPROTO_TCP;
int IPPROTO_UDP;
scalar_t__ strcmp(char *, char *);
int getProtocol(int *ptr, char *tok) {
  int rc = 0;
  if (ptr) {
    if (strcmp(tok, "tcp") == 0)
      *ptr = IPPROTO_TCP;
    else if (strcmp(tok, "udp") == 0)
      *ptr = IPPROTO_UDP;
    else
      rc = 9;
  } else
    rc = 9;
  return rc;
}


x86 assembly (clang, -O0):
<getProtocol>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     119f <getProtocol+0x8f>
mov    -0x10(%rbp),%rdi
lea    0xec3(%rip),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%rax
jne    1160 <getProtocol+0x50>
mov    0x2e95(%rip),%rax
mov    (%rax),%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
jmp    119a <getProtocol+0x8a>
mov    -0x10(%rbp),%rdi
lea    0xe99(%rip),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%rax
jne    118e <getProtocol+0x7e>
mov    0x2e4f(%rip),%rax
mov    (%rax),%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
jmp    1195 <getProtocol+0x85>
movl   $0x9,-0x14(%rbp)
jmp    119a <getProtocol+0x8a>
jmp    11a6 <getProtocol+0x96>
movl   $0x9,-0x14(%rbp)
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getProtocol>:
push   %rbp
push   %r14
push   %rbx
mov    $0x9,%ebp
test   %rdi,%rdi
je     1163 <getProtocol+0x53>
mov    %rsi,%rbx
mov    %rdi,%r14
lea    0xed5(%rip),%rsi
mov    %rbx,%rdi
call   1030 <strcmp@plt>
test   %rax,%rax
je     1155 <getProtocol+0x45>
lea    0xec5(%rip),%rsi
mov    %rbx,%rdi
call   1030 <strcmp@plt>
test   %rax,%rax
jne    1163 <getProtocol+0x53>
mov    0x2e7d(%rip),%rax
jmp    115c <getProtocol+0x4c>
mov    0x2e8c(%rip),%rax
mov    (%rax),%eax
mov    %eax,(%r14)
xor    %ebp,%ebp
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [4 x i8] c"tcp\00"
@IPPROTO_TCP = global i32 0
@.str.1 = [4 x i8] c"udp\00"
@IPPROTO_UDP = global i32 0
define i32 @getProtocol(i32* writeonly %0, i8* %1) {
%3 = icmp eq i32* %0, null
br i1 %3, label %13, label %4
4: ; preds = %2
%5 = tail call i64 @strcmp(i8* %1, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i64 %5, 0
br i1 %6, label %10, label %7
7: ; preds = %4
%8 = tail call i64 @strcmp(i8* %1, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %13
10: ; preds = %7, %4
%11 = phi i32* [ @IPPROTO_TCP, %4 ], [ @IPPROTO_UDP, %7 ]
%12 = load i32, i32* %11
store i32 %12, i32* %0
br label %13
13: ; preds = %10, %2, %7
%14 = phi i32 [ 9, %7 ], [ 9, %2 ], [ 0, %10 ]
ret i32 %14
}