#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 *concat_path(char *, char const *);
char *file_dir(char const *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ memcmp(char const *, char *, int);
char *strdup(char const *);
char *build_filename(const char *orig, const char *filename) {
  if (!filename[0])
    return NULL;
  if (!memcmp(filename, "http://", 7) || filename[0] == '/')
    return strdup(filename);
  char *dir = file_dir(orig);
  if (dir == NULL)
    return NULL;
  char *name = concat_path(dir, filename);
  free(dir);
  return name;
}


x86 assembly (clang, -O0):
<build_filename>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmpb   $0x0,(%rax)
jne    117a <build_filename+0x2a>
movq   $0x0,-0x8(%rbp)
jmp    1201 <build_filename+0xb1>
mov    -0x18(%rbp),%rdi
lea    0xe7b(%rip),%rsi
mov    $0x7,%edx
call   1060 <memcmp@plt>
cmp    $0x0,%eax
je     11a8 <build_filename+0x58>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
jne    11ba <build_filename+0x6a>
mov    -0x18(%rbp),%rdi
call   1070 <strdup@plt>
mov    %rax,-0x8(%rbp)
jmp    1201 <build_filename+0xb1>
mov    -0x10(%rbp),%rdi
call   1050 <file_dir@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11df <build_filename+0x8f>
movq   $0x0,-0x8(%rbp)
jmp    1201 <build_filename+0xb1>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <concat_path@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<build_filename>:
push   %r14
push   %rbx
push   %rax
cmpb   $0x0,(%rsi)
je     11b6 <build_filename+0x66>
mov    %rsi,%rbx
mov    %rdi,%r14
lea    0xe9a(%rip),%rsi
mov    %rbx,%rdi
mov    $0x7,%edx
call   1060 <memcmp@plt>
test   %eax,%eax
je     117c <build_filename+0x2c>
cmpb   $0x2f,(%rbx)
jne    118b <build_filename+0x3b>
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1070 <strdup@plt>
mov    %r14,%rdi
call   1050 <file_dir@plt>
test   %rax,%rax
je     11b6 <build_filename+0x66>
mov    %rax,%r14
mov    %rax,%rdi
mov    %rbx,%rsi
call   1040 <concat_path@plt>
mov    %rax,%rbx
mov    %r14,%rdi
call   1030 <free@plt>
mov    %rbx,%rax
jmp    11b8 <build_filename+0x68>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [8 x i8] c"http://\00"
define i8* @build_filename(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
%8 = load i8*, i8** %5
%9 = getelementptr inbounds i8, i8* %8, i64 0
%10 = load i8, i8* %9
%11 = icmp ne i8 %10, 0
br i1 %11, label %13, label %12
12: ; preds = %2
store i8* null, i8** %3
br label %39
13: ; preds = %2
%14 = load i8*, i8** %5
%15 = call i32 @memcmp(i8* %14, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 7)
%16 = icmp ne i32 %15, 0
br i1 %16, label %17, label %23
17: ; preds = %13
%18 = load i8*, i8** %5
%19 = getelementptr inbounds i8, i8* %18, i64 0
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
%22 = icmp eq i32 %21, 47
br i1 %22, label %23, label %26
23: ; preds = %17, %13
%24 = load i8*, i8** %5
%25 = call i8* @strdup(i8* %24)
store i8* %25, i8** %3
br label %39
26: ; preds = %17
%27 = load i8*, i8** %4
%28 = call i8* @file_dir(i8* %27)
store i8* %28, i8** %6
%29 = load i8*, i8** %6
%30 = icmp eq i8* %29, null
br i1 %30, label %31, label %32
31: ; preds = %26
store i8* null, i8** %3
br label %39
32: ; preds = %26
%33 = load i8*, i8** %6
%34 = load i8*, i8** %5
%35 = call i8* @concat_path(i8* %33, i8* %34)
store i8* %35, i8** %7
%36 = load i8*, i8** %6
%37 = call i32 @free(i8* %36)
%38 = load i8*, i8** %7
store i8* %38, i8** %3
br label %39
39: ; preds = %32, %31, %23, %12
%40 = load i8*, i8** %3
ret i8* %40
}

LLVM IR (-O2):
@.str = [8 x i8] c"http://\00"
define i8* @build_filename(i8* %0, i8* %1) {
%3 = load i8, i8* %1
%4 = icmp eq i8 %3, 0
br i1 %4, label %19, label %5
5: ; preds = %2
%6 = tail call i32 @memcmp(i8* %1, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 7)
%7 = icmp eq i32 %6, 0
br i1 %7, label %11, label %8
8: ; preds = %5
%9 = load i8, i8* %1
%10 = icmp eq i8 %9, 47
br i1 %10, label %11, label %13
11: ; preds = %8, %5
%12 = tail call i8* @strdup(i8* %1)
br label %19
13: ; preds = %8
%14 = tail call i8* @file_dir(i8* %0)
%15 = icmp eq i8* %14, null
br i1 %15, label %19, label %16
16: ; preds = %13
%17 = tail call i8* @concat_path(i8* %14, i8* %1)
%18 = tail call i32 @free(i8* %14)
br label %19
19: ; preds = %16, %13, %2, %11
%20 = phi i8* [ %12, %11 ], [ null, %2 ], [ %17, %16 ], [ null, %13 ]
ret i8* %20
}