#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 */
typedef int /*<<< orphan*/ buffer;

/* Variables and functions */
int /*<<< orphan*/ ConvertStrings(char *, char **, int);
int /*<<< orphan*/ bzero(char *, int);
int /*<<< orphan*/ execvp(char *, char **);
scalar_t__ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ stdin;
scalar_t__ strncasecmp(char *, char *, int);
char *strstr(char *, char *);
void child(void) {
  int i;
  char *s, *str, buffer[1024], *strings[20];
  bzero(buffer, sizeof(buffer));
  if (fgets(buffer, sizeof(buffer), stdin) != 0) {
    if ((s = strstr(buffer, " HTTP/")) != 0)
      *s = 0;
    if (strncasecmp(buffer, "GET ", 4) == 0) {
      str = buffer + 4;
      ConvertStrings(str, strings, 20);
      printf("HTTP/1.1 200 OK\nContent-Type: text/plain\n\n");
      execvp(strings[0], strings);
    }
  }
  printf("<html><body>ERROR IN REQUEST</body></html>\n\n");
}


x86 assembly (clang, -O0):
<child>:
push   %rbp
mov    %rsp,%rbp
sub    $0x4c0,%rsp
lea    -0x420(%rbp),%rdi
mov    $0x400,%esi
call   1070 <bzero@plt>
lea    -0x420(%rbp),%rdi
mov    0x2e4e(%rip),%rax
mov    (%rax),%edx
mov    $0x400,%esi
call   1040 <fgets@plt>
cmp    $0x0,%rax
je     1242 <child+0xd2>
lea    -0x420(%rbp),%rdi
lea    0xe42(%rip),%rsi
call   1090 <strstr@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
je     11d8 <child+0x68>
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
lea    -0x420(%rbp),%rdi
lea    0xe21(%rip),%rsi
mov    $0x4,%edx
call   1060 <strncasecmp@plt>
cmp    $0x0,%rax
jne    123d <child+0xcd>
lea    -0x420(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    -0x4c0(%rbp),%rsi
mov    $0x14,%edx
call   1050 <ConvertStrings@plt>
lea    0xde7(%rip),%rdi
call   1030 <printf@plt>
mov    -0x4c0(%rbp),%rdi
lea    -0x4c0(%rbp),%rsi
call   1080 <execvp@plt>
jmp    1242 <child+0xd2>
lea    0xdee(%rip),%rdi
call   1030 <printf@plt>
add    $0x4c0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<child>:
push   %rbx
sub    $0x4a0,%rsp
lea    0xa0(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x400,%esi
call   1070 <bzero@plt>
mov    0x2e54(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
mov    $0x400,%esi
call   1040 <fgets@plt>
test   %rax,%rax
je     1212 <child+0xa2>
lea    0xe51(%rip),%rsi
lea    0xa0(%rsp),%rdi
call   1090 <strstr@plt>
test   %rax,%rax
je     11c4 <child+0x54>
movb   $0x0,(%rax)
lea    0xe3c(%rip),%rsi
lea    0xa0(%rsp),%rdi
mov    $0x4,%edx
call   1060 <strncasecmp@plt>
test   %rax,%rax
jne    1212 <child+0xa2>
lea    0xa4(%rsp),%rdi
mov    %rsp,%rbx
mov    %rbx,%rsi
mov    $0x14,%edx
call   1050 <ConvertStrings@plt>
lea    0xe37(%rip),%rdi
call   1030 <puts@plt>
mov    (%rsp),%rdi
mov    %rbx,%rsi
call   1080 <execvp@plt>
lea    0xdf3(%rip),%rdi
call   1030 <puts@plt>
add    $0x4a0,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@stdin = global i32 0
@.str = [7 x i8] c" HTTP/\00"
@.str.1 = [5 x i8] c"GET \00"
@.str.2 = [43 x i8] c"HTTP/1.1 200 OK\0AContent-Type: text/plain\0A\0A\00"
@.str.3 = [45 x i8] c"<html><body>ERROR IN REQUEST</body></html>\0A\0A\00"
define void @child() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca [1024 x i8]
%5 = alloca [20 x i8*]
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%7 = call i32 @bzero(i8* %6, i32 1024)
%8 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%9 = load i32, i32* @stdin
%10 = call i64 @fgets(i8* %8, i32 1024, i32 %9)
%11 = icmp ne i64 %10, 0
br i1 %11, label %12, label %34
12: ; preds = %0
%13 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%14 = call i8* @strstr(i8* %13, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
store i8* %14, i8** %2
%15 = icmp ne i8* %14, null
br i1 %15, label %16, label %18
16: ; preds = %12
%17 = load i8*, i8** %2
store i8 0, i8* %17
br label %18
18: ; preds = %16, %12
%19 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%20 = call i64 @strncasecmp(i8* %19, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 4)
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %33
22: ; preds = %18
%23 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%24 = getelementptr inbounds i8, i8* %23, i64 4
store i8* %24, i8** %3
%25 = load i8*, i8** %3
%26 = getelementptr inbounds [20 x i8*], [20 x i8*]* %5, i64 0, i64 0
%27 = call i32 @ConvertStrings(i8* %25, i8** %26, i32 20)
%28 = call i32 @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.2, i64 0, i64 0))
%29 = getelementptr inbounds [20 x i8*], [20 x i8*]* %5, i64 0, i64 0
%30 = load i8*, i8** %29
%31 = getelementptr inbounds [20 x i8*], [20 x i8*]* %5, i64 0, i64 0
%32 = call i32 @execvp(i8* %30, i8** %31)
br label %33
33: ; preds = %22, %18
br label %34
34: ; preds = %33, %0
%35 = call i32 @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.3, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@stdin = global i32 0
@.str = [7 x i8] c" HTTP/\00"
@.str.1 = [5 x i8] c"GET \00"
@str = [44 x i8] c"<html><body>ERROR IN REQUEST</body></html>\0A\00"
@str.4 = [42 x i8] c"HTTP/1.1 200 OK\0AContent-Type: text/plain\0A\00"
define void @child() {
%1 = alloca [1024 x i8]
%2 = alloca [20 x i8*]
%3 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 0
%4 = bitcast [20 x i8*]* %2 to i8*
%5 = call i32 @bzero(i8* %3, i32 1024)
%6 = load i32, i32* @stdin
%7 = call i64 @fgets(i8* %3, i32 1024, i32 %6)
%8 = icmp eq i64 %7, 0
br i1 %8, label %23, label %9
9: ; preds = %0
%10 = call i8* @strstr(i8* %3, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%11 = icmp eq i8* %10, null
br i1 %11, label %13, label %12
12: ; preds = %9
store i8 0, i8* %10
br label %13
13: ; preds = %12, %9
%14 = call i64 @strncasecmp(i8* %3, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 4)
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %23
16: ; preds = %13
%17 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 4
%18 = getelementptr inbounds [20 x i8*], [20 x i8*]* %2, i64 0, i64 0
%19 = call i32 @ConvertStrings(i8* %17, i8** %18, i32 20)
%20 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @str.4, i64 0, i64 0))
%21 = load i8*, i8** %18
%22 = call i32 @execvp(i8* %21, i8** %18)
br label %23
23: ; preds = %13, %16, %0
%24 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @str, i64 0, i64 0))
ret void
}