#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 *index(char *, char);
int /*<<< orphan*/ sprintf(char *, char *, char *);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
int /*<<< orphan*/ strstr(char *, char *);
int requestParseURI(char *uri, char *filename, char *cgiargs) {
  char *ptr;
  if (!strstr(uri, "cgi")) {
    strcpy(cgiargs, "");
    sprintf(filename, ".%s", uri);
    if (uri[strlen(uri) - 1] == '/') {
      strcat(filename, "home.html");
    }
    return 1;
  } else {
    ptr = index(uri, '?');
    if (ptr) {
      strcpy(cgiargs, ptr + 1);
      *ptr = '\0';
    } else {
      strcpy(cgiargs, "");
    }
    sprintf(filename, ".%s", uri);
    return 0;
  }
}


x86 assembly (clang, -O0):
<requestParseURI>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe81(%rip),%rsi
call   1080 <strstr@plt>
cmp    $0x0,%eax
jne    11f7 <requestParseURI+0x97>
mov    -0x20(%rbp),%rdi
lea    0xe6b(%rip),%rsi
call   1030 <strcpy@plt>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xe58(%rip),%rsi
call   1070 <sprintf@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2f,%eax
jne    11eb <requestParseURI+0x8b>
mov    -0x18(%rbp),%rdi
lea    0xe22(%rip),%rsi
call   1060 <strcat@plt>
movl   $0x1,-0x4(%rbp)
jmp    125c <requestParseURI+0xfc>
mov    -0x10(%rbp),%rdi
mov    $0x3f,%esi
call   1050 <index@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     1231 <requestParseURI+0xd1>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
add    $0x1,%rsi
call   1030 <strcpy@plt>
mov    -0x28(%rbp),%rax
movb   $0x0,(%rax)
jmp    1241 <requestParseURI+0xe1>
mov    -0x20(%rbp),%rdi
lea    0xdc7(%rip),%rsi
call   1030 <strcpy@plt>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xdb4(%rip),%rsi
call   1070 <sprintf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<requestParseURI>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r15
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0xe89(%rip),%rsi
call   1080 <strstr@plt>
test   %eax,%eax
je     11aa <requestParseURI+0x4a>
mov    %rbx,%rdi
mov    $0x3f,%esi
call   1050 <index@plt>
test   %rax,%rax
je     11f2 <requestParseURI+0x92>
mov    %rax,%rbp
mov    %rax,%rsi
add    $0x1,%rsi
mov    %r15,%rdi
call   1030 <strcpy@plt>
movb   $0x0,0x0(%rbp)
jmp    1201 <requestParseURI+0xa1>
lea    0xe52(%rip),%rsi
mov    %r15,%rdi
call   1030 <strcpy@plt>
lea    0xe44(%rip),%rsi
mov    %r14,%rdi
mov    %rbx,%rdx
call   1070 <sprintf@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
cltq
mov    $0x1,%ebp
cmpb   $0x2f,-0x1(%rax,%rbx,1)
jne    1215 <requestParseURI+0xb5>
lea    0xe20(%rip),%rsi
mov    %r14,%rdi
call   1060 <strcat@plt>
jmp    1215 <requestParseURI+0xb5>
lea    0xe0a(%rip),%rsi
mov    %r15,%rdi
call   1030 <strcpy@plt>
lea    0xdfc(%rip),%rsi
mov    %r14,%rdi
mov    %rbx,%rdx
call   1070 <sprintf@plt>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"cgi\00"
@.str.1 = [1 x i8] zeroinitializer
@.str.2 = [4 x i8] c".%s\00"
@.str.3 = [10 x i8] c"home.html\00"
define i32 @requestParseURI(i8* %0, i8* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
%9 = load i8*, i8** %5
%10 = call i32 @strstr(i8* %9, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%11 = icmp ne i32 %10, 0
br i1 %11, label %31, label %12
12: ; preds = %3
%13 = load i8*, i8** %7
%14 = call i32 @strcpy(i8* %13, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0))
%15 = load i8*, i8** %6
%16 = load i8*, i8** %5
%17 = call i32 @sprintf(i8* %15, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %16)
%18 = load i8*, i8** %5
%19 = load i8*, i8** %5
%20 = call i32 @strlen(i8* %19)
%21 = sub nsw i32 %20, 1
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8, i8* %18, i64 %22
%24 = load i8, i8* %23
%25 = sext i8 %24 to i32
%26 = icmp eq i32 %25, 47
br i1 %26, label %27, label %30
27: ; preds = %12
%28 = load i8*, i8** %6
%29 = call i32 @strcat(i8* %28, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
br label %30
30: ; preds = %27, %12
store i32 1, i32* %4
br label %49
31: ; preds = %3
%32 = load i8*, i8** %5
%33 = call i8* @index(i8* %32, i8 signext 63)
store i8* %33, i8** %8
%34 = load i8*, i8** %8
%35 = icmp ne i8* %34, null
br i1 %35, label %36, label %42
36: ; preds = %31
%37 = load i8*, i8** %7
%38 = load i8*, i8** %8
%39 = getelementptr inbounds i8, i8* %38, i64 1
%40 = call i32 @strcpy(i8* %37, i8* %39)
%41 = load i8*, i8** %8
store i8 0, i8* %41
br label %45
42: ; preds = %31
%43 = load i8*, i8** %7
%44 = call i32 @strcpy(i8* %43, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0))
br label %45
45: ; preds = %42, %36
%46 = load i8*, i8** %6
%47 = load i8*, i8** %5
%48 = call i32 @sprintf(i8* %46, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %47)
store i32 0, i32* %4
br label %49
49: ; preds = %45, %30
%50 = load i32, i32* %4
ret i32 %50
}

LLVM IR (-O2):
@.str = [4 x i8] c"cgi\00"
@.str.1 = [1 x i8] zeroinitializer
@.str.2 = [4 x i8] c".%s\00"
@.str.3 = [10 x i8] c"home.html\00"
define i32 @requestParseURI(i8* %0, i8* %1, i8* %2) {
%4 = tail call i32 @strstr(i8* %0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i32 %4, 0
br i1 %5, label %6, label %17
6: ; preds = %3
%7 = tail call i32 @strcpy(i8* %2, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0))
%8 = tail call i32 @sprintf(i8* dereferenceable(1) %1, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %0)
%9 = tail call i32 @strlen(i8* %0)
%10 = add nsw i32 %9, -1
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds i8, i8* %0, i64 %11
%13 = load i8, i8* %12
%14 = icmp eq i8 %13, 47
br i1 %14, label %15, label %27
15: ; preds = %6
%16 = tail call i32 @strcat(i8* %1, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
br label %27
17: ; preds = %3
%18 = tail call i8* @index(i8* %0, i8 signext 63)
%19 = icmp eq i8* %18, null
br i1 %19, label %23, label %20
20: ; preds = %17
%21 = getelementptr inbounds i8, i8* %18, i64 1
%22 = tail call i32 @strcpy(i8* %2, i8* %21)
store i8 0, i8* %18
br label %25
23: ; preds = %17
%24 = tail call i32 @strcpy(i8* %2, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0))
br label %25
25: ; preds = %23, %20
%26 = tail call i32 @sprintf(i8* dereferenceable(1) %1, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %0)
br label %27
27: ; preds = %6, %15, %25
%28 = phi i32 [ 0, %25 ], [ 1, %15 ], [ 1, %6 ]
ret i32 %28
}