#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 */
double atof(char const *);
int atoi(char const *);
int /*<<< orphan*/ fputs(char const *, int /*<<< orphan*/);
int /*<<< orphan*/ print(char const *, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, double);
int /*<<< orphan*/ putchar(char const);
int /*<<< orphan*/ stdout;
void handle_formatter(int c, const char *arg) {
  switch (c) {
  case '%':
    putchar('%');
    break;
  case 'b':
    print(arg, NULL);
    break;
  case 'd':
  case 'i':
    printf("%d", atoi(arg));
    break;
  case 'o':
    printf("%o", atoi(arg));
    break;
  case 'u':
    printf("%u", atoi(arg));
    break;
  case 'x':
    printf("%x", atoi(arg));
    break;
  case 'X':
    printf("%X", atoi(arg));
    break;
  case 'f':
  case 'F':
    printf("%f", atof(arg));
    break;
  case 'e':
    printf("%e", atof(arg));
    break;
  case 'E':
    printf("%E", atof(arg));
    break;
  case 'g':
    printf("%g", atof(arg));
    break;
  case 'G':
    printf("%G", atof(arg));
    break;
  case 'c':
    putchar(arg[0]);
    break;
  case 's':
    fputs(arg, stdout);
    break;
  default:
    break;
  }
}


x86 assembly (clang, -O0):
<handle_formatter>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x4(%rbp),%eax
add    $0xffffffdb,%eax
mov    %eax,%ecx
mov    %rcx,-0x18(%rbp)
sub    $0x53,%eax
ja     12f9 <handle_formatter+0x199>
mov    -0x18(%rbp),%rax
lea    0xe71(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    $0x25,%edi
call   1030 <putchar@plt>
jmp    12fe <handle_formatter+0x19e>
mov    -0x10(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1070 <print@plt>
jmp    12fe <handle_formatter+0x19e>
mov    -0x10(%rbp),%rdi
call   1080 <atoi@plt>
cvtsi2sd %eax,%xmm0
lea    0xf83(%rip),%rdi
call   1050 <printf@plt>
jmp    12fe <handle_formatter+0x19e>
mov    -0x10(%rbp),%rdi
call   1080 <atoi@plt>
cvtsi2sd %eax,%xmm0
lea    0xf68(%rip),%rdi
call   1050 <printf@plt>
jmp    12fe <handle_formatter+0x19e>
mov    -0x10(%rbp),%rdi
call   1080 <atoi@plt>
cvtsi2sd %eax,%xmm0
lea    0xf4d(%rip),%rdi
call   1050 <printf@plt>
jmp    12fe <handle_formatter+0x19e>
mov    -0x10(%rbp),%rdi
call   1080 <atoi@plt>
cvtsi2sd %eax,%xmm0
lea    0xf32(%rip),%rdi
call   1050 <printf@plt>
jmp    12fe <handle_formatter+0x19e>
mov    -0x10(%rbp),%rdi
call   1080 <atoi@plt>
cvtsi2sd %eax,%xmm0
lea    0xf17(%rip),%rdi
call   1050 <printf@plt>
jmp    12fe <handle_formatter+0x19e>
mov    -0x10(%rbp),%rdi
call   1040 <atof@plt>
lea    0xf00(%rip),%rdi
call   1050 <printf@plt>
jmp    12fe <handle_formatter+0x19e>
mov    -0x10(%rbp),%rdi
call   1040 <atof@plt>
lea    0xee9(%rip),%rdi
call   1050 <printf@plt>
jmp    12fe <handle_formatter+0x19e>
mov    -0x10(%rbp),%rdi
call   1040 <atof@plt>
lea    0xed2(%rip),%rdi
call   1050 <printf@plt>
jmp    12fe <handle_formatter+0x19e>
mov    -0x10(%rbp),%rdi
call   1040 <atof@plt>
lea    0xebb(%rip),%rdi
call   1050 <printf@plt>
jmp    12fe <handle_formatter+0x19e>
mov    -0x10(%rbp),%rdi
call   1040 <atof@plt>
lea    0xea4(%rip),%rdi
call   1050 <printf@plt>
jmp    12fe <handle_formatter+0x19e>
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1030 <putchar@plt>
jmp    12fe <handle_formatter+0x19e>
mov    -0x10(%rbp),%rdi
mov    0x2cf3(%rip),%rax
mov    (%rax),%esi
call   1060 <fputs@plt>
jmp    12fe <handle_formatter+0x19e>
jmp    12fe <handle_formatter+0x19e>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<handle_formatter>:
push   %rax
add    $0xffffffdb,%edi
cmp    $0x53,%edi
ja     11b2 <handle_formatter+0x52>
lea    0xe90(%rip),%rax
movslq (%rax,%rdi,4),%rcx
add    %rax,%rcx
jmp    *%rcx
mov    %rsi,%rdi
call   1040 <atof@plt>
lea    0xfd7(%rip),%rdi
pop    %rax
jmp    1050 <printf@plt>
mov    %rsi,%rdi
call   1080 <atoi@plt>
cvtsi2sd %eax,%xmm0
lea    0xfaf(%rip),%rdi
pop    %rax
jmp    1050 <printf@plt>
mov    $0x25,%edi
pop    %rax
jmp    1030 <putchar@plt>
pop    %rax
ret
mov    %rsi,%rdi
call   1040 <atof@plt>
lea    0xfa2(%rip),%rdi
pop    %rax
jmp    1050 <printf@plt>
mov    %rsi,%rdi
call   1040 <atof@plt>
lea    0xf93(%rip),%rdi
pop    %rax
jmp    1050 <printf@plt>
mov    %rsi,%rdi
call   1080 <atoi@plt>
cvtsi2sd %eax,%xmm0
lea    0xf6b(%rip),%rdi
pop    %rax
jmp    1050 <printf@plt>
mov    %rsi,%rdi
xor    %esi,%esi
pop    %rax
jmp    1070 <print@plt>
movsbl (%rsi),%edi
pop    %rax
jmp    1030 <putchar@plt>
mov    %rsi,%rdi
call   1040 <atof@plt>
lea    0xf48(%rip),%rdi
pop    %rax
jmp    1050 <printf@plt>
mov    %rsi,%rdi
call   1040 <atof@plt>
lea    0xf39(%rip),%rdi
pop    %rax
jmp    1050 <printf@plt>
mov    %rsi,%rdi
call   1080 <atoi@plt>
cvtsi2sd %eax,%xmm0
lea    0xf0b(%rip),%rdi
pop    %rax
jmp    1050 <printf@plt>
mov    0x2d8b(%rip),%rax
mov    (%rax),%eax
mov    %rsi,%rdi
mov    %eax,%esi
pop    %rax
jmp    1060 <fputs@plt>
mov    %rsi,%rdi
call   1080 <atoi@plt>
cvtsi2sd %eax,%xmm0
lea    0xee1(%rip),%rdi
pop    %rax
jmp    1050 <printf@plt>
mov    %rsi,%rdi
call   1080 <atoi@plt>
cvtsi2sd %eax,%xmm0
lea    0xecb(%rip),%rdi
pop    %rax
jmp    1050 <printf@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@.str.1 = [3 x i8] c"%o\00"
@.str.2 = [3 x i8] c"%u\00"
@.str.3 = [3 x i8] c"%x\00"
@.str.4 = [3 x i8] c"%X\00"
@.str.5 = [3 x i8] c"%f\00"
@.str.6 = [3 x i8] c"%e\00"
@.str.7 = [3 x i8] c"%E\00"
@.str.8 = [3 x i8] c"%g\00"
@.str.9 = [3 x i8] c"%G\00"
@stdout = global i32 0
define void @handle_formatter(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
store i32 %0, i32* %3
store i8* %1, i8** %4
%5 = load i32, i32* %3
switch i32 %5, label %65 [
i32 37, label %6
i32 98, label %8
i32 100, label %11
i32 105, label %11
i32 111, label %16
i32 117, label %21
i32 120, label %26
i32 88, label %31
i32 102, label %36
i32 70, label %36
i32 101, label %40
i32 69, label %44
i32 103, label %48
i32 71, label %52
i32 99, label %56
i32 115, label %61
]
6: ; preds = %2
%7 = call i32 @putchar(i8 signext 37)
br label %66
8: ; preds = %2
%9 = load i8*, i8** %4
%10 = call i32 @print(i8* %9, i32* null)
br label %66
11: ; preds = %2, %2
%12 = load i8*, i8** %4
%13 = call i32 @atoi(i8* %12)
%14 = sitofp i32 %13 to double
%15 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), double %14)
br label %66
16: ; preds = %2
%17 = load i8*, i8** %4
%18 = call i32 @atoi(i8* %17)
%19 = sitofp i32 %18 to double
%20 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), double %19)
br label %66
21: ; preds = %2
%22 = load i8*, i8** %4
%23 = call i32 @atoi(i8* %22)
%24 = sitofp i32 %23 to double
%25 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), double %24)
br label %66
26: ; preds = %2
%27 = load i8*, i8** %4
%28 = call i32 @atoi(i8* %27)
%29 = sitofp i32 %28 to double
%30 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), double %29)
br label %66
31: ; preds = %2
%32 = load i8*, i8** %4
%33 = call i32 @atoi(i8* %32)
%34 = sitofp i32 %33 to double
%35 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), double %34)
br label %66
36: ; preds = %2, %2
%37 = load i8*, i8** %4
%38 = call double @atof(i8* %37)
%39 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), double %38)
br label %66
40: ; preds = %2
%41 = load i8*, i8** %4
%42 = call double @atof(i8* %41)
%43 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), double %42)
br label %66
44: ; preds = %2
%45 = load i8*, i8** %4
%46 = call double @atof(i8* %45)
%47 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), double %46)
br label %66
48: ; preds = %2
%49 = load i8*, i8** %4
%50 = call double @atof(i8* %49)
%51 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0), double %50)
br label %66
52: ; preds = %2
%53 = load i8*, i8** %4
%54 = call double @atof(i8* %53)
%55 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.9, i64 0, i64 0), double %54)
br label %66
56: ; preds = %2
%57 = load i8*, i8** %4
%58 = getelementptr inbounds i8, i8* %57, i64 0
%59 = load i8, i8* %58
%60 = call i32 @putchar(i8 signext %59)
br label %66
61: ; preds = %2
%62 = load i8*, i8** %4
%63 = load i32, i32* @stdout
%64 = call i32 @fputs(i8* %62, i32 %63)
br label %66
65: ; preds = %2
br label %66
66: ; preds = %65, %61, %56, %52, %48, %44, %40, %36, %31, %26, %21, %16, %11, %8, %6
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@.str.1 = [3 x i8] c"%o\00"
@.str.2 = [3 x i8] c"%u\00"
@.str.3 = [3 x i8] c"%x\00"
@.str.4 = [3 x i8] c"%X\00"
@.str.5 = [3 x i8] c"%f\00"
@.str.6 = [3 x i8] c"%e\00"
@.str.7 = [3 x i8] c"%E\00"
@.str.8 = [3 x i8] c"%g\00"
@.str.9 = [3 x i8] c"%G\00"
@stdout = global i32 0
define void @handle_formatter(i32 %0, i8* %1) {
switch i32 %0, label %48 [
i32 37, label %3
i32 98, label %5
i32 100, label %7
i32 105, label %7
i32 111, label %11
i32 117, label %15
i32 120, label %19
i32 88, label %23
i32 102, label %27
i32 70, label %27
i32 101, label %30
i32 69, label %33
i32 103, label %36
i32 71, label %39
i32 99, label %42
i32 115, label %45
]
3: ; preds = %2
%4 = tail call i32 @putchar(i8 signext 37)
br label %48
5: ; preds = %2
%6 = tail call i32 @print(i8* %1, i32* null)
br label %48
7: ; preds = %2, %2
%8 = tail call i32 @atoi(i8* %1)
%9 = sitofp i32 %8 to double
%10 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), double %9)
br label %48
11: ; preds = %2
%12 = tail call i32 @atoi(i8* %1)
%13 = sitofp i32 %12 to double
%14 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), double %13)
br label %48
15: ; preds = %2
%16 = tail call i32 @atoi(i8* %1)
%17 = sitofp i32 %16 to double
%18 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), double %17)
br label %48
19: ; preds = %2
%20 = tail call i32 @atoi(i8* %1)
%21 = sitofp i32 %20 to double
%22 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), double %21)
br label %48
23: ; preds = %2
%24 = tail call i32 @atoi(i8* %1)
%25 = sitofp i32 %24 to double
%26 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), double %25)
br label %48
27: ; preds = %2, %2
%28 = tail call double @atof(i8* %1)
%29 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), double %28)
br label %48
30: ; preds = %2
%31 = tail call double @atof(i8* %1)
%32 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), double %31)
br label %48
33: ; preds = %2
%34 = tail call double @atof(i8* %1)
%35 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), double %34)
br label %48
36: ; preds = %2
%37 = tail call double @atof(i8* %1)
%38 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0), double %37)
br label %48
39: ; preds = %2
%40 = tail call double @atof(i8* %1)
%41 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.9, i64 0, i64 0), double %40)
br label %48
42: ; preds = %2
%43 = load i8, i8* %1
%44 = tail call i32 @putchar(i8 signext %43)
br label %48
45: ; preds = %2
%46 = load i32, i32* @stdout
%47 = tail call i32 @fputs(i8* %1, i32 %46)
br label %48
48: ; preds = %2, %45, %42, %39, %36, %33, %30, %27, %23, %19, %15, %11, %7, %5, %3
ret void
}