#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*/ itoa(int, char *, char);
int /*<<< orphan*/ putchar(int);
void printf(const char *format, ...) {
  char **arg = (char **)&format;
  int c;
  char buf[20];
  *arg++;
  while ((c = *format++) != 0) {
    if (c != '%') {
      putchar(c);
    } else {
      char *p;
      c = *format++;
      switch (c) {
      case 'i':
      case 'd':
        itoa(*((int *)arg++), buf, 'd');
        p = buf;
        goto string;
        break;
      case 'u':
      case 'x':
        itoa(*((int *)arg++), buf, 'x');
        p = buf;
        goto string;
        break;
      case 's':
        p = *arg++;
        if (!p) {
          p = "(null)";
        }
      string:
        while (*p)
          putchar(*p++);
        break;
      }
    }
  }
}


x86 assembly (clang, -O0):
<printf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movsbl (%rax),%eax
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
je     1279 <printf+0x159>
cmpl   $0x25,-0x14(%rbp)
je     1175 <printf+0x55>
mov    -0x14(%rbp),%edi
call   1030 <putchar@plt>
jmp    1274 <printf+0x154>
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movsbl (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
add    $0xffffff9c,%eax
mov    %eax,%ecx
mov    %rcx,-0x40(%rbp)
sub    $0x14,%eax
ja     126f <printf+0x14f>
mov    -0x40(%rbp),%rax
lea    0xe56(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x8,%rcx
mov    %rcx,-0x10(%rbp)
mov    (%rax),%edi
lea    -0x30(%rbp),%rsi
mov    $0x64,%edx
call   1040 <itoa@plt>
lea    -0x30(%rbp),%rax
mov    %rax,-0x38(%rbp)
jmp    123c <printf+0x11c>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x8,%rcx
mov    %rcx,-0x10(%rbp)
mov    (%rax),%edi
lea    -0x30(%rbp),%rsi
mov    $0x78,%edx
call   1040 <itoa@plt>
lea    -0x30(%rbp),%rax
mov    %rax,-0x38(%rbp)
jmp    123c <printf+0x11c>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x8,%rcx
mov    %rcx,-0x10(%rbp)
mov    (%rax),%rax
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    1237 <printf+0x117>
lea    0xe21(%rip),%rax
mov    %rax,-0x38(%rbp)
jmp    123c <printf+0x11c>
jmp    1241 <printf+0x121>
mov    -0x38(%rbp),%rax
cmpb   $0x0,(%rax)
je     126a <printf+0x14a>
mov    -0x38(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x38(%rbp)
movsbl (%rax),%edi
call   1030 <putchar@plt>
jmp    1241 <printf+0x121>
jmp    126f <printf+0x14f>
jmp    1274 <printf+0x154>
jmp    1140 <printf+0x20>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printf>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rdi,%rbx
lea    0x8(%rsp),%r15
lea    0xec3(%rip),%r12
lea    0x10(%rsp),%r14
lea    0xf0b(%rip),%r13
nopl   0x0(%rax)
add    $0x8,%r15
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rbx,%rax
lea    0x1(%rax),%rbx
mov    %rbx,0x8(%rsp)
movsbl (%rax),%edi
cmp    $0x25,%edi
jne    11a0 <printf+0x80>
lea    0x2(%rax),%rbx
mov    %rbx,0x8(%rsp)
movsbl 0x1(%rax),%ecx
add    $0xffffff9c,%ecx
mov    %rbx,%rax
cmp    $0x14,%ecx
ja     1163 <printf+0x43>
movslq (%r12,%rcx,4),%rcx
add    %r12,%rcx
mov    %rbx,%rax
jmp    *%rcx
nopl   0x0(%rax,%rax,1)
test   %dil,%dil
je     1209 <printf+0xe9>
call   1030 <putchar@plt>
jmp    1160 <printf+0x40>
nopl   0x0(%rax)
mov    (%r15),%edi
mov    %r14,%rsi
mov    $0x64,%edx
jmp    11cb <printf+0xab>
nopl   (%rax)
mov    (%r15),%edi
mov    %r14,%rsi
mov    $0x78,%edx
call   1040 <itoa@plt>
mov    %r14,%rbp
jmp    11df <printf+0xbf>
mov    (%r15),%rbp
test   %rbp,%rbp
cmove  %r13,%rbp
mov    0x0(%rbp),%al
test   %al,%al
je     1150 <printf+0x30>
add    $0x1,%rbp
xchg   %ax,%ax
movsbl %al,%edi
call   1030 <putchar@plt>
movzbl 0x0(%rbp),%eax
add    $0x1,%rbp
test   %al,%al
jne    11f0 <printf+0xd0>
jmp    1150 <printf+0x30>
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [7 x i8] c"(null)\00"
define void @printf(i8* %0, ...) {
%2 = alloca i8*
%3 = alloca i8**
%4 = alloca i32
%5 = alloca [20 x i8]
%6 = alloca i8*
store i8* %0, i8** %2
store i8** %2, i8*** %3
%7 = load i8**, i8*** %3
%8 = getelementptr inbounds i8*, i8** %7, i32 1
store i8** %8, i8*** %3
%9 = load i8*, i8** %7
br label %10
10: ; preds = %65, %1
%11 = load i8*, i8** %2
%12 = getelementptr inbounds i8, i8* %11, i32 1
store i8* %12, i8** %2
%13 = load i8, i8* %11
%14 = sext i8 %13 to i32
store i32 %14, i32* %4
%15 = icmp ne i32 %14, 0
br i1 %15, label %16, label %66
16: ; preds = %10
%17 = load i32, i32* %4
%18 = icmp ne i32 %17, 37
br i1 %18, label %19, label %22
19: ; preds = %16
%20 = load i32, i32* %4
%21 = call i32 @putchar(i32 %20)
br label %65
22: ; preds = %16
%23 = load i8*, i8** %2
%24 = getelementptr inbounds i8, i8* %23, i32 1
store i8* %24, i8** %2
%25 = load i8, i8* %23
%26 = sext i8 %25 to i32
store i32 %26, i32* %4
%27 = load i32, i32* %4
switch i32 %27, label %64 [
i32 105, label %28
i32 100, label %28
i32 117, label %36
i32 120, label %36
i32 115, label %44
]
28: ; preds = %22, %22
%29 = load i8**, i8*** %3
%30 = getelementptr inbounds i8*, i8** %29, i32 1
store i8** %30, i8*** %3
%31 = bitcast i8** %29 to i32*
%32 = load i32, i32* %31
%33 = getelementptr inbounds [20 x i8], [20 x i8]* %5, i64 0, i64 0
%34 = call i32 @itoa(i32 %32, i8* %33, i8 signext 100)
%35 = getelementptr inbounds [20 x i8], [20 x i8]* %5, i64 0, i64 0
store i8* %35, i8** %6
br label %52
36: ; preds = %22, %22
%37 = load i8**, i8*** %3
%38 = getelementptr inbounds i8*, i8** %37, i32 1
store i8** %38, i8*** %3
%39 = bitcast i8** %37 to i32*
%40 = load i32, i32* %39
%41 = getelementptr inbounds [20 x i8], [20 x i8]* %5, i64 0, i64 0
%42 = call i32 @itoa(i32 %40, i8* %41, i8 signext 120)
%43 = getelementptr inbounds [20 x i8], [20 x i8]* %5, i64 0, i64 0
store i8* %43, i8** %6
br label %52
44: ; preds = %22
%45 = load i8**, i8*** %3
%46 = getelementptr inbounds i8*, i8** %45, i32 1
store i8** %46, i8*** %3
%47 = load i8*, i8** %45
store i8* %47, i8** %6
%48 = load i8*, i8** %6
%49 = icmp ne i8* %48, null
br i1 %49, label %51, label %50
50: ; preds = %44
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8** %6
br label %51
51: ; preds = %50, %44
br label %52
52: ; preds = %51, %36, %28
br label %53
53: ; preds = %57, %52
%54 = load i8*, i8** %6
%55 = load i8, i8* %54
%56 = icmp ne i8 %55, 0
br i1 %56, label %57, label %63
57: ; preds = %53
%58 = load i8*, i8** %6
%59 = getelementptr inbounds i8, i8* %58, i32 1
store i8* %59, i8** %6
%60 = load i8, i8* %58
%61 = sext i8 %60 to i32
%62 = call i32 @putchar(i32 %61)
br label %53
63: ; preds = %53
br label %64
64: ; preds = %22, %63
br label %65
65: ; preds = %64, %19
br label %10
66: ; preds = %10
ret void
}

LLVM IR (-O2):
@.str = [7 x i8] c"(null)\00"
define void @printf(i8* %0, ...) {
%2 = alloca i8*
%3 = alloca [20 x i8]
%4 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 0
br label %5
5: ; preds = %38, %1
%6 = phi i8* [ %0, %1 ], [ %17, %38 ]
%7 = phi i8** [ %2, %1 ], [ %8, %38 ]
%8 = getelementptr inbounds i8*, i8** %7, i64 1
br label %9
9: ; preds = %20, %5
%10 = phi i8* [ %6, %5 ], [ %21, %20 ]
%11 = getelementptr inbounds i8, i8* %10, i64 1
store i8* %11, i8** %2
%12 = load i8, i8* %10
switch i8 %12, label %13 [
i8 0, label %47
i8 37, label %16
]
13: ; preds = %9
%14 = sext i8 %12 to i32
%15 = call i32 @putchar(i32 %14)
br label %20
16: ; preds = %9
%17 = getelementptr inbounds i8, i8* %10, i64 2
store i8* %17, i8** %2
%18 = load i8, i8* %11
%19 = sext i8 %18 to i32
switch i32 %19, label %20 [
i32 105, label %22
i32 100, label %22
i32 117, label %26
i32 120, label %26
i32 115, label %30
]
20: ; preds = %16, %13
%21 = phi i8* [ %11, %13 ], [ %17, %16 ]
br label %9
22: ; preds = %16, %16
%23 = bitcast i8** %8 to i32*
%24 = load i32, i32* %23
%25 = call i32 @itoa(i32 %24, i8* %4, i8 signext 100)
br label %34
26: ; preds = %16, %16
%27 = bitcast i8** %8 to i32*
%28 = load i32, i32* %27
%29 = call i32 @itoa(i32 %28, i8* %4, i8 signext 120)
br label %34
30: ; preds = %16
%31 = load i8*, i8** %8
%32 = icmp eq i8* %31, null
%33 = select i1 %32, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %31
br label %34
34: ; preds = %30, %26, %22
%35 = phi i8* [ %33, %30 ], [ %4, %26 ], [ %4, %22 ]
%36 = load i8, i8* %35
%37 = icmp eq i8 %36, 0
br i1 %37, label %38, label %39
38: ; preds = %39, %34
br label %5
39: ; preds = %34, %39
%40 = phi i8 [ %45, %39 ], [ %36, %34 ]
%41 = phi i8* [ %42, %39 ], [ %35, %34 ]
%42 = getelementptr inbounds i8, i8* %41, i64 1
%43 = sext i8 %40 to i32
%44 = call i32 @putchar(i32 %43)
%45 = load i8, i8* %42
%46 = icmp eq i8 %45, 0
br i1 %46, label %38, label %39
47: ; preds = %9
ret void
}