void getFileName(filename, head, tail, number, max) char *filename, *head,
    *tail;
int number, max;
{
  int digits;
  char ext[10], format[20];
  digits = 1;
  if (max < 1)
    max = 1;
  while (max /= 10)
    digits++;
  sprintf(format, "%%0%dd", digits);
  strcat(format, "\0");
  sprintf(ext, format, number);
  strcpy(filename, head);
  strcat(filename, ".");
  strcat(filename, ext);
  strcat(filename, ".");
  strcat(filename, tail);
}


x86 assembly (clang, -O0):
<getFileName>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8d,-0x20(%rbp)
movl   $0x1,-0x24(%rbp)
cmpl   $0x1,-0x20(%rbp)
jge    1163 <getFileName+0x33>
movl   $0x1,-0x20(%rbp)
jmp    1168 <getFileName+0x38>
mov    -0x20(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,-0x20(%rbp)
cmp    $0x0,%eax
je     118d <getFileName+0x5d>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1168 <getFileName+0x38>
lea    -0x50(%rbp),%rdi
mov    -0x24(%rbp),%edx
lea    0xe65(%rip),%rsi
mov    $0x0,%al
call   1050 <sprintf@plt>
lea    -0x50(%rbp),%rdi
lea    0xe5c(%rip),%rsi
call   1040 <strcat@plt>
lea    -0x2e(%rbp),%rdi
lea    -0x50(%rbp),%rsi
mov    -0x1c(%rbp),%edx
mov    $0x0,%al
call   1050 <sprintf@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x8(%rbp),%rdi
lea    0xe2b(%rip),%rsi
call   1040 <strcat@plt>
mov    -0x8(%rbp),%rdi
lea    -0x2e(%rbp),%rsi
call   1040 <strcat@plt>
mov    -0x8(%rbp),%rdi
lea    0xe0e(%rip),%rsi
call   1040 <strcat@plt>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <strcat@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getFileName>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %ecx,%r12d
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
mov    $0x1,%edx
cmp    $0xa,%r8d
jl     1196 <getFileName+0x56>
mov    $0x1,%edx
nopw   0x0(%rax,%rax,1)
movslq %r8d,%rax
imul   $0x66666667,%rax,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x22,%rax
lea    (%rax,%rcx,1),%r8d
add    $0x1,%edx
add    %ecx,%eax
add    $0x9,%eax
cmp    $0x12,%eax
ja     1170 <getFileName+0x30>
lea    0xe63(%rip),%rsi
lea    0x10(%rsp),%rbp
mov    %rbp,%rdi
xor    %eax,%eax
call   1060 <sprintf@plt>
lea    0x6(%rsp),%r13
mov    %r13,%rdi
mov    %rbp,%rsi
mov    %r12d,%edx
xor    %eax,%eax
call   1060 <sprintf@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1030 <strcpy@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
movw   $0x2e,(%rbx,%rax,1)
mov    %rbx,%rdi
mov    %r13,%rsi
call   1050 <strcat@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
movw   $0x2e,(%rbx,%rax,1)
mov    %rbx,%rdi
mov    %r14,%rsi
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <strcat@plt>

LLVM IR (-O0):
@.str = [7 x i8] c"%%0%dd\00"
@.str.1 = [2 x i8] zeroinitializer
@.str.2 = [2 x i8] c".\00"
define void @getFileName(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 i32
%12 = alloca [10 x i8]
%13 = alloca [20 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
store i32 1, i32* %11
%14 = load i32, i32* %10
%15 = icmp slt i32 %14, 1
br i1 %15, label %16, label %17
16: ; preds = %5
store i32 1, i32* %10
br label %17
17: ; preds = %16, %5
br label %18
18: ; preds = %22, %17
%19 = load i32, i32* %10
%20 = sdiv i32 %19, 10
store i32 %20, i32* %10
%21 = icmp ne i32 %20, 0
br i1 %21, label %22, label %25
22: ; preds = %18
%23 = load i32, i32* %11
%24 = add nsw i32 %23, 1
store i32 %24, i32* %11
br label %18
25: ; preds = %18
%26 = getelementptr inbounds [20 x i8], [20 x i8]* %13, i64 0, i64 0
%27 = load i32, i32* %11
%28 = call i32 (i8*, i8*, ...) @sprintf(i8* %26, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %27)
%29 = getelementptr inbounds [20 x i8], [20 x i8]* %13, i64 0, i64 0
%30 = call i8* @strcat(i8* %29, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%31 = getelementptr inbounds [10 x i8], [10 x i8]* %12, i64 0, i64 0
%32 = getelementptr inbounds [20 x i8], [20 x i8]* %13, i64 0, i64 0
%33 = load i32, i32* %9
%34 = call i32 (i8*, i8*, ...) @sprintf(i8* %31, i8* %32, i32 %33)
%35 = load i8*, i8** %6
%36 = load i8*, i8** %7
%37 = call i8* @strcpy(i8* %35, i8* %36)
%38 = load i8*, i8** %6
%39 = call i8* @strcat(i8* %38, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%40 = load i8*, i8** %6
%41 = getelementptr inbounds [10 x i8], [10 x i8]* %12, i64 0, i64 0
%42 = call i8* @strcat(i8* %40, i8* %41)
%43 = load i8*, i8** %6
%44 = call i8* @strcat(i8* %43, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%45 = load i8*, i8** %6
%46 = load i8*, i8** %8
%47 = call i8* @strcat(i8* %45, i8* %46)
ret void
}

LLVM IR (-O2):
@.str = [7 x i8] c"%%0%dd\00"
define void @getFileName(i8* %0, i8* nocapture %1, i8* nocapture %2, i32 %3, i32 %4) {
%6 = alloca [10 x i8]
%7 = alloca [20 x i8]
%8 = getelementptr inbounds [10 x i8], [10 x i8]* %6, i64 0, i64 0
%9 = getelementptr inbounds [20 x i8], [20 x i8]* %7, i64 0, i64 0
%10 = icmp slt i32 %4, 10
br i1 %10, label %18, label %11
11: ; preds = %5, %11
%12 = phi i32 [ %15, %11 ], [ 1, %5 ]
%13 = phi i32 [ %14, %11 ], [ %4, %5 ]
%14 = sdiv i32 %13, 10
%15 = add nuw nsw i32 %12, 1
%16 = add nsw i32 %14, 9
%17 = icmp ult i32 %16, 19
br i1 %17, label %18, label %11
18: ; preds = %11, %5
%19 = phi i32 [ 1, %5 ], [ %15, %11 ]
%20 = call i32 (i8*, i8*, ...) @sprintf(i8* %9, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %19)
%21 = call i32 (i8*, i8*, ...) @sprintf(i8* %8, i8* %9, i32 %3)
%22 = tail call i8* @strcpy(i8* dereferenceable(1) %0, i8* dereferenceable(1) %1)
%23 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%24 = getelementptr i8, i8* %0, i64 %23
%25 = bitcast i8* %24 to i16*
store i16 46, i16* %25
%26 = call i8* @strcat(i8* dereferenceable(1) %0, i8* %8)
%27 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%28 = getelementptr i8, i8* %0, i64 %27
%29 = bitcast i8* %28 to i16*
store i16 46, i16* %29
%30 = tail call i8* @strcat(i8* dereferenceable(1) %0, i8* dereferenceable(1) %2)
ret void
}