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


x86 assembly (clang, -O0):
<printf1>:
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     1261 <printf1+0x141>
cmpl   $0x25,-0x14(%rbp)
je     1175 <printf1+0x55>
mov    -0x14(%rbp),%edi
call   1030 <putchar1@plt>
jmp    125c <printf1+0x13c>
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 <printf1+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 <printf1+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 <printf1+0xe9>
lea    0xe4f(%rip),%rax
mov    %rax,-0x38(%rbp)
jmp    120e <printf1+0xee>
jmp    1213 <printf1+0xf3>
mov    -0x38(%rbp),%rax
cmpb   $0x0,(%rax)
je     123c <printf1+0x11c>
mov    -0x38(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x38(%rbp)
movsbl (%rax),%edi
call   1030 <putchar1@plt>
jmp    1213 <printf1+0xf3>
jmp    1257 <printf1+0x137>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x8,%rcx
mov    %rcx,-0x10(%rbp)
mov    (%rax),%edi
call   1030 <putchar1@plt>
jmp    125c <printf1+0x13c>
jmp    1140 <printf1+0x20>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printf1>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rdi,%rbx
lea    0x10(%rsp),%r15
lea    0xec3(%rip),%r12
lea    0x10(%rsp),%r14
lea    0xf0b(%rip),%r13
add    $0x1,%rbx
mov    %rbx,%rbp
mov    %rbp,0x8(%rsp)
movsbl -0x1(%rbp),%edi
test   %edi,%edi
je     11ed <printf1+0xcd>
cmp    $0x25,%dil
je     1180 <printf1+0x60>
call   1030 <putchar1@plt>
add    $0x1,%rbp
jmp    1150 <printf1+0x30>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
lea    0x1(%rbp),%rbx
mov    %rbx,0x8(%rsp)
movsbl 0x0(%rbp),%esi
lea    -0x64(%rsi),%eax
cmp    $0x14,%eax
ja     11ae <printf1+0x8e>
movslq (%r12,%rax,4),%rax
add    %r12,%rax
jmp    *%rax
mov    (%r15),%edx
mov    %r14,%rdi
call   1040 <itoa@plt>
mov    %r14,%rbp
jmp    11c2 <printf1+0xa2>
mov    (%r15),%edi
call   1030 <putchar1@plt>
jmp    11e4 <printf1+0xc4>
mov    (%r15),%rbp
test   %rbp,%rbp
cmove  %r13,%rbp
mov    0x0(%rbp),%al
test   %al,%al
je     11e4 <printf1+0xc4>
add    $0x1,%rbp
nopl   (%rax)
movsbl %al,%edi
call   1030 <putchar1@plt>
movzbl 0x0(%rbp),%eax
add    $0x1,%rbp
test   %al,%al
jne    11d0 <printf1+0xb0>
add    $0x8,%r15
jmp    1149 <printf1+0x29>
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 @printf1(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 = %63, %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 %64
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 @putchar1(i32 %19)
br label %63
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 @putchar1(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 @putchar1(i32 %60)
br label %62
62: ; preds = %56, %55
br label %63
63: ; preds = %62, %18
br label %9
64: ; preds = %9
ret void
}

LLVM IR (-O2):
@.str = [7 x i8] c"(null)\00"
define void @printf1(i8* %0, ...) {
%2 = alloca i8*
%3 = alloca [20 x i8]
%4 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 0
%5 = getelementptr inbounds i8*, i8** %2, i64 1
br label %6
6: ; preds = %44, %1
%7 = phi i8* [ %17, %44 ], [ %0, %1 ]
%8 = phi i8** [ %45, %44 ], [ %5, %1 ]
br label %9
9: ; preds = %6, %13
%10 = phi i8* [ %11, %13 ], [ %7, %6 ]
%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 %46
i8 37, label %16
]
13: ; preds = %9
%14 = sext i8 %12 to i32
%15 = call i32 @putchar1(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 %40 [
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 %44, label %32
32: ; preds = %28, %32
%33 = phi i8 [ %38, %32 ], [ %30, %28 ]
%34 = phi i8* [ %35, %32 ], [ %29, %28 ]
%35 = getelementptr inbounds i8, i8* %34, i64 1
%36 = sext i8 %33 to i32
%37 = call i32 @putchar1(i32 %36)
%38 = load i8, i8* %35
%39 = icmp eq i8 %38, 0
br i1 %39, label %44, label %32
40: ; preds = %16
%41 = bitcast i8** %8 to i32*
%42 = load i32, i32* %41
%43 = call i32 @putchar1(i32 %42)
br label %44
44: ; preds = %32, %28, %40
%45 = getelementptr inbounds i8*, i8** %8, i64 1
br label %6
46: ; preds = %9
ret void
}