#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*/ strcat(char *, char *);
char *strchr(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")) {
    strcpy(cgiargs, "");
    strcpy(filename, ".");
    strcat(filename, uri);
    if (uri[strlen(uri) - 1] == '/')
      strcat(filename, "home.html");
    return 1;
  } else {
    ptr = strchr(uri, '?');
    if (ptr) {
      strcpy(cgiargs, ptr + 1);
      *ptr = '\0';
    } else {
      strcpy(cgiargs, "");
    }
    strcpy(filename, ".");
    strcat(filename, uri);
    return 0;
  }
}


x86 assembly (clang, -O0):
<parse_uri>:
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    0xe91(%rip),%rsi
call   1070 <strstr@plt>
cmp    $0x0,%eax
jne    11f0 <parse_uri+0xa0>
mov    -0x20(%rbp),%rdi
lea    0xe81(%rip),%rsi
call   1030 <strcpy@plt>
mov    -0x18(%rbp),%rdi
lea    0xe70(%rip),%rsi
call   1030 <strcpy@plt>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1060 <strcat@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    11e4 <parse_uri+0x94>
mov    -0x18(%rbp),%rdi
lea    0xe2b(%rip),%rsi
call   1060 <strcat@plt>
movl   $0x1,-0x4(%rbp)
jmp    125e <parse_uri+0x10e>
mov    -0x10(%rbp),%rdi
mov    $0x3f,%esi
call   1050 <strchr@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     122a <parse_uri+0xda>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
add    $0x1,%rsi
call   1030 <strcpy@plt>
mov    -0x28(%rbp),%rax
movb   $0x0,(%rax)
jmp    123a <parse_uri+0xea>
mov    -0x20(%rbp),%rdi
lea    0xdd4(%rip),%rsi
call   1030 <strcpy@plt>
mov    -0x18(%rbp),%rdi
lea    0xdc3(%rip),%rsi
call   1030 <strcpy@plt>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1060 <strcat@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%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
je     119a <parse_uri+0x4a>
mov    %rbx,%rdi
mov    $0x3f,%esi
call   1050 <strchr@plt>
test   %rax,%rax
je     11e2 <parse_uri+0x92>
mov    %rax,%rbp
mov    %rax,%rsi
add    $0x1,%rsi
mov    %r15,%rdi
call   1030 <strcpy@plt>
movb   $0x0,0x0(%rbp)
jmp    11f1 <parse_uri+0xa1>
lea    0xe68(%rip),%rsi
mov    %r15,%rdi
call   1030 <strcpy@plt>
lea    0xe58(%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
mov    $0x1,%ebp
cmpb   $0x2f,-0x1(%rax,%rbx,1)
jne    120d <parse_uri+0xbd>
lea    0xe2a(%rip),%rbx
jmp    1202 <parse_uri+0xb2>
lea    0xe20(%rip),%rsi
mov    %r15,%rdi
call   1030 <strcpy@plt>
lea    0xe10(%rip),%rsi
mov    %r14,%rdi
call   1030 <strcpy@plt>
xor    %ebp,%ebp
mov    %r14,%rdi
mov    %rbx,%rsi
call   1060 <strcat@plt>
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 = [2 x i8] c".\00"
@.str.3 = [10 x i8] c"home.html\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 %33, 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 = call i32 @strcpy(i8* %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%17 = load i8*, i8** %6
%18 = load i8*, i8** %5
%19 = call i32 @strcat(i8* %17, i8* %18)
%20 = load i8*, i8** %5
%21 = load i8*, i8** %5
%22 = call i32 @strlen(i8* %21)
%23 = sub nsw i32 %22, 1
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8, i8* %20, i64 %24
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
%28 = icmp eq i32 %27, 47
br i1 %28, label %29, label %32
29: ; preds = %12
%30 = load i8*, i8** %6
%31 = call i32 @strcat(i8* %30, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
br label %32
32: ; preds = %29, %12
store i32 1, i32* %4
br label %53
33: ; preds = %3
%34 = load i8*, i8** %5
%35 = call i8* @strchr(i8* %34, i8 signext 63)
store i8* %35, i8** %8
%36 = load i8*, i8** %8
%37 = icmp ne i8* %36, null
br i1 %37, label %38, label %44
38: ; preds = %33
%39 = load i8*, i8** %7
%40 = load i8*, i8** %8
%41 = getelementptr inbounds i8, i8* %40, i64 1
%42 = call i32 @strcpy(i8* %39, i8* %41)
%43 = load i8*, i8** %8
store i8 0, i8* %43
br label %47
44: ; preds = %33
%45 = load i8*, i8** %7
%46 = call i32 @strcpy(i8* %45, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0))
br label %47
47: ; preds = %44, %38
%48 = load i8*, i8** %6
%49 = call i32 @strcpy(i8* %48, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%50 = load i8*, i8** %6
%51 = load i8*, i8** %5
%52 = call i32 @strcat(i8* %50, i8* %51)
store i32 0, i32* %4
br label %53
53: ; preds = %47, %32
%54 = load i32, i32* %4
ret i32 %54
}

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