#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*/ die(char *, ...);
int /*<<< orphan*/ memcpy(char *, char const *, size_t);
int /*<<< orphan*/ snprintf(char *, size_t, char *, unsigned int);
char *strchr(char const *, char);
size_t strlen(char const *);
void generate_filename(const char *pattern, char *out, size_t q_len,
                       unsigned int d_w, unsigned int d_h,
                       unsigned int frame_in) {
  const char *p = pattern;
  char *q = out;
  do {
    char *next_pat = strchr(p, '%');
    if (p == next_pat) {
      size_t pat_len;
      q[q_len - 1] = '\0';
      switch (p[1]) {
      case 'w':
        snprintf(q, q_len - 1, "%d", d_w);
        break;
      case 'h':
        snprintf(q, q_len - 1, "%d", d_h);
        break;
      case '1':
        snprintf(q, q_len - 1, "%d", frame_in);
        break;
      case '2':
        snprintf(q, q_len - 1, "%02d", frame_in);
        break;
      case '3':
        snprintf(q, q_len - 1, "%03d", frame_in);
        break;
      case '4':
        snprintf(q, q_len - 1, "%04d", frame_in);
        break;
      case '5':
        snprintf(q, q_len - 1, "%05d", frame_in);
        break;
      case '6':
        snprintf(q, q_len - 1, "%06d", frame_in);
        break;
      case '7':
        snprintf(q, q_len - 1, "%07d", frame_in);
        break;
      case '8':
        snprintf(q, q_len - 1, "%08d", frame_in);
        break;
      case '9':
        snprintf(q, q_len - 1, "%09d", frame_in);
        break;
      default:
        die("Unrecognized pattern %%%c\n", p[1]);
        break;
      }
      pat_len = strlen(q);
      if (pat_len >= q_len - 1)
        die("Output filename too long.\n");
      q += pat_len;
      p += 2;
      q_len -= pat_len;
    } else {
      size_t copy_len;
      if (!next_pat)
        copy_len = strlen(p);
      else
        copy_len = next_pat - p;
      if (copy_len >= q_len - 1)
        die("Output filename too long.\n");
      memcpy(q, p, copy_len);
      q[copy_len] = '\0';
      q += copy_len;
      p += copy_len;
      q_len -= copy_len;
    }
  } while (*p);
}


x86 assembly (clang, -O0):
<generate_filename>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8d,-0x20(%rbp)
mov    %r9d,-0x24(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x30(%rbp),%rdi
mov    $0x25,%esi
call   1040 <strchr@plt>
mov    %rax,-0x40(%rbp)
mov    -0x30(%rbp),%rax
cmp    -0x40(%rbp),%rax
jne    13ac <generate_filename+0x25c>
mov    -0x38(%rbp),%rcx
mov    -0x18(%rbp),%rax
movb   $0x0,-0x1(%rax,%rcx,1)
mov    -0x30(%rbp),%rax
movsbl 0x1(%rax),%eax
add    $0xffffffcf,%eax
mov    %eax,%ecx
mov    %rcx,-0x58(%rbp)
sub    $0x46,%eax
ja     133a <generate_filename+0x1ea>
mov    -0x58(%rbp),%rax
lea    0xe2f(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x38(%rbp),%rdi
mov    -0x18(%rbp),%rsi
sub    $0x1,%rsi
mov    -0x1c(%rbp),%ecx
lea    0xf2c(%rip),%rdx
call   1050 <snprintf@plt>
jmp    1350 <generate_filename+0x200>
mov    -0x38(%rbp),%rdi
mov    -0x18(%rbp),%rsi
sub    $0x1,%rsi
mov    -0x20(%rbp),%ecx
lea    0xf0c(%rip),%rdx
call   1050 <snprintf@plt>
jmp    1350 <generate_filename+0x200>
mov    -0x38(%rbp),%rdi
mov    -0x18(%rbp),%rsi
sub    $0x1,%rsi
mov    -0x24(%rbp),%ecx
lea    0xeec(%rip),%rdx
call   1050 <snprintf@plt>
jmp    1350 <generate_filename+0x200>
mov    -0x38(%rbp),%rdi
mov    -0x18(%rbp),%rsi
sub    $0x1,%rsi
mov    -0x24(%rbp),%ecx
lea    0xecf(%rip),%rdx
call   1050 <snprintf@plt>
jmp    1350 <generate_filename+0x200>
mov    -0x38(%rbp),%rdi
mov    -0x18(%rbp),%rsi
sub    $0x1,%rsi
mov    -0x24(%rbp),%ecx
lea    0xeb4(%rip),%rdx
call   1050 <snprintf@plt>
jmp    1350 <generate_filename+0x200>
mov    -0x38(%rbp),%rdi
mov    -0x18(%rbp),%rsi
sub    $0x1,%rsi
mov    -0x24(%rbp),%ecx
lea    0xe99(%rip),%rdx
call   1050 <snprintf@plt>
jmp    1350 <generate_filename+0x200>
mov    -0x38(%rbp),%rdi
mov    -0x18(%rbp),%rsi
sub    $0x1,%rsi
mov    -0x24(%rbp),%ecx
lea    0xe7e(%rip),%rdx
call   1050 <snprintf@plt>
jmp    1350 <generate_filename+0x200>
mov    -0x38(%rbp),%rdi
mov    -0x18(%rbp),%rsi
sub    $0x1,%rsi
mov    -0x24(%rbp),%ecx
lea    0xe63(%rip),%rdx
call   1050 <snprintf@plt>
jmp    1350 <generate_filename+0x200>
mov    -0x38(%rbp),%rdi
mov    -0x18(%rbp),%rsi
sub    $0x1,%rsi
mov    -0x24(%rbp),%ecx
lea    0xe48(%rip),%rdx
call   1050 <snprintf@plt>
jmp    1350 <generate_filename+0x200>
mov    -0x38(%rbp),%rdi
mov    -0x18(%rbp),%rsi
sub    $0x1,%rsi
mov    -0x24(%rbp),%ecx
lea    0xe2d(%rip),%rdx
call   1050 <snprintf@plt>
jmp    1350 <generate_filename+0x200>
mov    -0x38(%rbp),%rdi
mov    -0x18(%rbp),%rsi
sub    $0x1,%rsi
mov    -0x24(%rbp),%ecx
lea    0xe12(%rip),%rdx
call   1050 <snprintf@plt>
jmp    1350 <generate_filename+0x200>
mov    -0x30(%rbp),%rax
movsbl 0x1(%rax),%esi
lea    0xdfe(%rip),%rdi
mov    $0x0,%al
call   1070 <die@plt>
mov    -0x38(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rax
mov    -0x18(%rbp),%rcx
sub    $0x1,%rcx
cmp    %rcx,%rax
jb     1380 <generate_filename+0x230>
lea    0xde9(%rip),%rdi
mov    $0x0,%al
call   1070 <die@plt>
mov    -0x48(%rbp),%rax
add    -0x38(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x30(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x30(%rbp)
mov    -0x48(%rbp),%rcx
mov    -0x18(%rbp),%rax
sub    %rcx,%rax
mov    %rax,-0x18(%rbp)
jmp    143f <generate_filename+0x2ef>
cmpq   $0x0,-0x40(%rbp)
jne    13c9 <generate_filename+0x279>
mov    -0x30(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x50(%rbp)
jmp    13d8 <generate_filename+0x288>
mov    -0x40(%rbp),%rax
mov    -0x30(%rbp),%rcx
sub    %rcx,%rax
mov    %rax,-0x50(%rbp)
mov    -0x50(%rbp),%rax
mov    -0x18(%rbp),%rcx
sub    $0x1,%rcx
cmp    %rcx,%rax
jb     13fb <generate_filename+0x2ab>
lea    0xd6e(%rip),%rdi
mov    $0x0,%al
call   1070 <die@plt>
mov    -0x38(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x50(%rbp),%rdx
call   1060 <memcpy@plt>
mov    -0x38(%rbp),%rax
mov    -0x50(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x50(%rbp),%rax
add    -0x38(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x50(%rbp),%rax
add    -0x30(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x50(%rbp),%rcx
mov    -0x18(%rbp),%rax
sub    %rcx,%rax
mov    %rax,-0x18(%rbp)
jmp    1444 <generate_filename+0x2f4>
mov    -0x30(%rbp),%rax
cmpb   $0x0,(%rax)
jne    117f <generate_filename+0x2f>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<generate_filename>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r9d,0xc(%rsp)
mov    %r8d,0x14(%rsp)
mov    %ecx,0x10(%rsp)
mov    %rdx,%r14
mov    %rsi,%r13
mov    %rdi,%rbx
jmp    11ab <generate_filename+0x5b>
nopw   0x0(%rax,%rax,1)
mov    %r13,%rdi
mov    %rbx,%rsi
mov    %rbp,%rdx
call   1060 <memcpy@plt>
movb   $0x0,0x0(%r13,%rbp,1)
add    %rbp,%r13
mov    %rbp,%r12
sub    %r12,%r14
cmpb   $0x0,(%rbx,%rbp,1)
lea    (%rbx,%rbp,1),%rbx
je     132a <generate_filename+0x1da>
mov    %rbx,%rdi
mov    $0x25,%esi
call   1040 <strchr@plt>
cmp    %rax,%rbx
je     11d0 <generate_filename+0x80>
mov    %rax,%rbp
test   %rax,%rax
je     1210 <generate_filename+0xc0>
sub    %rbx,%rbp
jmp    121b <generate_filename+0xcb>
nopw   0x0(%rax,%rax,1)
lea    -0x1(%r14),%r15
movb   $0x0,-0x1(%r13,%r14,1)
movsbl 0x1(%rbx),%esi
lea    -0x31(%rsi),%eax
cmp    $0x46,%eax
ja     12f4 <generate_filename+0x1a4>
lea    0xe0f(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    %r13,%rdi
mov    %r15,%rsi
lea    0xf15(%rip),%rdx
jmp    12c0 <generate_filename+0x170>
nopl   0x0(%rax)
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %rax,%rbp
lea    -0x1(%r14),%rax
cmp    %rax,%rbp
jb     1180 <generate_filename+0x30>
lea    0xf33(%rip),%rdi
xor    %eax,%eax
call   1070 <die@plt>
jmp    1180 <generate_filename+0x30>
mov    %r13,%rdi
mov    %r15,%rsi
lea    0xed7(%rip),%rdx
jmp    12c0 <generate_filename+0x170>
mov    %r13,%rdi
mov    %r15,%rsi
lea    0xecd(%rip),%rdx
jmp    12c0 <generate_filename+0x170>
mov    %r13,%rdi
mov    %r15,%rsi
lea    0xec3(%rip),%rdx
jmp    12c0 <generate_filename+0x170>
mov    %r13,%rdi
mov    %r15,%rsi
lea    0xeb9(%rip),%rdx
jmp    12c0 <generate_filename+0x170>
mov    %r13,%rdi
mov    %r15,%rsi
lea    0xeaf(%rip),%rdx
jmp    12c0 <generate_filename+0x170>
mov    %r13,%rdi
mov    %r15,%rsi
lea    0xea5(%rip),%rdx
jmp    12c0 <generate_filename+0x170>
mov    %r13,%rdi
mov    %r15,%rsi
lea    0xe9b(%rip),%rdx
jmp    12c0 <generate_filename+0x170>
mov    %r13,%rdi
mov    %r15,%rsi
lea    0xe91(%rip),%rdx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    0xc(%rsp),%ecx
call   1050 <snprintf@plt>
mov    %r13,%rdi
call   1030 <strlen@plt>
mov    %rax,%r12
cmp    %r15,%rax
jb     12e7 <generate_filename+0x197>
lea    0xe82(%rip),%rdi
xor    %eax,%eax
call   1070 <die@plt>
add    %r12,%r13
mov    $0x2,%ebp
jmp    119a <generate_filename+0x4a>
lea    0xe4c(%rip),%rdi
xor    %eax,%eax
call   1070 <die@plt>
jmp    12c9 <generate_filename+0x179>
mov    %r13,%rdi
mov    %r15,%rsi
lea    0xe0b(%rip),%rdx
mov    0x14(%rsp),%ecx
jmp    12c4 <generate_filename+0x174>
mov    %r13,%rdi
mov    %r15,%rsi
lea    0xdf8(%rip),%rdx
mov    0x10(%rsp),%ecx
jmp    12c4 <generate_filename+0x174>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@.str.1 = [5 x i8] c"%02d\00"
@.str.2 = [5 x i8] c"%03d\00"
@.str.3 = [5 x i8] c"%04d\00"
@.str.4 = [5 x i8] c"%05d\00"
@.str.5 = [5 x i8] c"%06d\00"
@.str.6 = [5 x i8] c"%07d\00"
@.str.7 = [5 x i8] c"%08d\00"
@.str.8 = [5 x i8] c"%09d\00"
@.str.9 = [27 x i8] c"Unrecognized pattern %%%c\0A\00"
@.str.10 = [27 x i8] c"Output filename too long.\0A\00"
define void @generate_filename(i8* %0, i8* %1, i64 %2, i32 %3, i32 %4, i32 %5) {
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i8*
%14 = alloca i8*
%15 = alloca i8*
%16 = alloca i64
%17 = alloca i64
store i8* %0, i8** %7
store i8* %1, i8** %8
store i64 %2, i64* %9
store i32 %3, i32* %10
store i32 %4, i32* %11
store i32 %5, i32* %12
%18 = load i8*, i8** %7
store i8* %18, i8** %13
%19 = load i8*, i8** %8
store i8* %19, i8** %14
br label %20
20: ; preds = %162, %6
%21 = load i8*, i8** %13
%22 = call i8* @strchr(i8* %21, i8 signext 37)
store i8* %22, i8** %15
%23 = load i8*, i8** %13
%24 = load i8*, i8** %15
%25 = icmp eq i8* %23, %24
br i1 %25, label %26, label %125
26: ; preds = %20
%27 = load i8*, i8** %14
%28 = load i64, i64* %9
%29 = sub i64 %28, 1
%30 = getelementptr inbounds i8, i8* %27, i64 %29
store i8 0, i8* %30
%31 = load i8*, i8** %13
%32 = getelementptr inbounds i8, i8* %31, i64 1
%33 = load i8, i8* %32
%34 = sext i8 %33 to i32
switch i32 %34, label %101 [
i32 119, label %35
i32 104, label %41
i32 49, label %47
i32 50, label %53
i32 51, label %59
i32 52, label %65
i32 53, label %71
i32 54, label %77
i32 55, label %83
i32 56, label %89
i32 57, label %95
]
35: ; preds = %26
%36 = load i8*, i8** %14
%37 = load i64, i64* %9
%38 = sub i64 %37, 1
%39 = load i32, i32* %10
%40 = call i32 @snprintf(i8* %36, i64 %38, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %39)
br label %107
41: ; preds = %26
%42 = load i8*, i8** %14
%43 = load i64, i64* %9
%44 = sub i64 %43, 1
%45 = load i32, i32* %11
%46 = call i32 @snprintf(i8* %42, i64 %44, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %45)
br label %107
47: ; preds = %26
%48 = load i8*, i8** %14
%49 = load i64, i64* %9
%50 = sub i64 %49, 1
%51 = load i32, i32* %12
%52 = call i32 @snprintf(i8* %48, i64 %50, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %51)
br label %107
53: ; preds = %26
%54 = load i8*, i8** %14
%55 = load i64, i64* %9
%56 = sub i64 %55, 1
%57 = load i32, i32* %12
%58 = call i32 @snprintf(i8* %54, i64 %56, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %57)
br label %107
59: ; preds = %26
%60 = load i8*, i8** %14
%61 = load i64, i64* %9
%62 = sub i64 %61, 1
%63 = load i32, i32* %12
%64 = call i32 @snprintf(i8* %60, i64 %62, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %63)
br label %107
65: ; preds = %26
%66 = load i8*, i8** %14
%67 = load i64, i64* %9
%68 = sub i64 %67, 1
%69 = load i32, i32* %12
%70 = call i32 @snprintf(i8* %66, i64 %68, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 %69)
br label %107
71: ; preds = %26
%72 = load i8*, i8** %14
%73 = load i64, i64* %9
%74 = sub i64 %73, 1
%75 = load i32, i32* %12
%76 = call i32 @snprintf(i8* %72, i64 %74, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 %75)
br label %107
77: ; preds = %26
%78 = load i8*, i8** %14
%79 = load i64, i64* %9
%80 = sub i64 %79, 1
%81 = load i32, i32* %12
%82 = call i32 @snprintf(i8* %78, i64 %80, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i32 %81)
br label %107
83: ; preds = %26
%84 = load i8*, i8** %14
%85 = load i64, i64* %9
%86 = sub i64 %85, 1
%87 = load i32, i32* %12
%88 = call i32 @snprintf(i8* %84, i64 %86, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0), i32 %87)
br label %107
89: ; preds = %26
%90 = load i8*, i8** %14
%91 = load i64, i64* %9
%92 = sub i64 %91, 1
%93 = load i32, i32* %12
%94 = call i32 @snprintf(i8* %90, i64 %92, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0), i32 %93)
br label %107
95: ; preds = %26
%96 = load i8*, i8** %14
%97 = load i64, i64* %9
%98 = sub i64 %97, 1
%99 = load i32, i32* %12
%100 = call i32 @snprintf(i8* %96, i64 %98, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0), i32 %99)
br label %107
101: ; preds = %26
%102 = load i8*, i8** %13
%103 = getelementptr inbounds i8, i8* %102, i64 1
%104 = load i8, i8* %103
%105 = sext i8 %104 to i32
%106 = call i32 (i8*, ...) @die(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.9, i64 0, i64 0), i32 %105)
br label %107
107: ; preds = %101, %95, %89, %83, %77, %71, %65, %59, %53, %47, %41, %35
%108 = load i8*, i8** %14
%109 = call i64 @strlen(i8* %108)
store i64 %109, i64* %16
%110 = load i64, i64* %16
%111 = load i64, i64* %9
%112 = sub i64 %111, 1
%113 = icmp uge i64 %110, %112
br i1 %113, label %114, label %116
114: ; preds = %107
%115 = call i32 (i8*, ...) @die(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.10, i64 0, i64 0))
br label %116
116: ; preds = %114, %107
%117 = load i64, i64* %16
%118 = load i8*, i8** %14
%119 = getelementptr inbounds i8, i8* %118, i64 %117
store i8* %119, i8** %14
%120 = load i8*, i8** %13
%121 = getelementptr inbounds i8, i8* %120, i64 2
store i8* %121, i8** %13
%122 = load i64, i64* %16
%123 = load i64, i64* %9
%124 = sub i64 %123, %122
store i64 %124, i64* %9
br label %161
125: ; preds = %20
%126 = load i8*, i8** %15
%127 = icmp ne i8* %126, null
br i1 %127, label %131, label %128
128: ; preds = %125
%129 = load i8*, i8** %13
%130 = call i64 @strlen(i8* %129)
store i64 %130, i64* %17
br label %137
131: ; preds = %125
%132 = load i8*, i8** %15
%133 = load i8*, i8** %13
%134 = ptrtoint i8* %132 to i64
%135 = ptrtoint i8* %133 to i64
%136 = sub i64 %134, %135
store i64 %136, i64* %17
br label %137
137: ; preds = %131, %128
%138 = load i64, i64* %17
%139 = load i64, i64* %9
%140 = sub i64 %139, 1
%141 = icmp uge i64 %138, %140
br i1 %141, label %142, label %144
142: ; preds = %137
%143 = call i32 (i8*, ...) @die(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.10, i64 0, i64 0))
br label %144
144: ; preds = %142, %137
%145 = load i8*, i8** %14
%146 = load i8*, i8** %13
%147 = load i64, i64* %17
%148 = call i32 @memcpy(i8* %145, i8* %146, i64 %147)
%149 = load i8*, i8** %14
%150 = load i64, i64* %17
%151 = getelementptr inbounds i8, i8* %149, i64 %150
store i8 0, i8* %151
%152 = load i64, i64* %17
%153 = load i8*, i8** %14
%154 = getelementptr inbounds i8, i8* %153, i64 %152
store i8* %154, i8** %14
%155 = load i64, i64* %17
%156 = load i8*, i8** %13
%157 = getelementptr inbounds i8, i8* %156, i64 %155
store i8* %157, i8** %13
%158 = load i64, i64* %17
%159 = load i64, i64* %9
%160 = sub i64 %159, %158
store i64 %160, i64* %9
br label %161
161: ; preds = %144, %116
br label %162
162: ; preds = %161
%163 = load i8*, i8** %13
%164 = load i8, i8* %163
%165 = icmp ne i8 %164, 0
br i1 %165, label %20, label %166
166: ; preds = %162
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@.str.1 = [5 x i8] c"%02d\00"
@.str.2 = [5 x i8] c"%03d\00"
@.str.3 = [5 x i8] c"%04d\00"
@.str.4 = [5 x i8] c"%05d\00"
@.str.5 = [5 x i8] c"%06d\00"
@.str.6 = [5 x i8] c"%07d\00"
@.str.7 = [5 x i8] c"%08d\00"
@.str.8 = [5 x i8] c"%09d\00"
@.str.9 = [27 x i8] c"Unrecognized pattern %%%c\0A\00"
@.str.10 = [27 x i8] c"Output filename too long.\0A\00"
define void @generate_filename(i8* %0, i8* %1, i64 %2, i32 %3, i32 %4, i32 %5) {
br label %7
7: ; preds = %67, %6
%8 = phi i8* [ %1, %6 ], [ %69, %67 ]
%9 = phi i8* [ %0, %6 ], [ %71, %67 ]
%10 = phi i64 [ %2, %6 ], [ %72, %67 ]
%11 = tail call i8* @strchr(i8* dereferenceable(1) %9, i8 signext 37)
%12 = icmp eq i8* %9, %11
br i1 %12, label %13, label %50
13: ; preds = %7
%14 = add i64 %10, -1
%15 = getelementptr inbounds i8, i8* %8, i64 %14
store i8 0, i8* %15
%16 = getelementptr inbounds i8, i8* %9, i64 1
%17 = load i8, i8* %16
%18 = sext i8 %17 to i32
switch i32 %18, label %41 [
i32 119, label %19
i32 104, label %21
i32 49, label %23
i32 50, label %25
i32 51, label %27
i32 52, label %29
i32 53, label %31
i32 54, label %33
i32 55, label %35
i32 56, label %37
i32 57, label %39
]
19: ; preds = %13
%20 = tail call i32 @snprintf(i8* %8, i64 %14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %3)
br label %43
21: ; preds = %13
%22 = tail call i32 @snprintf(i8* %8, i64 %14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %4)
br label %43
23: ; preds = %13
%24 = tail call i32 @snprintf(i8* %8, i64 %14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %5)
br label %43
25: ; preds = %13
%26 = tail call i32 @snprintf(i8* %8, i64 %14, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %5)
br label %43
27: ; preds = %13
%28 = tail call i32 @snprintf(i8* %8, i64 %14, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %5)
br label %43
29: ; preds = %13
%30 = tail call i32 @snprintf(i8* %8, i64 %14, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 %5)
br label %43
31: ; preds = %13
%32 = tail call i32 @snprintf(i8* %8, i64 %14, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 %5)
br label %43
33: ; preds = %13
%34 = tail call i32 @snprintf(i8* %8, i64 %14, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i32 %5)
br label %43
35: ; preds = %13
%36 = tail call i32 @snprintf(i8* %8, i64 %14, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0), i32 %5)
br label %43
37: ; preds = %13
%38 = tail call i32 @snprintf(i8* %8, i64 %14, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0), i32 %5)
br label %43
39: ; preds = %13
%40 = tail call i32 @snprintf(i8* %8, i64 %14, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0), i32 %5)
br label %43
41: ; preds = %13
%42 = tail call i32 (i8*, ...) @die(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.9, i64 0, i64 0), i32 %18)
br label %43
43: ; preds = %41, %39, %37, %35, %33, %31, %29, %27, %25, %23, %21, %19
%44 = tail call i64 @strlen(i8* dereferenceable(1) %8)
%45 = icmp ult i64 %44, %14
br i1 %45, label %48, label %46
46: ; preds = %43
%47 = tail call i32 (i8*, ...) @die(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.10, i64 0, i64 0))
br label %48
48: ; preds = %46, %43
%49 = getelementptr inbounds i8, i8* %8, i64 %44
br label %67
50: ; preds = %7
%51 = icmp eq i8* %11, null
br i1 %51, label %52, label %54
52: ; preds = %50
%53 = tail call i64 @strlen(i8* dereferenceable(1) %9)
br label %58
54: ; preds = %50
%55 = ptrtoint i8* %11 to i64
%56 = ptrtoint i8* %9 to i64
%57 = sub i64 %55, %56
br label %58
58: ; preds = %54, %52
%59 = phi i64 [ %57, %54 ], [ %53, %52 ]
%60 = add i64 %10, -1
%61 = icmp ult i64 %59, %60
br i1 %61, label %64, label %62
62: ; preds = %58
%63 = tail call i32 (i8*, ...) @die(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.10, i64 0, i64 0))
br label %64
64: ; preds = %62, %58
%65 = tail call i32 @memcpy(i8* %8, i8* %9, i64 %59)
%66 = getelementptr inbounds i8, i8* %8, i64 %59
store i8 0, i8* %66
br label %67
67: ; preds = %64, %48
%68 = phi i64 [ %59, %64 ], [ 2, %48 ]
%69 = phi i8* [ %66, %64 ], [ %49, %48 ]
%70 = phi i64 [ %59, %64 ], [ %44, %48 ]
%71 = getelementptr inbounds i8, i8* %9, i64 %68
%72 = sub i64 %10, %70
%73 = load i8, i8* %71
%74 = icmp eq i8 %73, 0
br i1 %74, label %75, label %7
75: ; preds = %67
ret void
}