#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(char *, int, int);
int /*<<< orphan*/ putchar(int);
void printf(const char *format, ...) {
  char **arg = (char **)&format;
  int c;
  char buf[20], *p;
  arg++;
  while ((c = *format++) != 0) {
    if (c != '%') {
      putchar(c);
      continue;
    }
    c = *format++;
    switch (c) {
    case 'd':
    case 'u':
    case 'x':
      itoa(buf, c, *((int *)arg++));
      p = buf;
      goto string;
    case 's':
      p = *arg++;
      if (!p)
        p = "(null)";
    string:
      while (*p)
        putchar(*p++);
      break;
    default:
      putchar(*((int *)arg++));
      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     125c <printf+0x13c>
cmpl   $0x25,-0x14(%rbp)
je     1175 <printf+0x55>
mov    -0x14(%rbp),%edi
call   1030 <putchar@plt>
jmp    1140 <printf+0x20>
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     1241 <printf+0x121>
mov    -0x40(%rbp),%rax
lea    0xe56(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    -0x30(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x8,%rcx
mov    %rcx,-0x10(%rbp)
mov    (%rax),%edx
call   1040 <itoa@plt>
lea    -0x30(%rbp),%rax
mov    %rax,-0x38(%rbp)
jmp    120e <printf+0xee>
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    1209 <printf+0xe9>
lea    0xe4f(%rip),%rax
mov    %rax,-0x38(%rbp)
jmp    120e <printf+0xee>
jmp    1213 <printf+0xf3>
mov    -0x38(%rbp),%rax
cmpb   $0x0,(%rax)
je     123c <printf+0x11c>
mov    -0x38(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x38(%rbp)
movsbl (%rax),%edi
call   1030 <putchar@plt>
jmp    1213 <printf+0xf3>
jmp    1257 <printf+0x137>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x8,%rcx
mov    %rcx,-0x10(%rbp)
mov    (%rax),%edi
call   1030 <putchar@plt>
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
mov    %rdi,0x8(%rsp)
lea    0x8(%rsp),%r15
lea    0xebe(%rip),%r12
lea    0x10(%rsp),%r14
lea    0xf06(%rip),%r13
add    $0x8,%r15
add    $0x2,%rbx
cs nopw 0x0(%rax,%rax,1)
movsbl -0x2(%rbx),%edi
test   %edi,%edi
je     11e9 <printf+0xc9>
cmp    $0x25,%dil
je     1180 <printf+0x60>
call   1030 <putchar@plt>
add    $0x1,%rbx
jmp    1160 <printf+0x40>
nopl   (%rax)
mov    %rbx,0x8(%rsp)
movsbl -0x1(%rbx),%esi
lea    -0x64(%rsi),%eax
cmp    $0x14,%eax
ja     11aa <printf+0x8a>
movslq (%r12,%rax,4),%rax
add    %r12,%rax
jmp    *%rax
mov    (%r15),%edx
mov    %r14,%rdi
call   1040 <itoa@plt>
mov    %r14,%rbp
jmp    11be <printf+0x9e>
mov    (%r15),%edi
call   1030 <putchar@plt>
jmp    114e <printf+0x2e>
mov    (%r15),%rbp
test   %rbp,%rbp
cmove  %r13,%rbp
mov    0x0(%rbp),%al
test   %al,%al
je     114e <printf+0x2e>
add    $0x1,%rbp
nopl   0x0(%rax)
movsbl %al,%edi
call   1030 <putchar@plt>
movzbl 0x0(%rbp),%eax
add    $0x1,%rbp
test   %al,%al
jne    11d0 <printf+0xb0>
jmp    114e <printf+0x2e>
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
br label %9
9: ; preds = %62, %18, %1
%10 = load i8*, i8** %2
%11 = getelementptr inbounds i8, i8* %10, i32 1
store i8* %11, i8** %2
%12 = load i8, i8* %10
%13 = sext i8 %12 to i32
store i32 %13, i32* %4
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %63
15: ; preds = %9
%16 = load i32, i32* %4
%17 = icmp ne i32 %16, 37
br i1 %17, label %18, label %21
18: ; preds = %15
%19 = load i32, i32* %4
%20 = call i32 @putchar(i32 %19)
br label %9
21: ; preds = %15
%22 = load i8*, i8** %2
%23 = getelementptr inbounds i8, i8* %22, i32 1
store i8* %23, i8** %2
%24 = load i8, i8* %22
%25 = sext i8 %24 to i32
store i32 %25, i32* %4
%26 = load i32, i32* %4
switch i32 %26, label %56 [
i32 100, label %27
i32 117, label %27
i32 120, label %27
i32 115, label %36
]
27: ; preds = %21, %21, %21
%28 = getelementptr inbounds [20 x i8], [20 x i8]* %5, i64 0, i64 0
%29 = load i32, i32* %4
%30 = load i8**, i8*** %3
%31 = getelementptr inbounds i8*, i8** %30, i32 1
store i8** %31, i8*** %3
%32 = bitcast i8** %30 to i32*
%33 = load i32, i32* %32
%34 = call i32 @itoa(i8* %28, i32 %29, i32 %33)
%35 = getelementptr inbounds [20 x i8], [20 x i8]* %5, i64 0, i64 0
store i8* %35, i8** %6
br label %44
36: ; preds = %21
%37 = load i8**, i8*** %3
%38 = getelementptr inbounds i8*, i8** %37, i32 1
store i8** %38, i8*** %3
%39 = load i8*, i8** %37
store i8* %39, i8** %6
%40 = load i8*, i8** %6
%41 = icmp ne i8* %40, null
br i1 %41, label %43, label %42
42: ; preds = %36
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8** %6
br label %43
43: ; preds = %42, %36
br label %44
44: ; preds = %43, %27
br label %45
45: ; preds = %49, %44
%46 = load i8*, i8** %6
%47 = load i8, i8* %46
%48 = icmp ne i8 %47, 0
br i1 %48, label %49, label %55
49: ; preds = %45
%50 = load i8*, i8** %6
%51 = getelementptr inbounds i8, i8* %50, i32 1
store i8* %51, i8** %6
%52 = load i8, i8* %50
%53 = sext i8 %52 to i32
%54 = call i32 @putchar(i32 %53)
br label %45
55: ; preds = %45
br label %62
56: ; preds = %21
%57 = load i8**, i8*** %3
%58 = getelementptr inbounds i8*, i8** %57, i32 1
store i8** %58, i8*** %3
%59 = bitcast i8** %57 to i32*
%60 = load i32, i32* %59
%61 = call i32 @putchar(i32 %60)
br label %62
62: ; preds = %56, %55
br label %9
63: ; preds = %9
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]
store i8* %0, i8** %2
%4 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 0
br label %5
5: ; preds = %32, %1
%6 = phi i8** [ %2, %1 ], [ %8, %32 ]
%7 = phi i8* [ %0, %1 ], [ %17, %32 ]
%8 = getelementptr inbounds i8*, i8** %6, i64 1
br label %9
9: ; preds = %5, %13
%10 = phi i8* [ %7, %5 ], [ %11, %13 ]
%11 = getelementptr inbounds i8, i8* %10, i64 1
%12 = load i8, i8* %10
switch i8 %12, label %13 [
i8 0, label %45
i8 37, label %16
]
13: ; preds = %9
%14 = sext i8 %12 to i32
%15 = call i32 @putchar(i32 %14)
br label %9
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 %41 [
i32 100, label %20
i32 117, label %20
i32 120, label %20
i32 115, label %24
]
20: ; preds = %16, %16, %16
%21 = bitcast i8** %8 to i32*
%22 = load i32, i32* %21
%23 = call i32 @itoa(i8* %4, i32 %19, i32 %22)
br label %28
24: ; preds = %16
%25 = load i8*, i8** %8
%26 = icmp eq i8* %25, null
%27 = select i1 %26, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %25
br label %28
28: ; preds = %24, %20
%29 = phi i8* [ %27, %24 ], [ %4, %20 ]
%30 = load i8, i8* %29
%31 = icmp eq i8 %30, 0
br i1 %31, label %32, label %33
32: ; preds = %33, %28, %41
br label %5
33: ; preds = %28, %33
%34 = phi i8 [ %39, %33 ], [ %30, %28 ]
%35 = phi i8* [ %36, %33 ], [ %29, %28 ]
%36 = getelementptr inbounds i8, i8* %35, i64 1
%37 = sext i8 %34 to i32
%38 = call i32 @putchar(i32 %37)
%39 = load i8, i8* %36
%40 = icmp eq i8 %39, 0
br i1 %40, label %32, label %33
41: ; preds = %16
%42 = bitcast i8** %8 to i32*
%43 = load i32, i32* %42
%44 = call i32 @putchar(i32 %43)
br label %32
45: ; preds = %9
ret void
}