#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*/ io_error_msg(char *, int, int);
int /*<<< orphan*/ sprintf(char *, char *, ...);
char *fmt_to_str(int format, int precision) {
  char *ptr;
  static char buf[30];
  char nbuf[10];
  nbuf[0] = '\0';
  switch (format) {
  case 6:
    ptr = "user-";
    sprintf(nbuf, "%d", precision + 1);
    break;
  case 9:
    ptr = "general.";
    sprintf(nbuf, "%d", precision);
    break;
  case 3:
    ptr = "dollar.";
    sprintf(nbuf, "%d", precision);
    break;
  case 4:
    ptr = "comma.";
    sprintf(nbuf, "%d", precision);
    break;
  case 5:
    ptr = "percent.";
    sprintf(nbuf, "%d", precision);
    break;
  case 7:
    if (precision == 0)
      return "integer";
    ptr = "fixed.";
    sprintf(nbuf, "%d", precision);
    break;
  case 8:
    ptr = "exponent.";
    sprintf(nbuf, "%d", precision);
    break;
  default:
    io_error_msg("Unknown format %d (%x)", format, format);
    ptr = "UNKNOWN";
    break;
  }
  sprintf(buf, "%s%s", ptr, nbuf);
  return buf;
}


x86 assembly (clang, -O0):
<fmt_to_str>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0xc(%rbp)
mov    %esi,-0x10(%rbp)
movb   $0x0,-0x22(%rbp)
mov    -0xc(%rbp),%eax
add    $0xfffffffd,%eax
mov    %eax,%ecx
mov    %rcx,-0x30(%rbp)
sub    $0x6,%eax
ja     127b <fmt_to_str+0x15b>
mov    -0x30(%rbp),%rax
lea    0xeae(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xeba(%rip),%rax
mov    %rax,-0x18(%rbp)
lea    -0x22(%rbp),%rdi
mov    -0x10(%rbp),%edx
add    $0x1,%edx
lea    0xeab(%rip),%rsi
mov    $0x0,%al
call   1040 <sprintf@plt>
jmp    1298 <fmt_to_str+0x178>
lea    0xe9b(%rip),%rax
mov    %rax,-0x18(%rbp)
lea    -0x22(%rbp),%rdi
mov    -0x10(%rbp),%edx
lea    0xe86(%rip),%rsi
mov    $0x0,%al
call   1040 <sprintf@plt>
jmp    1298 <fmt_to_str+0x178>
lea    0xe7f(%rip),%rax
mov    %rax,-0x18(%rbp)
lea    -0x22(%rbp),%rdi
mov    -0x10(%rbp),%edx
lea    0xe61(%rip),%rsi
mov    $0x0,%al
call   1040 <sprintf@plt>
jmp    1298 <fmt_to_str+0x178>
lea    0xe62(%rip),%rax
mov    %rax,-0x18(%rbp)
lea    -0x22(%rbp),%rdi
mov    -0x10(%rbp),%edx
lea    0xe3c(%rip),%rsi
mov    $0x0,%al
call   1040 <sprintf@plt>
jmp    1298 <fmt_to_str+0x178>
lea    0xe44(%rip),%rax
mov    %rax,-0x18(%rbp)
lea    -0x22(%rbp),%rdi
mov    -0x10(%rbp),%edx
lea    0xe17(%rip),%rsi
mov    $0x0,%al
call   1040 <sprintf@plt>
jmp    1298 <fmt_to_str+0x178>
cmpl   $0x0,-0x10(%rbp)
jne    1231 <fmt_to_str+0x111>
lea    0xe1e(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    12c0 <fmt_to_str+0x1a0>
lea    0xe16(%rip),%rax
mov    %rax,-0x18(%rbp)
lea    -0x22(%rbp),%rdi
mov    -0x10(%rbp),%edx
lea    0xdd8(%rip),%rsi
mov    $0x0,%al
call   1040 <sprintf@plt>
jmp    1298 <fmt_to_str+0x178>
lea    0xdf8(%rip),%rax
mov    %rax,-0x18(%rbp)
lea    -0x22(%rbp),%rdi
mov    -0x10(%rbp),%edx
lea    0xdb3(%rip),%rsi
mov    $0x0,%al
call   1040 <sprintf@plt>
jmp    1298 <fmt_to_str+0x178>
mov    -0xc(%rbp),%esi
mov    -0xc(%rbp),%edx
lea    0xdd7(%rip),%rdi
call   1030 <io_error_msg@plt>
lea    0xde2(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdx
lea    -0x22(%rbp),%rcx
lea    0x2d99(%rip),%rdi
lea    0xdd0(%rip),%rsi
mov    $0x0,%al
call   1040 <sprintf@plt>
lea    0x2d84(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fmt_to_str>:
push   %rbx
sub    $0x10,%rsp
mov    %esi,%edx
mov    %edi,%esi
movb   $0x0,0x6(%rsp)
lea    -0x3(%rsi),%eax
cmp    $0x6,%eax
ja     1165 <fmt_to_str+0x45>
lea    0xec3(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xed5(%rip),%rsi
lea    0x6(%rsp),%rdi
xor    %eax,%eax
call   1040 <sprintf@plt>
lea    0xece(%rip),%rdx
jmp    122f <fmt_to_str+0x10f>
lea    0xef3(%rip),%rdi
mov    %esi,%edx
call   1030 <io_error_msg@plt>
lea    0xefc(%rip),%rdx
jmp    122f <fmt_to_str+0x10f>
lea    0xe9c(%rip),%rsi
lea    0x6(%rsp),%rdi
xor    %eax,%eax
call   1040 <sprintf@plt>
lea    0xe9d(%rip),%rdx
jmp    122f <fmt_to_str+0x10f>
lea    0xe7d(%rip),%rsi
lea    0x6(%rsp),%rdi
xor    %eax,%eax
call   1040 <sprintf@plt>
lea    0xe85(%rip),%rdx
jmp    122f <fmt_to_str+0x10f>
add    $0x1,%edx
lea    0xe5e(%rip),%rsi
lea    0x6(%rsp),%rdi
xor    %eax,%eax
call   1040 <sprintf@plt>
lea    0xe45(%rip),%rdx
jmp    122f <fmt_to_str+0x10f>
test   %edx,%edx
je     1255 <fmt_to_str+0x135>
lea    0xe3e(%rip),%rsi
lea    0x6(%rsp),%rdi
xor    %eax,%eax
call   1040 <sprintf@plt>
lea    0xe57(%rip),%rdx
jmp    122f <fmt_to_str+0x10f>
lea    0xe22(%rip),%rsi
lea    0x6(%rsp),%rdi
xor    %eax,%eax
call   1040 <sprintf@plt>
lea    0xe42(%rip),%rdx
jmp    122f <fmt_to_str+0x10f>
lea    0xe06(%rip),%rsi
lea    0x6(%rsp),%rdi
xor    %eax,%eax
call   1040 <sprintf@plt>
lea    0xdf6(%rip),%rdx
lea    0x2e0a(%rip),%rbx
lea    0xe41(%rip),%rsi
lea    0x6(%rsp),%rcx
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <sprintf@plt>
mov    %rbx,%rax
add    $0x10,%rsp
pop    %rbx
ret
lea    0xdea(%rip),%rbx
jmp    124c <fmt_to_str+0x12c>

LLVM IR (-O0):
@fmt_to_str.buf = internal global [30 x i8] zeroinitializer
@.str = [6 x i8] c"user-\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [9 x i8] c"general.\00"
@.str.3 = [8 x i8] c"dollar.\00"
@.str.4 = [7 x i8] c"comma.\00"
@.str.5 = [9 x i8] c"percent.\00"
@.str.6 = [8 x i8] c"integer\00"
@.str.7 = [7 x i8] c"fixed.\00"
@.str.8 = [10 x i8] c"exponent.\00"
@.str.9 = [23 x i8] c"Unknown format %d (%x)\00"
@.str.10 = [8 x i8] c"UNKNOWN\00"
@.str.11 = [5 x i8] c"%s%s\00"
define i8* @fmt_to_str(i32 %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca [10 x i8]
store i32 %0, i32* %4
store i32 %1, i32* %5
%8 = getelementptr inbounds [10 x i8], [10 x i8]* %7, i64 0, i64 0
store i8 0, i8* %8
%9 = load i32, i32* %4
switch i32 %9, label %43 [
i32 6, label %10
i32 9, label %15
i32 3, label %19
i32 4, label %23
i32 5, label %27
i32 7, label %31
i32 8, label %39
]
10: ; preds = %2
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8** %6
%11 = getelementptr inbounds [10 x i8], [10 x i8]* %7, i64 0, i64 0
%12 = load i32, i32* %5
%13 = add nsw i32 %12, 1
%14 = call i32 (i8*, i8*, ...) @sprintf(i8* %11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %13)
br label %47
15: ; preds = %2
store i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8** %6
%16 = getelementptr inbounds [10 x i8], [10 x i8]* %7, i64 0, i64 0
%17 = load i32, i32* %5
%18 = call i32 (i8*, i8*, ...) @sprintf(i8* %16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %17)
br label %47
19: ; preds = %2
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i8** %6
%20 = getelementptr inbounds [10 x i8], [10 x i8]* %7, i64 0, i64 0
%21 = load i32, i32* %5
%22 = call i32 (i8*, i8*, ...) @sprintf(i8* %20, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %21)
br label %47
23: ; preds = %2
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i8** %6
%24 = getelementptr inbounds [10 x i8], [10 x i8]* %7, i64 0, i64 0
%25 = load i32, i32* %5
%26 = call i32 (i8*, i8*, ...) @sprintf(i8* %24, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %25)
br label %47
27: ; preds = %2
store i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i8** %6
%28 = getelementptr inbounds [10 x i8], [10 x i8]* %7, i64 0, i64 0
%29 = load i32, i32* %5
%30 = call i32 (i8*, i8*, ...) @sprintf(i8* %28, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %29)
br label %47
31: ; preds = %2
%32 = load i32, i32* %5
%33 = icmp eq i32 %32, 0
br i1 %33, label %34, label %35
34: ; preds = %31
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0), i8** %3
br label %51
35: ; preds = %31
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0), i8** %6
%36 = getelementptr inbounds [10 x i8], [10 x i8]* %7, i64 0, i64 0
%37 = load i32, i32* %5
%38 = call i32 (i8*, i8*, ...) @sprintf(i8* %36, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %37)
br label %47
39: ; preds = %2
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.8, i64 0, i64 0), i8** %6
%40 = getelementptr inbounds [10 x i8], [10 x i8]* %7, i64 0, i64 0
%41 = load i32, i32* %5
%42 = call i32 (i8*, i8*, ...) @sprintf(i8* %40, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %41)
br label %47
43: ; preds = %2
%44 = load i32, i32* %4
%45 = load i32, i32* %4
%46 = call i32 @io_error_msg(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.9, i64 0, i64 0), i32 %44, i32 %45)
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.10, i64 0, i64 0), i8** %6
br label %47
47: ; preds = %43, %39, %35, %27, %23, %19, %15, %10
%48 = load i8*, i8** %6
%49 = getelementptr inbounds [10 x i8], [10 x i8]* %7, i64 0, i64 0
%50 = call i32 (i8*, i8*, ...) @sprintf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @fmt_to_str.buf, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.11, i64 0, i64 0), i8* %48, i8* %49)
store i8* getelementptr inbounds ([30 x i8], [30 x i8]* @fmt_to_str.buf, i64 0, i64 0), i8** %3
br label %51
51: ; preds = %47, %34
%52 = load i8*, i8** %3
ret i8* %52
}

LLVM IR (-O2):
@fmt_to_str.buf = internal global [30 x i8] zeroinitializer
@.str = [6 x i8] c"user-\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [9 x i8] c"general.\00"
@.str.3 = [8 x i8] c"dollar.\00"
@.str.4 = [7 x i8] c"comma.\00"
@.str.5 = [9 x i8] c"percent.\00"
@.str.6 = [8 x i8] c"integer\00"
@.str.7 = [7 x i8] c"fixed.\00"
@.str.8 = [10 x i8] c"exponent.\00"
@.str.9 = [23 x i8] c"Unknown format %d (%x)\00"
@.str.10 = [8 x i8] c"UNKNOWN\00"
@.str.11 = [5 x i8] c"%s%s\00"
define i8* @fmt_to_str(i32 %0, i32 %1) {
%3 = alloca [10 x i8]
%4 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
store i8 0, i8* %4
switch i32 %0, label %22 [
i32 6, label %5
i32 9, label %8
i32 3, label %10
i32 4, label %12
i32 5, label %14
i32 7, label %16
i32 8, label %20
]
5: ; preds = %2
%6 = add nsw i32 %1, 1
%7 = call i32 (i8*, i8*, ...) @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %6)
br label %24
8: ; preds = %2
%9 = call i32 (i8*, i8*, ...) @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %1)
br label %24
10: ; preds = %2
%11 = call i32 (i8*, i8*, ...) @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %1)
br label %24
12: ; preds = %2
%13 = call i32 (i8*, i8*, ...) @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %1)
br label %24
14: ; preds = %2
%15 = call i32 (i8*, i8*, ...) @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %1)
br label %24
16: ; preds = %2
%17 = icmp eq i32 %1, 0
br i1 %17, label %27, label %18
18: ; preds = %16
%19 = call i32 (i8*, i8*, ...) @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %1)
br label %24
20: ; preds = %2
%21 = call i32 (i8*, i8*, ...) @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %1)
br label %24
22: ; preds = %2
%23 = tail call i32 @io_error_msg(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.9, i64 0, i64 0), i32 %0, i32 %0)
br label %24
24: ; preds = %22, %20, %18, %14, %12, %10, %8, %5
%25 = phi i8* [ getelementptr inbounds ([8 x i8], [8 x i8]* @.str.10, i64 0, i64 0), %22 ], [ getelementptr inbounds ([10 x i8], [10 x i8]* @.str.8, i64 0, i64 0), %20 ], [ getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0), %18 ], [ getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), %14 ], [ getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), %12 ], [ getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), %10 ], [ getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), %8 ], [ getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), %5 ]
%26 = call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @fmt_to_str.buf, i64 0, i64 0), i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.11, i64 0, i64 0), i8* %25, i8* %4)
br label %27
27: ; preds = %16, %24
%28 = phi i8* [ getelementptr inbounds ([30 x i8], [30 x i8]* @fmt_to_str.buf, i64 0, i64 0), %24 ], [ getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0), %16 ]
ret i8* %28
}