#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*/ sprintf(char *, char const *, ...);
char *gen_path(char *dst, const char *base, const char *fmt, int i) {
  static char path[256];
  char name[16];
  if (dst == NULL)
    dst = path;
  sprintf(name, fmt, i);
  sprintf(dst, "%s/%s", base, name);
  return dst;
}


x86 assembly (clang, -O0):
<gen_path>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    113d <gen_path+0x2d>
lea    0x2f07(%rip),%rax
mov    %rax,-0x8(%rbp)
lea    -0x30(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
mov    $0x0,%al
call   1030 <sprintf@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    -0x30(%rbp),%rcx
lea    0xe9e(%rip),%rsi
mov    $0x0,%al
call   1030 <sprintf@plt>
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gen_path>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
test   %rdi,%rdi
lea    0x2f1a(%rip),%rbx
cmovne %rdi,%rbx
mov    %rsp,%r15
mov    %r15,%rdi
mov    %rdx,%rsi
mov    %ecx,%edx
xor    %eax,%eax
call   1030 <sprintf@plt>
lea    0xebd(%rip),%rsi
mov    %rbx,%rdi
mov    %r14,%rdx
mov    %r15,%rcx
xor    %eax,%eax
call   1030 <sprintf@plt>
mov    %rbx,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@gen_path.path = internal global [256 x i8] zeroinitializer
@.str = [6 x i8] c"%s/%s\00"
define i8* @gen_path(i8* %0, i8* %1, i8* %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca [16 x i8]
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
store i32 %3, i32* %8
%10 = load i8*, i8** %5
%11 = icmp eq i8* %10, null
br i1 %11, label %12, label %13
12: ; preds = %4
store i8* getelementptr inbounds ([256 x i8], [256 x i8]* @gen_path.path, i64 0, i64 0), i8** %5
br label %13
13: ; preds = %12, %4
%14 = getelementptr inbounds [16 x i8], [16 x i8]* %9, i64 0, i64 0
%15 = load i8*, i8** %7
%16 = load i32, i32* %8
%17 = call i32 (i8*, i8*, ...) @sprintf(i8* %14, i8* %15, i32 %16)
%18 = load i8*, i8** %5
%19 = load i8*, i8** %6
%20 = getelementptr inbounds [16 x i8], [16 x i8]* %9, i64 0, i64 0
%21 = call i32 (i8*, i8*, ...) @sprintf(i8* %18, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %19, i8* %20)
%22 = load i8*, i8** %5
ret i8* %22
}

LLVM IR (-O2):
@gen_path.path = internal global [256 x i8] zeroinitializer
@.str = [6 x i8] c"%s/%s\00"
define i8* @gen_path(i8* writeonly %0, i8* %1, i8* nocapture %2, i32 %3) {
%5 = alloca [16 x i8]
%6 = getelementptr inbounds [16 x i8], [16 x i8]* %5, i64 0, i64 0
%7 = icmp eq i8* %0, null
%8 = select i1 %7, i8* getelementptr inbounds ([256 x i8], [256 x i8]* @gen_path.path, i64 0, i64 0), i8* %0
%9 = call i32 (i8*, i8*, ...) @sprintf(i8* %6, i8* dereferenceable(1) %2, i32 %3)
%10 = call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %8, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %1, i8* %6)
ret i8* %8
}