#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 */
scalar_t__ EEXIST;
scalar_t__ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, char *);
int mkdir(char *, int);
int /*<<< orphan*/ snprintf(char *, int, char const *, unsigned int);
int /*<<< orphan*/ stderr;
char *strerror(scalar_t__);
int strlen(char *);
int /*<<< orphan*/ strncat(char *, char *, int);
const char *file_name(const char *dir_format, const char *file_format,
                      unsigned int index) {
  static char dir_buffer[200];
  char file_buffer[100];
  if (dir_format) {
    snprintf(dir_buffer, sizeof dir_buffer, dir_format, index / 100);
    if (mkdir(dir_buffer, 0777) == -1 && errno != EEXIST) {
      fprintf(stderr, "recoverjpeg: unable to create directory %s (%s)\n",
              dir_buffer, strerror(errno));
      exit(1);
    }
    strncat(dir_buffer, "/", sizeof dir_buffer - 1);
  } else {
    *dir_buffer = '\0';
  }
  snprintf(file_buffer, sizeof file_buffer, file_format, index);
  strncat(dir_buffer, file_buffer, sizeof dir_buffer - strlen(dir_buffer) - 1);
  return dir_buffer;
}


x86 assembly (clang, -O0):
<file_name>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     1257 <file_name+0xe7>
mov    -0x8(%rbp),%rax
mov    %rax,-0x88(%rbp)
mov    -0x14(%rbp),%eax
mov    $0x64,%ecx
xor    %edx,%edx
div    %ecx
mov    -0x88(%rbp),%rdx
mov    %eax,%ecx
lea    0x2eb8(%rip),%rdi
mov    $0xc8,%esi
call   1050 <snprintf@plt>
lea    0x2ea7(%rip),%rdi
mov    $0x1ff,%esi
call   1030 <mkdir@plt>
cmp    $0xffffffff,%eax
jne    123a <file_name+0xca>
mov    0x2ded(%rip),%rax
mov    (%rax),%rax
mov    0x2df3(%rip),%rcx
cmp    (%rcx),%rax
je     123a <file_name+0xca>
mov    0x2ddb(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x8c(%rbp)
mov    0x2dc4(%rip),%rax
mov    (%rax),%rdi
call   1090 <strerror@plt>
mov    -0x8c(%rbp),%edi
mov    %rax,%rcx
lea    0xddc(%rip),%rsi
lea    0x2e45(%rip),%rdx
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
lea    0x2e2f(%rip),%rdi
lea    0xde9(%rip),%rsi
mov    $0xc7,%edx
call   1060 <strncat@plt>
jmp    125e <file_name+0xee>
movb   $0x0,0x2e12(%rip)
lea    -0x80(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    -0x14(%rbp),%ecx
mov    $0x64,%esi
call   1050 <snprintf@plt>
lea    -0x80(%rbp),%rax
mov    %rax,-0x98(%rbp)
lea    0x2deb(%rip),%rdi
call   1040 <strlen@plt>
mov    -0x98(%rbp),%rsi
movslq %eax,%rcx
mov    $0xc8,%eax
sub    %rcx,%rax
sub    $0x1,%rax
mov    %eax,%edx
lea    0x2dc7(%rip),%rdi
call   1060 <strncat@plt>
lea    0x2dbb(%rip),%rax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<file_name>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x68,%rsp
mov    %edx,%ebp
mov    %rsi,%r14
test   %rdi,%rdi
je     11ea <file_name+0x7a>
mov    %rdi,%rdx
mov    %ebp,%eax
imul   $0x51eb851f,%rax,%rcx
shr    $0x25,%rcx
lea    0x2ed5(%rip),%r15
mov    %r15,%rdi
mov    $0xc8,%esi
call   1050 <snprintf@plt>
mov    %r15,%rdi
mov    $0x1ff,%esi
call   1030 <mkdir@plt>
cmp    $0xffffffff,%eax
jne    11d0 <file_name+0x60>
mov    0x2e0f(%rip),%rax
mov    (%rax),%rdi
mov    0x2e15(%rip),%rax
cmp    (%rax),%rdi
jne    1235 <file_name+0xc5>
lea    0x2e99(%rip),%rdi
lea    0xe53(%rip),%rsi
mov    $0xc7,%edx
call   1060 <strncat@plt>
jmp    11f1 <file_name+0x81>
movb   $0x0,0x2e7f(%rip)
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x64,%esi
mov    %r14,%rdx
mov    %ebp,%ecx
call   1050 <snprintf@plt>
lea    0x2e63(%rip),%rbp
mov    %rbp,%rdi
call   1040 <strlen@plt>
mov    $0xc7,%edx
sub    %eax,%edx
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1060 <strncat@plt>
mov    %rbp,%rax
add    $0x68,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d9c(%rip),%rax
mov    (%rax),%ebx
call   1090 <strerror@plt>
lea    0xdb6(%rip),%rsi
lea    0x2e1f(%rip),%rdx
mov    %ebx,%edi
mov    %rax,%rcx
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@file_name.dir_buffer = internal global [200 x i8] zeroinitializer
@errno = global i64 0
@EEXIST = global i64 0
@stderr = global i32 0
@.str = [49 x i8] c"recoverjpeg: unable to create directory %s (%s)\0A\00"
@.str.1 = [2 x i8] c"/\00"
define i8* @file_name(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca [100 x i8]
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%8 = load i8*, i8** %4
%9 = icmp ne i8* %8, null
br i1 %9, label %10, label %29
10: ; preds = %3
%11 = load i8*, i8** %4
%12 = load i32, i32* %6
%13 = udiv i32 %12, 100
%14 = call i32 @snprintf(i8* getelementptr inbounds ([200 x i8], [200 x i8]* @file_name.dir_buffer, i64 0, i64 0), i32 200, i8* %11, i32 %13)
%15 = call i32 @mkdir(i8* getelementptr inbounds ([200 x i8], [200 x i8]* @file_name.dir_buffer, i64 0, i64 0), i32 511)
%16 = icmp eq i32 %15, -1
br i1 %16, label %17, label %27
17: ; preds = %10
%18 = load i64, i64* @errno
%19 = load i64, i64* @EEXIST
%20 = icmp ne i64 %18, %19
br i1 %20, label %21, label %27
21: ; preds = %17
%22 = load i32, i32* @stderr
%23 = load i64, i64* @errno
%24 = call i8* @strerror(i64 %23)
%25 = call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([200 x i8], [200 x i8]* @file_name.dir_buffer, i64 0, i64 0), i8* %24)
%26 = call i32 @exit(i32 1)
unreachable
27: ; preds = %17, %10
%28 = call i32 @strncat(i8* getelementptr inbounds ([200 x i8], [200 x i8]* @file_name.dir_buffer, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 199)
br label %30
29: ; preds = %3
store i8 0, i8* getelementptr inbounds ([200 x i8], [200 x i8]* @file_name.dir_buffer, i64 0, i64 0)
br label %30
30: ; preds = %29, %27
%31 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%32 = load i8*, i8** %5
%33 = load i32, i32* %6
%34 = call i32 @snprintf(i8* %31, i32 100, i8* %32, i32 %33)
%35 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%36 = call i32 @strlen(i8* getelementptr inbounds ([200 x i8], [200 x i8]* @file_name.dir_buffer, i64 0, i64 0))
%37 = sext i32 %36 to i64
%38 = sub i64 200, %37
%39 = sub i64 %38, 1
%40 = trunc i64 %39 to i32
%41 = call i32 @strncat(i8* getelementptr inbounds ([200 x i8], [200 x i8]* @file_name.dir_buffer, i64 0, i64 0), i8* %35, i32 %40)
ret i8* getelementptr inbounds ([200 x i8], [200 x i8]* @file_name.dir_buffer, i64 0, i64 0)
}

LLVM IR (-O2):
@file_name.dir_buffer = internal global [200 x i8] zeroinitializer
@errno = global i64 0
@EEXIST = global i64 0
@stderr = global i32 0
@.str = [49 x i8] c"recoverjpeg: unable to create directory %s (%s)\0A\00"
@.str.1 = [2 x i8] c"/\00"
define i8* @file_name(i8* %0, i8* %1, i32 %2) {
%4 = alloca [100 x i8]
%5 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%6 = icmp eq i8* %0, null
br i1 %6, label %23, label %7
7: ; preds = %3
%8 = udiv i32 %2, 100
%9 = tail call i32 @snprintf(i8* getelementptr inbounds ([200 x i8], [200 x i8]* @file_name.dir_buffer, i64 0, i64 0), i32 200, i8* %0, i32 %8)
%10 = tail call i32 @mkdir(i8* getelementptr inbounds ([200 x i8], [200 x i8]* @file_name.dir_buffer, i64 0, i64 0), i32 511)
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %21
12: ; preds = %7
%13 = load i64, i64* @errno
%14 = load i64, i64* @EEXIST
%15 = icmp eq i64 %13, %14
br i1 %15, label %21, label %16
16: ; preds = %12
%17 = load i32, i32* @stderr
%18 = tail call i8* @strerror(i64 %13)
%19 = tail call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([200 x i8], [200 x i8]* @file_name.dir_buffer, i64 0, i64 0), i8* %18)
%20 = tail call i32 @exit(i32 1)
unreachable
21: ; preds = %12, %7
%22 = tail call i32 @strncat(i8* getelementptr inbounds ([200 x i8], [200 x i8]* @file_name.dir_buffer, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 199)
br label %24
23: ; preds = %3
store i8 0, i8* getelementptr inbounds ([200 x i8], [200 x i8]* @file_name.dir_buffer, i64 0, i64 0)
br label %24
24: ; preds = %23, %21
%25 = call i32 @snprintf(i8* %5, i32 100, i8* %1, i32 %2)
%26 = call i32 @strlen(i8* getelementptr inbounds ([200 x i8], [200 x i8]* @file_name.dir_buffer, i64 0, i64 0))
%27 = sub i32 199, %26
%28 = call i32 @strncat(i8* getelementptr inbounds ([200 x i8], [200 x i8]* @file_name.dir_buffer, i64 0, i64 0), i8* %5, i32 %27)
ret i8* getelementptr inbounds ([200 x i8], [200 x i8]* @file_name.dir_buffer, i64 0, i64 0)
}