#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 /*<<< orphan*/ error(int, char *);
char *getenv(char *);
int /*<<< orphan*/ strcat(char *, char *);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int /*<<< orphan*/ unescape_url(char *);
void getCmd(char *cmdText) {
  if (strcmp(getenv("REQUEST_METHOD"), "GET"))
    error(400, "Invalid REQUEST_METHOD");
  char *qs;
  qs = getenv("QUERY_STRING");
  if (qs == NULL)
    error(400, "Missing QUERY_STRING");
  int i;
  for (i = 0; qs[i]; i++) {
    if (qs[i] == '+')
      qs[i] = ' ';
    else if (qs[i] == '&')
      qs[i] = '\t';
  }
  unescape_url(qs);
  strcpy(cmdText, qs);
  strcat(cmdText, "\r");
}


x86 assembly (clang, -O0):
<getCmd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
lea    0xe99(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rdi
lea    0xe7e(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
je     11a2 <getCmd+0x42>
mov    $0x190,%edi
lea    0xe67(%rip),%rsi
call   1070 <error@plt>
lea    0xe7a(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11ce <getCmd+0x6e>
mov    $0x190,%edi
lea    0xe52(%rip),%rsi
call   1070 <error@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
cmpb   $0x0,(%rax,%rcx,1)
je     1246 <getCmd+0xe6>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2b,%eax
jne    120d <getCmd+0xad>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movb   $0x20,(%rax,%rcx,1)
jmp    1233 <getCmd+0xd3>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x26,%eax
jne    122e <getCmd+0xce>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movb   $0x9,(%rax,%rcx,1)
jmp    1233 <getCmd+0xd3>
jmp    1238 <getCmd+0xd8>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11d5 <getCmd+0x75>
mov    -0x10(%rbp),%rdi
call   1060 <unescape_url@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x8(%rbp),%rdi
lea    0xdc9(%rip),%rsi
call   1080 <strcat@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getCmd>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
lea    0xe9e(%rip),%rdi
call   1030 <getenv@plt>
lea    0xe86(%rip),%rsi
mov    %rax,%rdi
call   1050 <strcmp@plt>
test   %rax,%rax
je     1198 <getCmd+0x38>
lea    0xe76(%rip),%rsi
mov    $0x190,%edi
call   1070 <error@plt>
lea    0xe84(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    11bd <getCmd+0x5d>
lea    0xe68(%rip),%rsi
mov    $0x190,%edi
call   1070 <error@plt>
mov    %rbx,%rax
jmp    11d8 <getCmd+0x78>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    $0x9,%dl
mov    %dl,(%rax)
add    $0x1,%rax
movzbl (%rax),%ecx
cmp    $0x26,%cl
je     11d0 <getCmd+0x70>
mov    $0x20,%dl
cmp    $0x2b,%cl
je     11d2 <getCmd+0x72>
test   %cl,%cl
jne    11d4 <getCmd+0x74>
mov    %rbx,%rdi
call   1060 <unescape_url@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1040 <strcpy@plt>
lea    0xe2b(%rip),%rsi
mov    %r14,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1080 <strcat@plt>

LLVM IR (-O0):
@.str = [15 x i8] c"REQUEST_METHOD\00"
@.str.1 = [4 x i8] c"GET\00"
@.str.2 = [23 x i8] c"Invalid REQUEST_METHOD\00"
@.str.3 = [13 x i8] c"QUERY_STRING\00"
@.str.4 = [21 x i8] c"Missing QUERY_STRING\00"
@.str.5 = [2 x i8] c"\0D\00"
define void @getCmd(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
store i8* %0, i8** %2
%5 = call i8* @getenv(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%6 = call i64 @strcmp(i8* %5, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%7 = icmp ne i64 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %1
%9 = call i32 @error(i32 400, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
br label %10
10: ; preds = %8, %1
%11 = call i8* @getenv(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
store i8* %11, i8** %3
%12 = load i8*, i8** %3
%13 = icmp eq i8* %12, null
br i1 %13, label %14, label %16
14: ; preds = %10
%15 = call i32 @error(i32 400, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0))
br label %16
16: ; preds = %14, %10
store i32 0, i32* %4
br label %17
17: ; preds = %52, %16
%18 = load i8*, i8** %3
%19 = load i32, i32* %4
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i8, i8* %18, i64 %20
%22 = load i8, i8* %21
%23 = icmp ne i8 %22, 0
br i1 %23, label %24, label %55
24: ; preds = %17
%25 = load i8*, i8** %3
%26 = load i32, i32* %4
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %25, i64 %27
%29 = load i8, i8* %28
%30 = sext i8 %29 to i32
%31 = icmp eq i32 %30, 43
br i1 %31, label %32, label %37
32: ; preds = %24
%33 = load i8*, i8** %3
%34 = load i32, i32* %4
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i8, i8* %33, i64 %35
store i8 32, i8* %36
br label %51
37: ; preds = %24
%38 = load i8*, i8** %3
%39 = load i32, i32* %4
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i8, i8* %38, i64 %40
%42 = load i8, i8* %41
%43 = sext i8 %42 to i32
%44 = icmp eq i32 %43, 38
br i1 %44, label %45, label %50
45: ; preds = %37
%46 = load i8*, i8** %3
%47 = load i32, i32* %4
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds i8, i8* %46, i64 %48
store i8 9, i8* %49
br label %50
50: ; preds = %45, %37
br label %51
51: ; preds = %50, %32
br label %52
52: ; preds = %51
%53 = load i32, i32* %4
%54 = add nsw i32 %53, 1
store i32 %54, i32* %4
br label %17
55: ; preds = %17
%56 = load i8*, i8** %3
%57 = call i32 @unescape_url(i8* %56)
%58 = load i8*, i8** %2
%59 = load i8*, i8** %3
%60 = call i32 @strcpy(i8* %58, i8* %59)
%61 = load i8*, i8** %2
%62 = call i32 @strcat(i8* %61, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [15 x i8] c"REQUEST_METHOD\00"
@.str.1 = [4 x i8] c"GET\00"
@.str.2 = [23 x i8] c"Invalid REQUEST_METHOD\00"
@.str.3 = [13 x i8] c"QUERY_STRING\00"
@.str.4 = [21 x i8] c"Missing QUERY_STRING\00"
@.str.5 = [2 x i8] c"\0D\00"
define void @getCmd(i8* %0) {
%2 = tail call i8* @getenv(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%3 = tail call i64 @strcmp(i8* %2, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%4 = icmp eq i64 %3, 0
br i1 %4, label %7, label %5
5: ; preds = %1
%6 = tail call i32 @error(i32 400, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
br label %7
7: ; preds = %5, %1
%8 = tail call i8* @getenv(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
%9 = icmp eq i8* %8, null
br i1 %9, label %10, label %12
10: ; preds = %7
%11 = tail call i32 @error(i32 400, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0))
br label %12
12: ; preds = %10, %7
br label %13
13: ; preds = %12, %20
%14 = phi i64 [ %21, %20 ], [ 0, %12 ]
%15 = getelementptr inbounds i8, i8* %8, i64 %14
%16 = load i8, i8* %15
switch i8 %16, label %20 [
i8 0, label %22
i8 43, label %18
i8 38, label %17
]
17: ; preds = %13
br label %18
18: ; preds = %13, %17
%19 = phi i8 [ 9, %17 ], [ 32, %13 ]
store i8 %19, i8* %15
br label %20
20: ; preds = %18, %13
%21 = add nuw i64 %14, 1
br label %13
22: ; preds = %13
%23 = tail call i32 @unescape_url(i8* %8)
%24 = tail call i32 @strcpy(i8* %0, i8* %8)
%25 = tail call i32 @strcat(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
ret void
}