#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 int32_t;

/* Variables and functions */
int /*<<< orphan*/ dumpio_trim_str(char *, char *, int);
int /*<<< orphan*/ sprintf(char *, char *, char const *, char const *, int);
void dumpio_mk_fname(char *fname, const char *base, const char *ext, int32_t i,
                     int32_t y) {
  char _fname[256];
  switch (y) {
  case 4:
    sprintf(_fname, "%s.%s%04d", base, ext, i);
    break;
  case 5:
    sprintf(_fname, "%s.%s%05d", base, ext, i);
    break;
  case 6:
    sprintf(_fname, "%s.%s%06d", base, ext, i);
    break;
  default:
    break;
  }
  dumpio_trim_str(fname, _fname, 256 - 1);
}


x86 assembly (clang, -O0):
<dumpio_mk_fname>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8d,-0x20(%rbp)
mov    -0x20(%rbp),%eax
mov    %eax,-0x124(%rbp)
sub    $0x4,%eax
je     117d <dumpio_mk_fname+0x5d>
jmp    1155 <dumpio_mk_fname+0x35>
mov    -0x124(%rbp),%eax
sub    $0x5,%eax
je     11a1 <dumpio_mk_fname+0x81>
jmp    1169 <dumpio_mk_fname+0x49>
mov    -0x124(%rbp),%eax
sub    $0x6,%eax
je     11c5 <dumpio_mk_fname+0xa5>
jmp    11e9 <dumpio_mk_fname+0xc9>
lea    -0x120(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
mov    -0x1c(%rbp),%r8d
lea    0xe69(%rip),%rsi
call   1040 <sprintf@plt>
jmp    11ee <dumpio_mk_fname+0xce>
lea    -0x120(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
mov    -0x1c(%rbp),%r8d
lea    0xe4f(%rip),%rsi
call   1040 <sprintf@plt>
jmp    11ee <dumpio_mk_fname+0xce>
lea    -0x120(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
mov    -0x1c(%rbp),%r8d
lea    0xe35(%rip),%rsi
call   1040 <sprintf@plt>
jmp    11ee <dumpio_mk_fname+0xce>
jmp    11ee <dumpio_mk_fname+0xce>
mov    -0x8(%rbp),%rdi
lea    -0x120(%rbp),%rsi
mov    $0xff,%edx
call   1030 <dumpio_trim_str@plt>
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dumpio_mk_fname>:
push   %rbx
sub    $0x100,%rsp
mov    %rdi,%rbx
add    $0xfffffffc,%r8d
cmp    $0x2,%r8d
ja     1159 <dumpio_mk_fname+0x39>
mov    %ecx,%eax
mov    %rdx,%rcx
mov    %rsi,%rdx
movslq %r8d,%rsi
lea    0xed9(%rip),%rdi
movslq (%rdi,%rsi,4),%rsi
add    %rdi,%rsi
mov    %rsp,%rdi
mov    %eax,%r8d
call   1040 <sprintf@plt>
mov    %rsp,%rsi
mov    %rbx,%rdi
mov    $0xff,%edx
call   1030 <dumpio_trim_str@plt>
add    $0x100,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [10 x i8] c"%s.%s%04d\00"
@.str.1 = [10 x i8] c"%s.%s%05d\00"
@.str.2 = [10 x i8] c"%s.%s%06d\00"
define void @dumpio_mk_fname(i8* %0, i8* %1, i8* %2, i32 %3, i32 %4) {
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
%11 = alloca [256 x i8]
store i8* %0, i8** %6
store i8* %1, i8** %7
store i8* %2, i8** %8
store i32 %3, i32* %9
store i32 %4, i32* %10
%12 = load i32, i32* %10
switch i32 %12, label %31 [
i32 4, label %13
i32 5, label %19
i32 6, label %25
]
13: ; preds = %5
%14 = getelementptr inbounds [256 x i8], [256 x i8]* %11, i64 0, i64 0
%15 = load i8*, i8** %7
%16 = load i8*, i8** %8
%17 = load i32, i32* %9
%18 = call i32 @sprintf(i8* %14, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* %15, i8* %16, i32 %17)
br label %32
19: ; preds = %5
%20 = getelementptr inbounds [256 x i8], [256 x i8]* %11, i64 0, i64 0
%21 = load i8*, i8** %7
%22 = load i8*, i8** %8
%23 = load i32, i32* %9
%24 = call i32 @sprintf(i8* %20, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* %21, i8* %22, i32 %23)
br label %32
25: ; preds = %5
%26 = getelementptr inbounds [256 x i8], [256 x i8]* %11, i64 0, i64 0
%27 = load i8*, i8** %7
%28 = load i8*, i8** %8
%29 = load i32, i32* %9
%30 = call i32 @sprintf(i8* %26, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* %27, i8* %28, i32 %29)
br label %32
31: ; preds = %5
br label %32
32: ; preds = %31, %25, %19, %13
%33 = load i8*, i8** %6
%34 = getelementptr inbounds [256 x i8], [256 x i8]* %11, i64 0, i64 0
%35 = call i32 @dumpio_trim_str(i8* %33, i8* %34, i32 255)
ret void
}

LLVM IR (-O2):
@.str = [10 x i8] c"%s.%s%04d\00"
@.str.1 = [10 x i8] c"%s.%s%05d\00"
@.str.2 = [10 x i8] c"%s.%s%06d\00"
@reltable.dumpio_mk_fname = [3 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([10 x i8]* @.str to i64), i64 ptrtoint ([3 x i32]* @reltable.dumpio_mk_fname to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([10 x i8]* @.str.1 to i64), i64 ptrtoint ([3 x i32]* @reltable.dumpio_mk_fname to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([10 x i8]* @.str.2 to i64), i64 ptrtoint ([3 x i32]* @reltable.dumpio_mk_fname to i64)) to i32)]
define void @dumpio_mk_fname(i8* %0, i8* %1, i8* %2, i32 %3, i32 %4) {
%6 = alloca [256 x i8]
%7 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%8 = add i32 %4, -4
%9 = icmp ult i32 %8, 3
br i1 %9, label %10, label %15
10: ; preds = %5
%11 = sext i32 %8 to i64
%12 = shl i64 %11, 2
%13 = call i8* @llvm.load.relative.i64(i8* bitcast ([3 x i32]* @reltable.dumpio_mk_fname to i8*), i64 %12)
%14 = call i32 @sprintf(i8* %7, i8* dereferenceable(1) %13, i8* %1, i8* %2, i32 %3)
br label %15
15: ; preds = %5, %10
%16 = call i32 @dumpio_trim_str(i8* %0, i8* %7, i32 255)
ret void
}