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

/* Variables and functions */
int get_random_num();
int /*<<< orphan*/ get_value(int /*<<< orphan*/ *, char *, char *, char *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ snprintf(char *, int, char *, int);
int /*<<< orphan*/ strcpy(char *, char *);
scalar_t__ strlen(char *);
char *strrchr(char *, char);
int get_file_name(FILE *fd, char *file_name) {
  int ret = 0;
  char file_name_str[5000] = {0};
  get_value(fd, "GET ", " HTTP", file_name_str);
  char *start = strrchr(file_name_str, '/');
  if (start != NULL) {
    strcpy(file_name, start + 1);
    if (strlen(file_name) == 0) {
      snprintf(file_name, 200, "%d", get_random_num());
    }
    printf("file_name is %s\n", file_name);
    ret = 1;
  }
  return ret;
}


x86 assembly (clang, -O0):
<get_file_name>:
push   %rbp
mov    %rsp,%rbp
sub    $0x13b0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
lea    -0x13a0(%rbp),%rdi
xor    %esi,%esi
mov    $0x1388,%edx
call   1090 <memset@plt>
mov    -0x8(%rbp),%rdi
lea    -0x13a0(%rbp),%rcx
lea    0xe41(%rip),%rsi
lea    0xe3f(%rip),%rdx
call   10a0 <get_value@plt>
lea    -0x13a0(%rbp),%rdi
mov    $0x2f,%esi
call   1080 <strrchr@plt>
mov    %rax,-0x13a8(%rbp)
cmpq   $0x0,-0x13a8(%rbp)
je     125b <get_file_name+0xdb>
mov    -0x10(%rbp),%rdi
mov    -0x13a8(%rbp),%rsi
add    $0x1,%rsi
call   1040 <strcpy@plt>
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
cmp    $0x0,%rax
jne    1244 <get_file_name+0xc4>
mov    -0x10(%rbp),%rax
mov    %rax,-0x13b0(%rbp)
mov    $0x0,%al
call   1030 <get_random_num@plt>
mov    -0x13b0(%rbp),%rdi
mov    %eax,%ecx
mov    $0xc8,%esi
lea    0xdcc(%rip),%rdx
call   1070 <snprintf@plt>
mov    -0x10(%rbp),%rsi
lea    0xdbf(%rip),%rdi
call   1060 <printf@plt>
movl   $0x1,-0x14(%rbp)
mov    -0x14(%rbp),%eax
add    $0x13b0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_file_name>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x1388,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
mov    %rsp,%r15
xor    %ebp,%ebp
mov    $0x1388,%edx
mov    %r15,%rdi
xor    %esi,%esi
call   1080 <memset@plt>
lea    0xe62(%rip),%rsi
lea    0xe60(%rip),%rdx
mov    %rbx,%rdi
mov    %r15,%rcx
call   1090 <get_value@plt>
mov    %r15,%rdi
mov    $0x2f,%esi
call   1070 <strrchr@plt>
test   %rax,%rax
je     1208 <get_file_name+0x98>
add    $0x1,%rax
mov    %r14,%rdi
mov    %rax,%rsi
call   1040 <strcpy@plt>
cmpb   $0x0,(%r14)
jne    11f4 <get_file_name+0x84>
xor    %eax,%eax
call   1030 <get_random_num@plt>
lea    0xe26(%rip),%rdx
mov    %r14,%rdi
mov    $0xc8,%esi
mov    %eax,%ecx
call   1060 <snprintf@plt>
lea    0xe13(%rip),%rdi
mov    %r14,%rsi
call   1050 <printf@plt>
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x1388,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"GET \00"
@.str.1 = [6 x i8] c" HTTP\00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [17 x i8] c"file_name is %s\0A\00"
define i32 @get_file_name(i32* %0, i8* %1) {
%3 = alloca i32*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca [5000 x i8]
%7 = alloca i8*
store i32* %0, i32** %3
store i8* %1, i8** %4
store i32 0, i32* %5
%8 = bitcast [5000 x i8]* %6 to i8*
%9 = load i32*, i32** %3
%10 = getelementptr inbounds [5000 x i8], [5000 x i8]* %6, i64 0, i64 0
%11 = call i32 @get_value(i32* %9, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %10)
%12 = getelementptr inbounds [5000 x i8], [5000 x i8]* %6, i64 0, i64 0
%13 = call i8* @strrchr(i8* %12, i8 signext 47)
store i8* %13, i8** %7
%14 = load i8*, i8** %7
%15 = icmp ne i8* %14, null
br i1 %15, label %16, label %31
16: ; preds = %2
%17 = load i8*, i8** %4
%18 = load i8*, i8** %7
%19 = getelementptr inbounds i8, i8* %18, i64 1
%20 = call i32 @strcpy(i8* %17, i8* %19)
%21 = load i8*, i8** %4
%22 = call i64 @strlen(i8* %21)
%23 = icmp eq i64 %22, 0
br i1 %23, label %24, label %28
24: ; preds = %16
%25 = load i8*, i8** %4
%26 = call i32 (...) @get_random_num()
%27 = call i32 @snprintf(i8* %25, i32 200, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %26)
br label %28
28: ; preds = %24, %16
%29 = load i8*, i8** %4
%30 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), i8* %29)
store i32 1, i32* %5
br label %31
31: ; preds = %28, %2
%32 = load i32, i32* %5
ret i32 %32
}

LLVM IR (-O2):
@.str = [5 x i8] c"GET \00"
@.str.1 = [6 x i8] c" HTTP\00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [17 x i8] c"file_name is %s\0A\00"
define i32 @get_file_name(i32* %0, i8* %1) {
%3 = alloca [5000 x i8]
%4 = getelementptr inbounds [5000 x i8], [5000 x i8]* %3, i64 0, i64 0
%5 = call i32 @get_value(i32* %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %4)
%6 = call i8* @strrchr(i8* %4, i8 signext 47)
%7 = icmp eq i8* %6, null
br i1 %7, label %18, label %8
8: ; preds = %2
%9 = getelementptr inbounds i8, i8* %6, i64 1
%10 = call i32 @strcpy(i8* %1, i8* %9)
%11 = load i8, i8* %1
%12 = icmp eq i8 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %8
%14 = call i32 (...) @get_random_num()
%15 = call i32 @snprintf(i8* %1, i32 200, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %14)
br label %16
16: ; preds = %13, %8
%17 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), i8* %1)
br label %18
18: ; preds = %16, %2
%19 = phi i32 [ 1, %16 ], [ 0, %2 ]
ret i32 %19
}