#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*/ perror(char *);
int snprintf(char *, size_t, char *, char const *, int);
int get_blkdata_filename(char *filename, size_t bufsize, const char *path,
                         int file_index) {
  int cb = snprintf(filename, bufsize, "%s/blk%.5d.dat", path, file_index);
  if (cb <= 0) {
    perror("snprintf");
    return cb;
  }
  filename[cb] = '\0';
  return cb;
}


x86 assembly (clang, -O0):
<get_blkdata_filename>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rcx
mov    -0x24(%rbp),%r8d
lea    0xeb2(%rip),%rdx
call   1030 <snprintf@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
jg     1177 <get_blkdata_filename+0x57>
lea    0xea8(%rip),%rdi
call   1040 <perror@plt>
mov    -0x28(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1189 <get_blkdata_filename+0x69>
mov    -0x10(%rbp),%rax
movslq -0x28(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x28(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_blkdata_filename>:
push   %rbp
push   %rbx
push   %rax
mov    %ecx,%r8d
mov    %rdx,%rcx
mov    %rdi,%rbx
lea    0xecd(%rip),%rdx
call   1030 <snprintf@plt>
mov    %eax,%ebp
test   %eax,%eax
jle    114d <get_blkdata_filename+0x2d>
mov    %ebp,%eax
movb   $0x0,(%rbx,%rax,1)
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xebb(%rip),%rdi
call   1040 <perror@plt>
jmp    1144 <get_blkdata_filename+0x24>

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

LLVM IR (-O2):
@.str = [15 x i8] c"%s/blk%.5d.dat\00"
@.str.1 = [9 x i8] c"snprintf\00"
define i32 @get_blkdata_filename(i8* %0, i64 %1, i8* %2, i32 %3) {
%5 = tail call i32 @snprintf(i8* %0, i64 %1, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* %2, i32 %3)
%6 = icmp slt i32 %5, 1
br i1 %6, label %7, label %9
7: ; preds = %4
%8 = tail call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
br label %12
9: ; preds = %4
%10 = zext i32 %5 to i64
%11 = getelementptr inbounds i8, i8* %0, i64 %10
store i8 0, i8* %11
br label %12
12: ; preds = %9, %7
ret i32 %5
}