#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 uint8_t;
typedef int /*<<< orphan*/ uint16_t;

/* Variables and functions */
int /*<<< orphan*/ free(char *);
scalar_t__ log10(int /*<<< orphan*/);
char *malloc(scalar_t__);
int /*<<< orphan*/ sprintf(char *, char *, char *, ...);
scalar_t__ strlen(char *);
char *_file_name(char *outdir, uint16_t tn, uint16_t ti) {
  uint8_t fmtlen;
  char *fmtstr;
  char *fname;
  fmtstr = NULL;
  fname = NULL;
  fmtlen = ((int)log10(tn)) + 1;
  if (fmtlen > 9)
    goto fail;
  fmtstr = malloc(strlen(outdir) + 7);
  if (fmtstr == NULL)
    goto fail;
  sprintf(fmtstr, "%s/%%%02uu", outdir, fmtlen);
  fname = malloc(strlen(outdir) + fmtlen + 3);
  if (fname == NULL)
    goto fail;
  sprintf(fname, fmtstr, ti);
  free(fmtstr);
  return fname;
fail:
  if (fmtstr != NULL)
    free(fmtstr);
  if (fname != NULL)
    free(fname);
  return NULL;
}


x86 assembly (clang, -O0):
<_file_name>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
mov    -0x14(%rbp),%edi
call   1060 <log10@plt>
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0x9,-0x1c(%rbp)
jle    118f <_file_name+0x3f>
jmp    122a <_file_name+0xda>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rdi
add    $0x7,%rdi
call   1050 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11b8 <_file_name+0x68>
jmp    122a <_file_name+0xda>
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    -0x1c(%rbp),%ecx
lea    0xe36(%rip),%rsi
mov    $0x0,%al
call   1070 <sprintf@plt>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rdi
movslq -0x1c(%rbp),%rax
add    %rax,%rdi
add    $0x3,%rdi
call   1050 <malloc@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1201 <_file_name+0xb1>
jmp    122a <_file_name+0xda>
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%rsi
movslq -0x18(%rbp),%rdx
mov    $0x0,%al
call   1070 <sprintf@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    125a <_file_name+0x10a>
cmpq   $0x0,-0x28(%rbp)
je     123e <_file_name+0xee>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
cmpq   $0x0,-0x30(%rbp)
je     1252 <_file_name+0x102>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_file_name>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edx,%r14d
mov    %rdi,%rbx
mov    %esi,%edi
call   1060 <log10@plt>
mov    %rax,%rbp
cmp    $0x8,%ebp
jg     11dd <_file_name+0x8d>
mov    %rbx,%rdi
call   1040 <strlen@plt>
lea    0x7(%rax),%rdi
call   1050 <malloc@plt>
test   %rax,%rax
je     11dd <_file_name+0x8d>
mov    %rax,%r15
lea    0x1(%rbp),%ecx
lea    0xe70(%rip),%rsi
xor    %r12d,%r12d
mov    %rax,%rdi
mov    %rbx,%rdx
xor    %eax,%eax
call   1070 <sprintf@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
movslq %ebp,%rcx
lea    (%rcx,%rax,1),%rdi
add    $0x4,%rdi
call   1050 <malloc@plt>
test   %rax,%rax
je     11d3 <_file_name+0x83>
mov    %rax,%rbx
movslq %r14d,%rdx
mov    %rax,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1070 <sprintf@plt>
mov    %rbx,%r12
mov    %r15,%rdi
call   1030 <free@plt>
jmp    11e0 <_file_name+0x90>
xor    %r12d,%r12d
mov    %r12,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [11 x i8] c"%s/%%%02uu\00"
define i8* @_file_name(i8* %0, i32 %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i8*
store i8* %0, i8** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i8* null, i8** %9
store i8* null, i8** %10
%11 = load i32, i32* %6
%12 = call i64 @log10(i32 %11)
%13 = trunc i64 %12 to i32
%14 = add nsw i32 %13, 1
store i32 %14, i32* %8
%15 = load i32, i32* %8
%16 = icmp sgt i32 %15, 9
br i1 %16, label %17, label %18
17: ; preds = %3
br label %51
18: ; preds = %3
%19 = load i8*, i8** %5
%20 = call i64 @strlen(i8* %19)
%21 = add nsw i64 %20, 7
%22 = call i8* @malloc(i64 %21)
store i8* %22, i8** %9
%23 = load i8*, i8** %9
%24 = icmp eq i8* %23, null
br i1 %24, label %25, label %26
25: ; preds = %18
br label %51
26: ; preds = %18
%27 = load i8*, i8** %9
%28 = load i8*, i8** %5
%29 = load i32, i32* %8
%30 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %27, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* %28, i32 %29)
%31 = load i8*, i8** %5
%32 = call i64 @strlen(i8* %31)
%33 = load i32, i32* %8
%34 = sext i32 %33 to i64
%35 = add nsw i64 %32, %34
%36 = add nsw i64 %35, 3
%37 = call i8* @malloc(i64 %36)
store i8* %37, i8** %10
%38 = load i8*, i8** %10
%39 = icmp eq i8* %38, null
br i1 %39, label %40, label %41
40: ; preds = %26
br label %51
41: ; preds = %26
%42 = load i8*, i8** %10
%43 = load i8*, i8** %9
%44 = load i32, i32* %7
%45 = sext i32 %44 to i64
%46 = inttoptr i64 %45 to i8*
%47 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %42, i8* %43, i8* %46)
%48 = load i8*, i8** %9
%49 = call i32 @free(i8* %48)
%50 = load i8*, i8** %10
store i8* %50, i8** %4
br label %64
51: ; preds = %40, %25, %17
%52 = load i8*, i8** %9
%53 = icmp ne i8* %52, null
br i1 %53, label %54, label %57
54: ; preds = %51
%55 = load i8*, i8** %9
%56 = call i32 @free(i8* %55)
br label %57
57: ; preds = %54, %51
%58 = load i8*, i8** %10
%59 = icmp ne i8* %58, null
br i1 %59, label %60, label %63
60: ; preds = %57
%61 = load i8*, i8** %10
%62 = call i32 @free(i8* %61)
br label %63
63: ; preds = %60, %57
store i8* null, i8** %4
br label %64
64: ; preds = %63, %41
%65 = load i8*, i8** %4
ret i8* %65
}

LLVM IR (-O2):
@.str = [11 x i8] c"%s/%%%02uu\00"
define noalias i8* @_file_name(i8* %0, i32 %1, i32 %2) {
%4 = tail call i64 @log10(i32 %1)
%5 = trunc i64 %4 to i32
%6 = add nsw i32 %5, 1
%7 = icmp sgt i32 %5, 8
br i1 %7, label %29, label %8
8: ; preds = %3
%9 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%10 = add nsw i64 %9, 7
%11 = tail call i8* @malloc(i64 %10)
%12 = icmp eq i8* %11, null
br i1 %12, label %29, label %13
13: ; preds = %8
%14 = tail call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %11, i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* %0, i32 %6)
%15 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%16 = shl i64 %4, 32
%17 = ashr exact i64 %16, 32
%18 = add nsw i64 %17, 4
%19 = add i64 %18, %15
%20 = tail call i8* @malloc(i64 %19)
%21 = icmp eq i8* %20, null
br i1 %21, label %26, label %22
22: ; preds = %13
%23 = sext i32 %2 to i64
%24 = inttoptr i64 %23 to i8*
%25 = tail call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %20, i8* %11, i8* %24)
br label %26
26: ; preds = %13, %22
%27 = phi i8* [ %20, %22 ], [ null, %13 ]
%28 = tail call i32 @free(i8* %11)
br label %29
29: ; preds = %26, %8, %3
%30 = phi i8* [ null, %3 ], [ null, %8 ], [ %27, %26 ]
ret i8* %30
}