#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 */
scalar_t__ getenv(char *);
char *strchr(char *, char);
int strlen(char *);
scalar_t__ strncmp(char *, char *, int);
char *strstr(char *, char *);
char *cgi_get(char *name) {
  char *method = NULL;
  char *qstring = NULL;
  char *valu = NULL;
  char *ch = NULL;
  if (name == NULL)
    return NULL;
  method = (char *)getenv("REQUEST_METHOD");
  if (method == NULL)
    return NULL;
  if (strncmp(method, "GET", 3) == 0) {
    qstring = (char *)getenv("QUERY_STRING");
    if (qstring == NULL)
      return NULL;
    if ((ch = strstr(qstring, name)) == NULL)
      return NULL;
    valu = ch + strlen(name) + 1;
    if ((ch = strchr(valu, '&')) == NULL) {
      return valu;
    } else {
      *ch = '\0';
      return valu;
    }
  } else if (strncmp(method, "POST", 4) == 0) {
  }
  return NULL;
}


x86 assembly (clang, -O0):
<cgi_get>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1194 <cgi_get+0x44>
movq   $0x0,-0x8(%rbp)
jmp    12be <cgi_get+0x16e>
lea    0xe65(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11bc <cgi_get+0x6c>
movq   $0x0,-0x8(%rbp)
jmp    12be <cgi_get+0x16e>
mov    -0x18(%rbp),%rdi
lea    0xe48(%rip),%rsi
mov    $0x3,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%rax
jne    128d <cgi_get+0x13d>
lea    0xe31(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1203 <cgi_get+0xb3>
movq   $0x0,-0x8(%rbp)
jmp    12be <cgi_get+0x16e>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1070 <strstr@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
jne    122b <cgi_get+0xdb>
movq   $0x0,-0x8(%rbp)
jmp    12be <cgi_get+0x16e>
mov    -0x30(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x38(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    $0x26,%esi
call   1060 <strchr@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
jne    1279 <cgi_get+0x129>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    12be <cgi_get+0x16e>
mov    -0x30(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    12be <cgi_get+0x16e>
mov    -0x18(%rbp),%rdi
lea    0xd88(%rip),%rsi
mov    $0x4,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%rax
jne    12b1 <cgi_get+0x161>
jmp    12b1 <cgi_get+0x161>
jmp    12b6 <cgi_get+0x166>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cgi_get>:
push   %r14
push   %rbx
push   %rax
test   %rdi,%rdi
je     119d <cgi_get+0x4d>
mov    %rdi,%r14
lea    0xe9d(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     119d <cgi_get+0x4d>
mov    %rax,%rbx
lea    0xe98(%rip),%rsi
mov    %rax,%rdi
mov    $0x3,%edx
call   1040 <strncmp@plt>
test   %rax,%rax
je     11aa <cgi_get+0x5a>
lea    0xe90(%rip),%rsi
mov    %rbx,%rdi
mov    $0x4,%edx
call   1040 <strncmp@plt>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe62(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     119d <cgi_get+0x4d>
mov    %rax,%rdi
mov    %r14,%rsi
call   1070 <strstr@plt>
test   %rax,%rax
je     119d <cgi_get+0x4d>
mov    %rax,%rbx
mov    %r14,%rdi
call   1050 <strlen@plt>
cltq
add    %rax,%rbx
add    $0x1,%rbx
mov    %rbx,%rdi
mov    $0x26,%esi
call   1060 <strchr@plt>
test   %rax,%rax
je     119f <cgi_get+0x4f>
movb   $0x0,(%rax)
jmp    119f <cgi_get+0x4f>

LLVM IR (-O0):
@.str = [15 x i8] c"REQUEST_METHOD\00"
@.str.1 = [4 x i8] c"GET\00"
@.str.2 = [13 x i8] c"QUERY_STRING\00"
@.str.3 = [5 x i8] c"POST\00"
define i8* @cgi_get(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
store i8* %0, i8** %3
store i8* null, i8** %4
store i8* null, i8** %5
store i8* null, i8** %6
store i8* null, i8** %7
%8 = load i8*, i8** %3
%9 = icmp eq i8* %8, null
br i1 %9, label %10, label %11
10: ; preds = %1
store i8* null, i8** %2
br label %55
11: ; preds = %1
%12 = call i64 @getenv(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%13 = inttoptr i64 %12 to i8*
store i8* %13, i8** %4
%14 = load i8*, i8** %4
%15 = icmp eq i8* %14, null
br i1 %15, label %16, label %17
16: ; preds = %11
store i8* null, i8** %2
br label %55
17: ; preds = %11
%18 = load i8*, i8** %4
%19 = call i64 @strncmp(i8* %18, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 3)
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %48
21: ; preds = %17
%22 = call i64 @getenv(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%23 = inttoptr i64 %22 to i8*
store i8* %23, i8** %5
%24 = load i8*, i8** %5
%25 = icmp eq i8* %24, null
br i1 %25, label %26, label %27
26: ; preds = %21
store i8* null, i8** %2
br label %55
27: ; preds = %21
%28 = load i8*, i8** %5
%29 = load i8*, i8** %3
%30 = call i8* @strstr(i8* %28, i8* %29)
store i8* %30, i8** %7
%31 = icmp eq i8* %30, null
br i1 %31, label %32, label %33
32: ; preds = %27
store i8* null, i8** %2
br label %55
33: ; preds = %27
%34 = load i8*, i8** %7
%35 = load i8*, i8** %3
%36 = call i32 @strlen(i8* %35)
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i8, i8* %34, i64 %37
%39 = getelementptr inbounds i8, i8* %38, i64 1
store i8* %39, i8** %6
%40 = load i8*, i8** %6
%41 = call i8* @strchr(i8* %40, i8 signext 38)
store i8* %41, i8** %7
%42 = icmp eq i8* %41, null
br i1 %42, label %43, label %45
43: ; preds = %33
%44 = load i8*, i8** %6
store i8* %44, i8** %2
br label %55
45: ; preds = %33
%46 = load i8*, i8** %7
store i8 0, i8* %46
%47 = load i8*, i8** %6
store i8* %47, i8** %2
br label %55
48: ; preds = %17
%49 = load i8*, i8** %4
%50 = call i64 @strncmp(i8* %49, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 4)
%51 = icmp eq i64 %50, 0
br i1 %51, label %52, label %53
52: ; preds = %48
br label %53
53: ; preds = %52, %48
br label %54
54: ; preds = %53
store i8* null, i8** %2
br label %55
55: ; preds = %54, %45, %43, %32, %26, %16, %10
%56 = load i8*, i8** %2
ret i8* %56
}

LLVM IR (-O2):
@.str = [15 x i8] c"REQUEST_METHOD\00"
@.str.1 = [4 x i8] c"GET\00"
@.str.2 = [13 x i8] c"QUERY_STRING\00"
@.str.3 = [5 x i8] c"POST\00"
define i8* @cgi_get(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %27, label %3
3: ; preds = %1
%4 = tail call i64 @getenv(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%5 = inttoptr i64 %4 to i8*
%6 = icmp eq i64 %4, 0
br i1 %6, label %27, label %7
7: ; preds = %3
%8 = tail call i64 @strncmp(i8* %5, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 3)
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %25
10: ; preds = %7
%11 = tail call i64 @getenv(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%12 = icmp eq i64 %11, 0
br i1 %12, label %27, label %13
13: ; preds = %10
%14 = inttoptr i64 %11 to i8*
%15 = tail call i8* @strstr(i8* %14, i8* %0)
%16 = icmp eq i8* %15, null
br i1 %16, label %27, label %17
17: ; preds = %13
%18 = tail call i32 @strlen(i8* %0)
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i8, i8* %15, i64 %19
%21 = getelementptr inbounds i8, i8* %20, i64 1
%22 = tail call i8* @strchr(i8* %21, i8 signext 38)
%23 = icmp eq i8* %22, null
br i1 %23, label %27, label %24
24: ; preds = %17
store i8 0, i8* %22
br label %27
25: ; preds = %7
%26 = tail call i64 @strncmp(i8* %5, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 4)
br label %27
27: ; preds = %17, %13, %10, %3, %1, %25, %24
%28 = phi i8* [ %21, %24 ], [ null, %25 ], [ null, %1 ], [ null, %3 ], [ null, %10 ], [ null, %13 ], [ %21, %17 ]
ret i8* %28
}