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


x86 assembly (clang, -O0):
<parse_uri>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe91(%rip),%rsi
call   1070 <strstr@plt>
cmp    $0x0,%eax
jne    11e0 <parse_uri+0x90>
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
je     11e0 <parse_uri+0x90>
mov    -0x20(%rbp),%rdi
lea    0xe60(%rip),%rsi
call   1030 <strcpy@plt>
mov    -0x18(%rbp),%rdi
lea    0xe46(%rip),%rsi
call   1030 <strcpy@plt>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1060 <strcat@plt>
movl   $0x1,-0x4(%rbp)
jmp    1288 <parse_uri+0x138>
mov    -0x10(%rbp),%rdi
mov    $0x3f,%esi
call   1050 <index@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     121a <parse_uri+0xca>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
add    $0x1,%rsi
call   1030 <strcpy@plt>
mov    -0x28(%rbp),%rax
movb   $0x0,(%rax)
jmp    122a <parse_uri+0xda>
mov    -0x20(%rbp),%rdi
lea    0xded(%rip),%rsi
call   1030 <strcpy@plt>
mov    -0x18(%rbp),%rdi
lea    0xdde(%rip),%rsi
call   1030 <strcpy@plt>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1060 <strcat@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x38(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2f,%eax
jne    1281 <parse_uri+0x131>
mov    -0x18(%rbp),%rdi
lea    0xd9d(%rip),%rsi
call   1060 <strcat@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_uri>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r15
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0xe99(%rip),%rsi
call   1070 <strstr@plt>
test   %eax,%eax
jne    1181 <parse_uri+0x31>
mov    %rbx,%rdi
call   1040 <strlen@plt>
cltq
cmpb   $0x2f,-0x1(%rax,%rbx,1)
jne    11f8 <parse_uri+0xa8>
mov    %rbx,%rdi
mov    $0x3f,%esi
call   1050 <index@plt>
test   %rax,%rax
je     11ab <parse_uri+0x5b>
mov    %rax,%rbp
mov    %rax,%rsi
add    $0x1,%rsi
mov    %r15,%rdi
call   1030 <strcpy@plt>
movb   $0x0,0x0(%rbp)
jmp    11ba <parse_uri+0x6a>
lea    0xe60(%rip),%rsi
mov    %r15,%rdi
call   1030 <strcpy@plt>
lea    0xe52(%rip),%rsi
mov    %r14,%rdi
call   1030 <strcpy@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1060 <strcat@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
cltq
xor    %ebp,%ebp
cmpb   $0x2f,-0x1(%rax,%rbx,1)
jne    1226 <parse_uri+0xd6>
lea    0xe2b(%rip),%rsi
mov    %r14,%rdi
call   1060 <strcat@plt>
jmp    1226 <parse_uri+0xd6>
lea    0xe13(%rip),%rsi
mov    %r15,%rdi
call   1030 <strcpy@plt>
lea    0xdfa(%rip),%rsi
mov    %r14,%rdi
call   1030 <strcpy@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1060 <strcat@plt>
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [8 x i8] c"cgi-bin\00"
@.str.1 = [1 x i8] zeroinitializer
@.str.2 = [11 x i8] c"./www/html\00"
@.str.3 = [6 x i8] c"./www\00"
@.str.4 = [21 x i8] c"cgi-bin/LibServer.py\00"
define i32 @parse_uri(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 ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%11 = icmp ne i32 %10, 0
br i1 %11, label %30, label %12
12: ; preds = %3
%13 = load i8*, i8** %5
%14 = load i8*, i8** %5
%15 = call i32 @strlen(i8* %14)
%16 = sub nsw i32 %15, 1
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i8, i8* %13, i64 %17
%19 = load i8, i8* %18
%20 = sext i8 %19 to i32
%21 = icmp ne i32 %20, 47
br i1 %21, label %22, label %30
22: ; preds = %12
%23 = load i8*, i8** %7
%24 = call i32 @strcpy(i8* %23, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0))
%25 = load i8*, i8** %6
%26 = call i32 @strcpy(i8* %25, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
%27 = load i8*, i8** %6
%28 = load i8*, i8** %5
%29 = call i32 @strcat(i8* %27, i8* %28)
store i32 1, i32* %4
br label %63
30: ; preds = %12, %3
%31 = load i8*, i8** %5
%32 = call i8* @index(i8* %31, i8 signext 63)
store i8* %32, i8** %8
%33 = load i8*, i8** %8
%34 = icmp ne i8* %33, null
br i1 %34, label %35, label %41
35: ; preds = %30
%36 = load i8*, i8** %7
%37 = load i8*, i8** %8
%38 = getelementptr inbounds i8, i8* %37, i64 1
%39 = call i32 @strcpy(i8* %36, i8* %38)
%40 = load i8*, i8** %8
store i8 0, i8* %40
br label %44
41: ; preds = %30
%42 = load i8*, i8** %7
%43 = call i32 @strcpy(i8* %42, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0))
br label %44
44: ; preds = %41, %35
%45 = load i8*, i8** %6
%46 = call i32 @strcpy(i8* %45, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%47 = load i8*, i8** %6
%48 = load i8*, i8** %5
%49 = call i32 @strcat(i8* %47, i8* %48)
%50 = load i8*, i8** %5
%51 = load i8*, i8** %5
%52 = call i32 @strlen(i8* %51)
%53 = sub nsw i32 %52, 1
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds i8, i8* %50, i64 %54
%56 = load i8, i8* %55
%57 = sext i8 %56 to i32
%58 = icmp eq i32 %57, 47
br i1 %58, label %59, label %62
59: ; preds = %44
%60 = load i8*, i8** %6
%61 = call i32 @strcat(i8* %60, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0))
br label %62
62: ; preds = %59, %44
store i32 0, i32* %4
br label %63
63: ; preds = %62, %22
%64 = load i32, i32* %4
ret i32 %64
}

LLVM IR (-O2):
@.str = [8 x i8] c"cgi-bin\00"
@.str.1 = [1 x i8] zeroinitializer
@.str.2 = [11 x i8] c"./www/html\00"
@.str.3 = [6 x i8] c"./www\00"
@.str.4 = [21 x i8] c"cgi-bin/LibServer.py\00"
define i32 @parse_uri(i8* %0, i8* %1, i8* %2) {
%4 = tail call i32 @strstr(i8* %0, i8* getelementptr inbounds ([8 x i8], [8 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 @strlen(i8* %0)
%8 = add nsw i32 %7, -1
%9 = sext i32 %8 to i64
%10 = getelementptr inbounds i8, i8* %0, i64 %9
%11 = load i8, i8* %10
%12 = icmp eq i8 %11, 47
br i1 %12, label %17, label %13
13: ; preds = %6
%14 = tail call i32 @strcpy(i8* %2, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0))
%15 = tail call i32 @strcpy(i8* %1, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
%16 = tail call i32 @strcat(i8* %1, i8* %0)
br label %36
17: ; preds = %6, %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 @strcpy(i8* %1, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%27 = tail call i32 @strcat(i8* %1, i8* %0)
%28 = tail call i32 @strlen(i8* %0)
%29 = add nsw i32 %28, -1
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i8, i8* %0, i64 %30
%32 = load i8, i8* %31
%33 = icmp eq i8 %32, 47
br i1 %33, label %34, label %36
34: ; preds = %25
%35 = tail call i32 @strcat(i8* %1, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0))
br label %36
36: ; preds = %25, %34, %13
%37 = phi i32 [ 1, %13 ], [ 0, %34 ], [ 0, %25 ]
ret i32 %37
}