#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*/ error_fatal(char *, int /*<<< orphan*/ *);
char *index_dir();
scalar_t__ malloc(size_t);
int /*<<< orphan*/ sprintf(char *, char *, char const *, char const *,
                           char const *);
int strlen(char const *);
char *index_file(const char *dir, const char *dbase, const char *suf) {
  const char *p;
  char *file;
  size_t len;
  if ((p = dir) == NULL) {
    p = index_dir();
  }
  len = strlen(p) + 1 + strlen(dbase) + 1 + strlen(suf);
  if ((file = (char *)malloc(len + 1)) == NULL) {
    error_fatal("memory", NULL);
  }
  (void)sprintf(file, "%s/%s.%s", p, dbase, suf);
  return file;
}


x86 assembly (clang, -O0):
<index_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    1181 <index_file+0x31>
mov    $0x0,%al
call   1050 <index_dir@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <strlen@plt>
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x38(%rbp),%eax
add    %ecx,%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x34(%rbp),%eax
add    %ecx,%eax
cltq
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
add    $0x1,%rdi
call   1040 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    11e7 <index_file+0x97>
lea    0xe22(%rip),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1070 <error_fatal@plt>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    -0x10(%rbp),%rcx
mov    -0x18(%rbp),%r8
lea    0xe09(%rip),%rsi
call   1060 <sprintf@plt>
mov    -0x28(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<index_file>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%r12
test   %rdi,%rdi
jne    1170 <index_file+0x20>
xor    %eax,%eax
call   1050 <index_dir@plt>
mov    %rax,%r12
mov    %r12,%rdi
call   1030 <strlen@plt>
mov    %eax,%ebp
mov    %r15,%rdi
call   1030 <strlen@plt>
mov    %eax,%ebx
mov    %r14,%rdi
call   1030 <strlen@plt>
add    %ebp,%ebx
add    %ebx,%eax
add    $0x2,%eax
movslq %eax,%rdi
add    $0x1,%rdi
call   1040 <malloc@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    11b5 <index_file+0x65>
lea    0xe52(%rip),%rdi
xor    %esi,%esi
call   1070 <error_fatal@plt>
lea    0xe4b(%rip),%rsi
mov    %rbx,%rdi
mov    %r12,%rdx
mov    %r15,%rcx
mov    %r14,%r8
call   1060 <sprintf@plt>
mov    %rbx,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [7 x i8] c"memory\00"
@.str.1 = [9 x i8] c"%s/%s.%s\00"
define i8* @index_file(i8* %0, i8* %1, i8* %2) {
%4 = icmp eq i8* %0, null
br i1 %4, label %5, label %7
5: ; preds = %3
%6 = tail call i8* (...) @index_dir()
br label %7
7: ; preds = %5, %3
%8 = phi i8* [ %6, %5 ], [ %0, %3 ]
%9 = tail call i32 @strlen(i8* %8)
%10 = tail call i32 @strlen(i8* %1)
%11 = tail call i32 @strlen(i8* %2)
%12 = add i32 %9, 2
%13 = add i32 %12, %10
%14 = add i32 %13, %11
%15 = sext i32 %14 to i64
%16 = add nsw i64 %15, 1
%17 = tail call i64 @malloc(i64 %16)
%18 = inttoptr i64 %17 to i8*
%19 = icmp eq i64 %17, 0
br i1 %19, label %20, label %22
20: ; preds = %7
%21 = tail call i32 @error_fatal(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32* null)
br label %22
22: ; preds = %20, %7
%23 = tail call i32 @sprintf(i8* dereferenceable(1) %18, i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* %8, i8* %1, i8* %2)
ret i8* %18
}