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


x86 assembly (clang, -O0):
<printf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%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)
mov    (%rax),%al
mov    %al,-0x11(%rbp)
movsbl %al,%eax
cmp    $0x0,%eax
je     1280 <printf+0x150>
movsbl -0x11(%rbp),%eax
cmp    $0x25,%eax
je     118b <printf+0x5b>
movsbl -0x11(%rbp),%edi
call   1030 <putchar@plt>
jmp    127b <printf+0x14b>
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
mov    (%rax),%al
mov    %al,-0x11(%rbp)
movsbl -0x11(%rbp),%eax
mov    %eax,-0x44(%rbp)
sub    $0x62,%eax
je     11f8 <printf+0xc8>
jmp    11b4 <printf+0x84>
mov    -0x44(%rbp),%eax
sub    $0x64,%eax
je     11f8 <printf+0xc8>
jmp    11c5 <printf+0x95>
mov    -0x44(%rbp),%eax
sub    $0x73,%eax
je     1226 <printf+0xf6>
jmp    11d6 <printf+0xa6>
mov    -0x44(%rbp),%eax
sub    $0x75,%eax
je     11f8 <printf+0xc8>
jmp    11e7 <printf+0xb7>
mov    -0x44(%rbp),%eax
sub    $0x78,%eax
jne    126d <printf+0x13d>
jmp    11f8 <printf+0xc8>
lea    -0x40(%rbp),%rdi
mov    -0x11(%rbp),%al
mov    -0x10(%rbp),%rcx
mov    %rcx,%rdx
add    $0x8,%rdx
mov    %rdx,-0x10(%rbp)
mov    (%rcx),%edx
movsbl %al,%esi
call   1050 <itoa@plt>
lea    -0x40(%rbp),%rdi
call   1040 <puts@plt>
jmp    1276 <printf+0x146>
mov    -0x10(%rbp),%rax
cmpq   $0x0,(%rax)
je     124f <printf+0x11f>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x8,%rcx
mov    %rcx,-0x10(%rbp)
mov    (%rax),%rax
mov    %rax,-0x50(%rbp)
jmp    125f <printf+0x12f>
lea    0xdaa(%rip),%rax
mov    %rax,-0x50(%rbp)
jmp    125f <printf+0x12f>
mov    -0x50(%rbp),%rdi
call   1040 <puts@plt>
jmp    1276 <printf+0x146>
movsbl -0x11(%rbp),%edi
call   1030 <putchar@plt>
jmp    127b <printf+0x14b>
jmp    1150 <printf+0x20>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printf>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x30,%rsp
mov    %rdi,%rbx
lea    0x10(%rsp),%r15
mov    $0x480005,%ebp
lea    0x10(%rsp),%r14
lea    0xeab(%rip),%r12
jmp    116d <printf+0x3d>
nopw   0x0(%rax,%rax,1)
cmp    $0x11,%ecx
je     11c8 <printf+0x98>
movsbl %al,%edi
call   1030 <putchar@plt>
mov    %rbx,%rax
add    $0x1,%rbx
mov    %rbx,0x8(%rsp)
movzbl (%rax),%ecx
cmp    $0x25,%cl
je     1190 <printf+0x60>
test   %cl,%cl
je     11e2 <printf+0xb2>
movsbl %cl,%edi
call   1030 <putchar@plt>
jmp    116d <printf+0x3d>
nop
lea    0x2(%rax),%rbx
mov    %rbx,0x8(%rsp)
movsbl 0x1(%rax),%eax
mov    %eax,%ecx
add    $0xffffff9e,%ecx
cmp    $0x16,%ecx
ja     1165 <printf+0x35>
bt     %ecx,%ebp
jae    1160 <printf+0x30>
mov    (%r15),%edx
add    $0x8,%r15
movsbl %al,%esi
mov    %r14,%rdi
call   1050 <itoa@plt>
mov    %r14,%rdi
call   1040 <puts@plt>
jmp    116d <printf+0x3d>
mov    (%r15),%rdi
xor    %eax,%eax
test   %rdi,%rdi
setne  %al
lea    (%r15,%rax,8),%r15
cmove  %r12,%rdi
call   1040 <puts@plt>
jmp    116d <printf+0x3d>
add    $0x30,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"null\00"
define void @printf(i8* %0, ...) {
%2 = alloca i8*
%3 = alloca i8**
%4 = alloca i8
%5 = alloca [32 x i8]
store i8* %0, i8** %2
store i8** %2, i8*** %3
%6 = load i8**, i8*** %3
%7 = getelementptr inbounds i8*, i8** %6, i32 1
store i8** %7, i8*** %3
br label %8
8: ; preds = %53, %1
%9 = load i8*, i8** %2
%10 = getelementptr inbounds i8, i8* %9, i32 1
store i8* %10, i8** %2
%11 = load i8, i8* %9
store i8 %11, i8* %4
%12 = sext i8 %11 to i32
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %54
14: ; preds = %8
%15 = load i8, i8* %4
%16 = sext i8 %15 to i32
%17 = icmp ne i32 %16, 37
br i1 %17, label %18, label %21
18: ; preds = %14
%19 = load i8, i8* %4
%20 = call i32 @putchar(i8 signext %19)
br label %53
21: ; preds = %14
%22 = load i8*, i8** %2
%23 = getelementptr inbounds i8, i8* %22, i32 1
store i8* %23, i8** %2
%24 = load i8, i8* %22
store i8 %24, i8* %4
%25 = load i8, i8* %4
%26 = sext i8 %25 to i32
switch i32 %26, label %49 [
i32 100, label %27
i32 117, label %27
i32 120, label %27
i32 98, label %27
i32 115, label %37
]
27: ; preds = %21, %21, %21, %21
%28 = getelementptr inbounds [32 x i8], [32 x i8]* %5, i64 0, i64 0
%29 = load i8, i8* %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, i8 signext %29, i32 %33)
%35 = getelementptr inbounds [32 x i8], [32 x i8]* %5, i64 0, i64 0
%36 = call i32 @puts(i8* %35)
br label %52
37: ; preds = %21
%38 = load i8**, i8*** %3
%39 = load i8*, i8** %38
%40 = icmp ne i8* %39, null
br i1 %40, label %41, label %45
41: ; preds = %37
%42 = load i8**, i8*** %3
%43 = getelementptr inbounds i8*, i8** %42, i32 1
store i8** %43, i8*** %3
%44 = load i8*, i8** %42
br label %46
45: ; preds = %37
br label %46
46: ; preds = %45, %41
%47 = phi i8* [ %44, %41 ], [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), %45 ]
%48 = call i32 @puts(i8* %47)
br label %52
49: ; preds = %21
%50 = load i8, i8* %4
%51 = call i32 @putchar(i8 signext %50)
br label %52
52: ; preds = %49, %46, %27
br label %53
53: ; preds = %52, %18
br label %8
54: ; preds = %8
ret void
}

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