#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 */
char *getenv(char *);
scalar_t__ strcmp(char const *, char *);
int cgi_method(void) {
  const char *method;
  int rc = 0;
  method = getenv("REQUEST_METHOD");
  if (method) {
    if (strcmp(method, "GET") == 0)
      rc = 2;
    else if (strcmp(method, "POST") == 0)
      rc = 3;
    else if (strcmp(method, "PUT") == 0)
      rc = 4;
    else if (strcmp(method, "DELETE") == 0)
      rc = 5;
  }
  return (rc);
}


x86 assembly (clang, -O0):
<cgi_method>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0xc(%rbp)
lea    0xeca(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     11f1 <cgi_method+0xd1>
mov    -0x8(%rbp),%rdi
lea    0xeba(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    1170 <cgi_method+0x50>
movl   $0x2,-0xc(%rbp)
jmp    11ec <cgi_method+0xcc>
mov    -0x8(%rbp),%rdi
lea    0xe98(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    1196 <cgi_method+0x76>
movl   $0x3,-0xc(%rbp)
jmp    11e7 <cgi_method+0xc7>
mov    -0x8(%rbp),%rdi
lea    0xe77(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    11bc <cgi_method+0x9c>
movl   $0x4,-0xc(%rbp)
jmp    11e2 <cgi_method+0xc2>
mov    -0x8(%rbp),%rdi
lea    0xe55(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    11dd <cgi_method+0xbd>
movl   $0x5,-0xc(%rbp)
jmp    11e2 <cgi_method+0xc2>
jmp    11e7 <cgi_method+0xc7>
jmp    11ec <cgi_method+0xcc>
jmp    11f1 <cgi_method+0xd1>
mov    -0xc(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cgi_method>:
push   %rbx
lea    0xed8(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     118d <cgi_method+0x6d>
mov    %rax,%rbx
lea    0xed3(%rip),%rsi
mov    %rax,%rdi
call   1040 <strcmp@plt>
test   %rax,%rax
je     1191 <cgi_method+0x71>
lea    0xec3(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strcmp@plt>
test   %rax,%rax
je     1198 <cgi_method+0x78>
lea    0xeb4(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strcmp@plt>
test   %rax,%rax
je     119f <cgi_method+0x7f>
lea    0xea4(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strcmp@plt>
xor    %ecx,%ecx
test   %rax,%rax
sete   %cl
lea    (%rcx,%rcx,4),%eax
pop    %rbx
ret
xor    %eax,%eax
pop    %rbx
ret
mov    $0x2,%eax
pop    %rbx
ret
mov    $0x3,%eax
pop    %rbx
ret
mov    $0x4,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [15 x i8] c"REQUEST_METHOD\00"
@.str.1 = [4 x i8] c"GET\00"
@.str.2 = [5 x i8] c"POST\00"
@.str.3 = [4 x i8] c"PUT\00"
@.str.4 = [7 x i8] c"DELETE\00"
define i32 @cgi_method() {
%1 = alloca i8*
%2 = alloca i32
store i32 0, i32* %2
%3 = call i8* @getenv(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
store i8* %3, i8** %1
%4 = load i8*, i8** %1
%5 = icmp ne i8* %4, null
br i1 %5, label %6, label %30
6: ; preds = %0
%7 = load i8*, i8** %1
%8 = call i64 @strcmp(i8* %7, 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 %11
10: ; preds = %6
store i32 2, i32* %2
br label %29
11: ; preds = %6
%12 = load i8*, i8** %1
%13 = call i64 @strcmp(i8* %12, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %16
15: ; preds = %11
store i32 3, i32* %2
br label %28
16: ; preds = %11
%17 = load i8*, i8** %1
%18 = call i64 @strcmp(i8* %17, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %21
20: ; preds = %16
store i32 4, i32* %2
br label %27
21: ; preds = %16
%22 = load i8*, i8** %1
%23 = call i64 @strcmp(i8* %22, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %26
25: ; preds = %21
store i32 5, i32* %2
br label %26
26: ; preds = %25, %21
br label %27
27: ; preds = %26, %20
br label %28
28: ; preds = %27, %15
br label %29
29: ; preds = %28, %10
br label %30
30: ; preds = %29, %0
%31 = load i32, i32* %2
ret i32 %31
}

LLVM IR (-O2):
@.str = [15 x i8] c"REQUEST_METHOD\00"
@.str.1 = [4 x i8] c"GET\00"
@.str.2 = [5 x i8] c"POST\00"
@.str.3 = [4 x i8] c"PUT\00"
@.str.4 = [7 x i8] c"DELETE\00"
define i32 @cgi_method() {
%1 = tail call i8* @getenv(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%2 = icmp eq i8* %1, null
br i1 %2, label %16, label %3
3: ; preds = %0
%4 = tail call i64 @strcmp(i8* %1, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%5 = icmp eq i64 %4, 0
br i1 %5, label %16, label %6
6: ; preds = %3
%7 = tail call i64 @strcmp(i8* %1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%8 = icmp eq i64 %7, 0
br i1 %8, label %16, label %9
9: ; preds = %6
%10 = tail call i64 @strcmp(i8* %1, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%11 = icmp eq i64 %10, 0
br i1 %11, label %16, label %12
12: ; preds = %9
%13 = tail call i64 @strcmp(i8* %1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
%14 = icmp eq i64 %13, 0
%15 = select i1 %14, i32 5, i32 0
br label %16
16: ; preds = %12, %9, %6, %3, %0
%17 = phi i32 [ 0, %0 ], [ 2, %3 ], [ 3, %6 ], [ 4, %9 ], [ %15, %12 ]
ret i32 %17
}