#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*/ ignore;

/* Variables and functions */
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ read_text_data(int, char *, int);
scalar_t__ strcmp(char *, char *);
scalar_t__ strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
scalar_t__ strspn(char *, char *);
char *strtok_r(char *, char *, char **);
int /*<<< orphan*/ write_data(int, char *);
void handle_request(int connection) {
  printf("Handling request...\n");
  char buffer[512];
  buffer[0] = '\0';
  read_text_data(connection, buffer, 512);
  char *saveptr = NULL;
  char *request = strtok_r(buffer, " ", &saveptr);
  char *resource = strtok_r(NULL, " ", &saveptr);
  char *version = strtok_r(NULL, " ", &saveptr);
  char mime_type[512];
  strncpy(mime_type, &resource[1], 511);
  mime_type[511] = '\0';
  if (strcmp(request, "GET")) {
    printf("Unknown request: 'GET %s %s'\n", request, version);
  } else {
    printf("Requesting '%s'\n", mime_type);
  }
  char ignore[512] = "ignore";
  while (strspn(ignore, " \n\r\t") != strlen(ignore)) {
    read_text_data(connection, ignore, sizeof(ignore));
  }
  write_data(connection, "HTTP/1.0 200 OK\r\n");
  write_data(connection, "Content-Type: ");
  write_data(connection, "pepper-application/x-chromoting-plugin");
  write_data(connection, "\r\n\r\n");
  write_data(connection, "Data\n");
}


x86 assembly (clang, -O0):
<handle_request>:
push   %rbp
mov    %rsp,%rbp
sub    $0x640,%rsp
mov    %edi,-0x4(%rbp)
lea    0xe5b(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movb   $0x0,-0x210(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x210(%rbp),%rsi
mov    $0x200,%edx
call   1040 <read_text_data@plt>
movq   $0x0,-0x218(%rbp)
lea    -0x210(%rbp),%rdi
lea    0xe8c(%rip),%rsi
lea    -0x218(%rbp),%rdx
call   1090 <strtok_r@plt>
mov    %rax,-0x220(%rbp)
xor    %eax,%eax
mov    %eax,%edi
lea    0xe6e(%rip),%rsi
lea    -0x218(%rbp),%rdx
call   1090 <strtok_r@plt>
mov    %rax,-0x228(%rbp)
xor    %eax,%eax
mov    %eax,%edi
lea    0xe50(%rip),%rsi
lea    -0x218(%rbp),%rdx
call   1090 <strtok_r@plt>
mov    %rax,-0x230(%rbp)
lea    -0x430(%rbp),%rdi
mov    -0x228(%rbp),%rsi
add    $0x1,%rsi
mov    $0x1ff,%edx
call   1030 <strncpy@plt>
movb   $0x0,-0x231(%rbp)
mov    -0x220(%rbp),%rdi
lea    0xdb5(%rip),%rsi
call   10a0 <strcmp@plt>
cmp    $0x0,%rax
je     1290 <handle_request+0x100>
mov    -0x220(%rbp),%rsi
mov    -0x230(%rbp),%rdx
lea    0xd95(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    12a5 <handle_request+0x115>
lea    -0x430(%rbp),%rsi
lea    0xd99(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    -0x630(%rbp),%rdi
xor    %esi,%esi
mov    $0x200,%edx
call   1070 <memset@plt>
movb   $0x69,-0x630(%rbp)
movb   $0x67,-0x62f(%rbp)
movb   $0x6e,-0x62e(%rbp)
movb   $0x6f,-0x62d(%rbp)
movb   $0x72,-0x62c(%rbp)
movb   $0x65,-0x62b(%rbp)
lea    -0x630(%rbp),%rdi
lea    0xd58(%rip),%rsi
call   1080 <strspn@plt>
mov    %rax,-0x638(%rbp)
lea    -0x630(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,%rcx
mov    -0x638(%rbp),%rax
cmp    %rcx,%rax
je     1334 <handle_request+0x1a4>
mov    -0x4(%rbp),%edi
lea    -0x630(%rbp),%rsi
mov    $0x200,%edx
call   1040 <read_text_data@plt>
jmp    12e2 <handle_request+0x152>
mov    -0x4(%rbp),%edi
lea    0xd0f(%rip),%rsi
call   10b0 <write_data@plt>
mov    -0x4(%rbp),%edi
lea    0xd12(%rip),%rsi
call   10b0 <write_data@plt>
mov    -0x4(%rbp),%edi
lea    0xd12(%rip),%rsi
call   10b0 <write_data@plt>
mov    -0x4(%rbp),%edi
lea    0xd2a(%rip),%rsi
call   10b0 <write_data@plt>
mov    -0x4(%rbp),%edi
lea    0xd20(%rip),%rsi
call   10b0 <write_data@plt>
add    $0x640,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<handle_request>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x610,%rsp
mov    %edi,%r12d
lea    0xed2(%rip),%rdi
call   1040 <puts@plt>
movb   $0x0,0x410(%rsp)
lea    0x410(%rsp),%r14
mov    %r12d,%edi
mov    %r14,%rsi
mov    $0x200,%edx
call   1050 <read_text_data@plt>
movq   $0x0,0x8(%rsp)
lea    0xe69(%rip),%rbp
lea    0x8(%rsp),%r15
mov    %r14,%rdi
mov    %rbp,%rsi
mov    %r15,%rdx
call   10a0 <strtok_r@plt>
mov    %rax,%r14
xor    %edi,%edi
mov    %rbp,%rsi
mov    %r15,%rdx
call   10a0 <strtok_r@plt>
mov    %rax,%rbx
xor    %edi,%edi
mov    %rbp,%rsi
mov    %r15,%rdx
call   10a0 <strtok_r@plt>
mov    %rax,%r15
add    $0x1,%rbx
lea    0x210(%rsp),%rdi
mov    %rbx,%rsi
mov    $0x1ff,%edx
call   1030 <strncpy@plt>
movb   $0x0,0x40f(%rsp)
lea    0xdb4(%rip),%rsi
mov    %r14,%rdi
call   10b0 <strcmp@plt>
test   %rax,%rax
je     126f <handle_request+0xcf>
lea    0xda4(%rip),%rdi
mov    %r14,%rsi
mov    %r15,%rdx
xor    %eax,%eax
call   1070 <printf@plt>
jmp    1285 <handle_request+0xe5>
lea    0xdac(%rip),%rdi
lea    0x210(%rsp),%rsi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0x10(%rsp),%rbx
mov    $0x200,%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1080 <memset@plt>
movl   $0x6f6e6769,0x10(%rsp)
6f
movw   $0x6572,0x14(%rsp)
lea    0xd84(%rip),%rsi
mov    %rbx,%rdi
call   1090 <strspn@plt>
mov    %rax,%rbp
mov    %rbx,%rdi
call   1060 <strlen@plt>
cmp    %rax,%rbp
je     130b <handle_request+0x16b>
lea    0x10(%rsp),%rbx
lea    0xd60(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r12d,%edi
mov    %rbx,%rsi
mov    $0x200,%edx
call   1050 <read_text_data@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1090 <strspn@plt>
mov    %rax,%rbp
mov    %rbx,%rdi
call   1060 <strlen@plt>
cmp    %rax,%rbp
jne    12e0 <handle_request+0x140>
lea    0xd26(%rip),%rsi
mov    %r12d,%edi
call   10c0 <write_data@plt>
lea    0xd29(%rip),%rsi
mov    %r12d,%edi
call   10c0 <write_data@plt>
lea    0xd29(%rip),%rsi
mov    %r12d,%edi
call   10c0 <write_data@plt>
lea    0xd41(%rip),%rsi
mov    %r12d,%edi
call   10c0 <write_data@plt>
lea    0xd37(%rip),%rsi
mov    %r12d,%edi
call   10c0 <write_data@plt>
add    $0x610,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [21 x i8] c"Handling request...\0A\00"
@.str.1 = [2 x i8] c" \00"
@.str.2 = [4 x i8] c"GET\00"
@.str.3 = [30 x i8] c"Unknown request: 'GET %s %s'\0A\00"
@.str.4 = [17 x i8] c"Requesting '%s'\0A\00"
@.str.5 = [5 x i8] c" \0A\0D\09\00"
@.str.6 = [18 x i8] c"HTTP/1.0 200 OK\0D\0A\00"
@.str.7 = [15 x i8] c"Content-Type: \00"
@.str.8 = [39 x i8] c"pepper-application/x-chromoting-plugin\00"
@.str.9 = [5 x i8] c"\0D\0A\0D\0A\00"
@.str.10 = [6 x i8] c"Data\0A\00"
define void @handle_request(i32 %0) {
%2 = alloca i32
%3 = alloca [512 x i8]
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca [512 x i8]
%9 = alloca [512 x i8]
store i32 %0, i32* %2
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
%11 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
store i8 0, i8* %11
%12 = load i32, i32* %2
%13 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%14 = call i32 @read_text_data(i32 %12, i8* %13, i32 512)
store i8* null, i8** %4
%15 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%16 = call i8* @strtok_r(i8* %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8** %4)
store i8* %16, i8** %5
%17 = call i8* @strtok_r(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8** %4)
store i8* %17, i8** %6
%18 = call i8* @strtok_r(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8** %4)
store i8* %18, i8** %7
%19 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 0
%20 = load i8*, i8** %6
%21 = getelementptr inbounds i8, i8* %20, i64 1
%22 = call i32 @strncpy(i8* %19, i8* %21, i32 511)
%23 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 511
store i8 0, i8* %23
%24 = load i8*, i8** %5
%25 = call i64 @strcmp(i8* %24, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%26 = icmp ne i64 %25, 0
br i1 %26, label %27, label %31
27: ; preds = %1
%28 = load i8*, i8** %5
%29 = load i8*, i8** %7
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0), i8* %28, i8* %29)
br label %34
31: ; preds = %1
%32 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 0
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0), i8* %32)
br label %34
34: ; preds = %31, %27
%35 = bitcast [512 x i8]* %9 to i8*
%36 = bitcast i8* %35 to [512 x i8]*
%37 = getelementptr inbounds [512 x i8], [512 x i8]* %36, i32 0, i32 0
store i8 105, i8* %37
%38 = getelementptr inbounds [512 x i8], [512 x i8]* %36, i32 0, i32 1
store i8 103, i8* %38
%39 = getelementptr inbounds [512 x i8], [512 x i8]* %36, i32 0, i32 2
store i8 110, i8* %39
%40 = getelementptr inbounds [512 x i8], [512 x i8]* %36, i32 0, i32 3
store i8 111, i8* %40
%41 = getelementptr inbounds [512 x i8], [512 x i8]* %36, i32 0, i32 4
store i8 114, i8* %41
%42 = getelementptr inbounds [512 x i8], [512 x i8]* %36, i32 0, i32 5
store i8 101, i8* %42
br label %43
43: ; preds = %49, %34
%44 = getelementptr inbounds [512 x i8], [512 x i8]* %9, i64 0, i64 0
%45 = call i64 @strspn(i8* %44, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
%46 = getelementptr inbounds [512 x i8], [512 x i8]* %9, i64 0, i64 0
%47 = call i64 @strlen(i8* %46)
%48 = icmp ne i64 %45, %47
br i1 %48, label %49, label %53
49: ; preds = %43
%50 = load i32, i32* %2
%51 = getelementptr inbounds [512 x i8], [512 x i8]* %9, i64 0, i64 0
%52 = call i32 @read_text_data(i32 %50, i8* %51, i32 512)
br label %43
53: ; preds = %43
%54 = load i32, i32* %2
%55 = call i32 @write_data(i32 %54, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.6, i64 0, i64 0))
%56 = load i32, i32* %2
%57 = call i32 @write_data(i32 %56, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.7, i64 0, i64 0))
%58 = load i32, i32* %2
%59 = call i32 @write_data(i32 %58, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.8, i64 0, i64 0))
%60 = load i32, i32* %2
%61 = call i32 @write_data(i32 %60, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.9, i64 0, i64 0))
%62 = load i32, i32* %2
%63 = call i32 @write_data(i32 %62, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.10, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str.1 = [2 x i8] c" \00"
@.str.2 = [4 x i8] c"GET\00"
@.str.3 = [30 x i8] c"Unknown request: 'GET %s %s'\0A\00"
@.str.4 = [17 x i8] c"Requesting '%s'\0A\00"
@.str.5 = [5 x i8] c" \0A\0D\09\00"
@.str.6 = [18 x i8] c"HTTP/1.0 200 OK\0D\0A\00"
@.str.7 = [15 x i8] c"Content-Type: \00"
@.str.8 = [39 x i8] c"pepper-application/x-chromoting-plugin\00"
@.str.9 = [5 x i8] c"\0D\0A\0D\0A\00"
@.str.10 = [6 x i8] c"Data\0A\00"
@str = [20 x i8] c"Handling request...\00"
define void @handle_request(i32 %0) {
%2 = alloca [512 x i8]
%3 = alloca i8*
%4 = alloca [512 x i8]
%5 = alloca [512 x i8]
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str, i64 0, i64 0))
%7 = getelementptr inbounds [512 x i8], [512 x i8]* %2, i64 0, i64 0
store i8 0, i8* %7
%8 = call i32 @read_text_data(i32 %0, i8* %7, i32 512)
%9 = bitcast i8** %3 to i8*
store i8* null, i8** %3
%10 = call i8* @strtok_r(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8** %3)
%11 = call i8* @strtok_r(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8** %3)
%12 = call i8* @strtok_r(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8** %3)
%13 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 0
%14 = getelementptr inbounds i8, i8* %11, i64 1
%15 = call i32 @strncpy(i8* %13, i8* %14, i32 511)
%16 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 511
store i8 0, i8* %16
%17 = call i64 @strcmp(i8* %10, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%18 = icmp eq i64 %17, 0
br i1 %18, label %21, label %19
19: ; preds = %1
%20 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0), i8* %10, i8* %12)
br label %23
21: ; preds = %1
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0), i8* %13)
br label %23
23: ; preds = %21, %19
%24 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
store i8 105, i8* %24
%25 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 1
store i8 103, i8* %25
%26 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 2
store i8 110, i8* %26
%27 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 3
store i8 111, i8* %27
%28 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 4
store i8 114, i8* %28
%29 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 5
store i8 101, i8* %29
%30 = call i64 @strspn(i8* %24, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
%31 = call i64 @strlen(i8* %24)
%32 = icmp eq i64 %30, %31
br i1 %32, label %38, label %33
33: ; preds = %23, %33
%34 = call i32 @read_text_data(i32 %0, i8* %24, i32 512)
%35 = call i64 @strspn(i8* %24, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
%36 = call i64 @strlen(i8* %24)
%37 = icmp eq i64 %35, %36
br i1 %37, label %38, label %33
38: ; preds = %33, %23
%39 = call i32 @write_data(i32 %0, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.6, i64 0, i64 0))
%40 = call i32 @write_data(i32 %0, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.7, i64 0, i64 0))
%41 = call i32 @write_data(i32 %0, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.8, i64 0, i64 0))
%42 = call i32 @write_data(i32 %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.9, i64 0, i64 0))
%43 = call i32 @write_data(i32 %0, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.10, i64 0, i64 0))
ret void
}