#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 simple_string_last_index_of(char const *, char *);
int /*<<< orphan*/ sprintf(char *, char *, char const *, int);
void build_location(char location_info[], const char *source_file, int line_num,
                    const char *func) {
  int index = simple_string_last_index_of(source_file, "/");
  if (index != -1) {
    const char *tmp = source_file + index + 1;
    sprintf(location_info, "(%s:%d)", tmp, line_num);
  } else {
    sprintf(location_info, "(%s:%d)", source_file, line_num);
  }
}


x86 assembly (clang, -O0):
<build_location>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xebe(%rip),%rsi
call   1030 <simple_string_last_index_of@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0xffffffff,-0x24(%rbp)
je     1183 <build_location+0x63>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
add    %rcx,%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x30(%rbp),%rdx
mov    -0x14(%rbp),%ecx
lea    0xe89(%rip),%rsi
call   1040 <sprintf@plt>
jmp    119a <build_location+0x7a>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    -0x14(%rbp),%ecx
lea    0xe6d(%rip),%rsi
call   1040 <sprintf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<build_location>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%r14d
mov    %rsi,%rbx
mov    %rdi,%rbp
lea    0xecc(%rip),%rsi
mov    %rbx,%rdi
call   1030 <simple_string_last_index_of@plt>
cmp    $0xffffffff,%eax
je     1157 <build_location+0x37>
cltq
lea    (%rbx,%rax,1),%rdx
add    $0x1,%rdx
lea    0xeb0(%rip),%rsi
mov    %rbp,%rdi
jmp    1164 <build_location+0x44>
lea    0xea4(%rip),%rsi
mov    %rbp,%rdi
mov    %rbx,%rdx
mov    %r14d,%ecx
pop    %rbx
pop    %r14
pop    %rbp
jmp    1040 <sprintf@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"/\00"
@.str.1 = [8 x i8] c"(%s:%d)\00"
define void @build_location(i8* %0, i8* %1, i32 %2, i8* %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i8*
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
store i8* %3, i8** %8
%11 = load i8*, i8** %6
%12 = call i32 @simple_string_last_index_of(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32 %12, i32* %9
%13 = load i32, i32* %9
%14 = icmp ne i32 %13, -1
br i1 %14, label %15, label %25
15: ; preds = %4
%16 = load i8*, i8** %6
%17 = load i32, i32* %9
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %16, i64 %18
%20 = getelementptr inbounds i8, i8* %19, i64 1
store i8* %20, i8** %10
%21 = load i8*, i8** %5
%22 = load i8*, i8** %10
%23 = load i32, i32* %7
%24 = call i32 @sprintf(i8* %21, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %22, i32 %23)
br label %30
25: ; preds = %4
%26 = load i8*, i8** %5
%27 = load i8*, i8** %6
%28 = load i32, i32* %7
%29 = call i32 @sprintf(i8* %26, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %27, i32 %28)
br label %30
30: ; preds = %25, %15
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"/\00"
@.str.1 = [8 x i8] c"(%s:%d)\00"
define void @build_location(i8* nocapture writeonly %0, i8* %1, i32 %2, i8* nocapture readnone %3) {
%5 = tail call i32 @simple_string_last_index_of(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i32 %5, -1
br i1 %6, label %12, label %7
7: ; preds = %4
%8 = sext i32 %5 to i64
%9 = getelementptr inbounds i8, i8* %1, i64 %8
%10 = getelementptr inbounds i8, i8* %9, i64 1
%11 = tail call i32 @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %10, i32 %2)
br label %14
12: ; preds = %4
%13 = tail call i32 @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %1, i32 %2)
br label %14
14: ; preds = %12, %7
ret void
}