#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 *);
char *malloc(int);
int /*<<< orphan*/ print_error(char *);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
char *get_GET(void) {
  char *puffer, *cgi_string, *request = getenv("REQUEST_METHOD");
  if (NULL == request)
    return NULL;
  else if (strcmp(request, "GET") == 0) {
    cgi_string = getenv("QUERY_STRING");
    if (NULL == cgi_string)
      return NULL;
    else {
      if ((puffer = malloc(sizeof(char) * strlen(cgi_string) + 1)) == NULL)
        print_error("Out of memory");
      strcpy(puffer, cgi_string);
      return puffer;
    }
  }
  return NULL;
}


x86 assembly (clang, -O0):
<get_GET>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xe91(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x20(%rbp)
xor    %eax,%eax
cmp    -0x20(%rbp),%rax
jne    1191 <get_GET+0x31>
movq   $0x0,-0x8(%rbp)
jmp    122f <get_GET+0xcf>
mov    -0x20(%rbp),%rdi
lea    0xe73(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
jne    1222 <get_GET+0xc2>
lea    0xe61(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x18(%rbp)
xor    %eax,%eax
cmp    -0x18(%rbp),%rax
jne    11d4 <get_GET+0x74>
movq   $0x0,-0x8(%rbp)
jmp    122f <get_GET+0xcf>
mov    -0x18(%rbp),%rdi
call   1060 <strlen@plt>
cltq
shl    $0x0,%rax
add    $0x1,%rax
mov    %eax,%edi
call   1080 <malloc@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    1208 <get_GET+0xa8>
lea    0xe1d(%rip),%rdi
call   1050 <print_error@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    122f <get_GET+0xcf>
jmp    1227 <get_GET+0xc7>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_GET>:
push   %r14
push   %rbx
push   %rax
lea    0xe95(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     1189 <get_GET+0x29>
lea    0xe93(%rip),%rsi
mov    %rax,%rdi
call   1070 <strcmp@plt>
test   %rax,%rax
je     1196 <get_GET+0x36>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe76(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     1189 <get_GET+0x29>
mov    %rax,%r14
mov    %rax,%rdi
call   1060 <strlen@plt>
lea    0x1(%rax),%edi
call   1080 <malloc@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    11ce <get_GET+0x6e>
lea    0xe57(%rip),%rdi
call   1050 <print_error@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <strcpy@plt>
jmp    118b <get_GET+0x2b>

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 = [14 x i8] c"Out of memory\00"
define i8* @get_GET() {
%1 = alloca i8*
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = call i8* @getenv(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
store i8* %5, i8** %4
%6 = load i8*, i8** %4
%7 = icmp eq i8* null, %6
br i1 %7, label %8, label %9
8: ; preds = %0
store i8* null, i8** %1
br label %36
9: ; preds = %0
%10 = load i8*, i8** %4
%11 = call i64 @strcmp(i8* %10, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %34
13: ; preds = %9
%14 = call i8* @getenv(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
store i8* %14, i8** %3
%15 = load i8*, i8** %3
%16 = icmp eq i8* null, %15
br i1 %16, label %17, label %18
17: ; preds = %13
store i8* null, i8** %1
br label %36
18: ; preds = %13
%19 = load i8*, i8** %3
%20 = call i32 @strlen(i8* %19)
%21 = sext i32 %20 to i64
%22 = mul i64 1, %21
%23 = add i64 %22, 1
%24 = trunc i64 %23 to i32
%25 = call i8* @malloc(i32 %24)
store i8* %25, i8** %2
%26 = icmp eq i8* %25, null
br i1 %26, label %27, label %29
27: ; preds = %18
%28 = call i32 @print_error(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
br label %29
29: ; preds = %27, %18
%30 = load i8*, i8** %2
%31 = load i8*, i8** %3
%32 = call i32 @strcpy(i8* %30, i8* %31)
%33 = load i8*, i8** %2
store i8* %33, i8** %1
br label %36
34: ; preds = %9
br label %35
35: ; preds = %34
store i8* null, i8** %1
br label %36
36: ; preds = %35, %29, %17, %8
%37 = load i8*, i8** %1
ret i8* %37
}

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 = [14 x i8] c"Out of memory\00"
define i8* @get_GET() {
%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 %18, 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 %6, label %18
6: ; preds = %3
%7 = tail call i8* @getenv(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%8 = icmp eq i8* %7, null
br i1 %8, label %18, label %9
9: ; preds = %6
%10 = tail call i32 @strlen(i8* %7)
%11 = add i32 %10, 1
%12 = tail call i8* @malloc(i32 %11)
%13 = icmp eq i8* %12, null
br i1 %13, label %14, label %16
14: ; preds = %9
%15 = tail call i32 @print_error(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
br label %16
16: ; preds = %14, %9
%17 = tail call i32 @strcpy(i8* %12, i8* %7)
br label %18
18: ; preds = %3, %6, %0, %16
%19 = phi i8* [ %12, %16 ], [ null, %0 ], [ null, %6 ], [ null, %3 ]
ret i8* %19
}