#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 *, int);
int /*<<< orphan*/ kprint(char *);
int /*<<< orphan*/ kputc(char);
void kprintf(char *format, ...) {
  register char *f = format;
  register char **varg = (&format) + 7;
  while (*f) {
    if (*f == '%') {
      char buf[64];
      f++;
      if (*f == 's') {
        kprint(*varg);
        varg += 1;
      } else if (*f == 'd') {
        itoa(*((int *)varg), buf, 10);
        kprint(buf);
        varg += sizeof(int);
      } else if (*f == 'x') {
        itoa(*((int *)varg), buf, 16);
        kprint(buf);
        varg += sizeof(int);
      }
    } else {
      kputc(*f);
    }
    f++;
  }
}


x86 assembly (clang, -O0):
<kprintf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
lea    -0x8(%rbp),%rax
add    $0x38,%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
cmpb   $0x0,(%rax)
je     1249 <kprintf+0x119>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x25,%eax
jne    122c <kprintf+0xfc>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x73,%eax
jne    11a6 <kprintf+0x76>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
call   1030 <kprint@plt>
mov    -0x18(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x18(%rbp)
jmp    1227 <kprintf+0xf7>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x64,%eax
jne    11e4 <kprintf+0xb4>
mov    -0x18(%rbp),%rax
mov    (%rax),%edi
lea    -0x60(%rbp),%rsi
mov    $0xa,%edx
call   1050 <itoa@plt>
lea    -0x60(%rbp),%rdi
call   1030 <kprint@plt>
mov    -0x18(%rbp),%rax
add    $0x20,%rax
mov    %rax,-0x18(%rbp)
jmp    1222 <kprintf+0xf2>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x78,%eax
jne    121d <kprintf+0xed>
mov    -0x18(%rbp),%rax
mov    (%rax),%edi
lea    -0x60(%rbp),%rsi
mov    $0x10,%edx
call   1050 <itoa@plt>
lea    -0x60(%rbp),%rdi
call   1030 <kprint@plt>
mov    -0x18(%rbp),%rax
add    $0x20,%rax
mov    %rax,-0x18(%rbp)
jmp    1222 <kprintf+0xf2>
jmp    1227 <kprintf+0xf7>
jmp    1238 <kprintf+0x108>
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1040 <kputc@plt>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1150 <kprintf+0x20>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<kprintf>:
push   %r15
push   %r14
push   %rbx
sub    $0x50,%rsp
mov    %rdi,%rbx
mov    %rdi,0x8(%rsp)
lea    0x40(%rsp),%r15
lea    0x10(%rsp),%r14
jmp    116d <kprintf+0x3d>
mov    (%r15),%edi
mov    %r14,%rsi
mov    $0x10,%edx
call   1050 <itoa@plt>
mov    %r14,%rdi
call   1030 <kprint@plt>
add    $0x20,%r15
add    $0x1,%rbx
movzbl (%rbx),%eax
cmp    $0x25,%al
je     1190 <kprintf+0x60>
test   %al,%al
je     11c3 <kprintf+0x93>
movsbl %al,%edi
call   1040 <kputc@plt>
add    $0x1,%rbx
jmp    116d <kprintf+0x3d>
cs nopw 0x0(%rax,%rax,1)
movzbl 0x1(%rbx),%eax
add    $0x1,%rbx
cmp    $0x64,%al
je     11b6 <kprintf+0x86>
cmp    $0x78,%al
je     114d <kprintf+0x1d>
cmp    $0x73,%al
jne    1169 <kprintf+0x39>
mov    (%r15),%rdi
call   1030 <kprint@plt>
add    $0x8,%r15
add    $0x1,%rbx
jmp    116d <kprintf+0x3d>
mov    (%r15),%edi
mov    %r14,%rsi
mov    $0xa,%edx
jmp    1158 <kprintf+0x28>
add    $0x50,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define void @kprintf(i8* %0, ...) {
%2 = alloca i8*
%3 = alloca [64 x i8]
store i8* %0, i8** %2
%4 = getelementptr inbounds i8*, i8** %2, i64 7
%5 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 0
br label %6
6: ; preds = %33, %1
%7 = phi i8* [ %0, %1 ], [ %36, %33 ]
%8 = phi i8** [ %4, %1 ], [ %35, %33 ]
%9 = load i8, i8* %7
switch i8 %9, label %31 [
i8 0, label %37
i8 37, label %10
]
10: ; preds = %6
%11 = getelementptr inbounds i8, i8* %7, i64 1
%12 = load i8, i8* %11
switch i8 %12, label %29 [
i8 115, label %13
i8 100, label %17
i8 120, label %23
]
13: ; preds = %10
%14 = load i8*, i8** %8
%15 = call i32 @kprint(i8* %14)
%16 = getelementptr inbounds i8*, i8** %8, i64 1
br label %29
17: ; preds = %10
%18 = bitcast i8** %8 to i32*
%19 = load i32, i32* %18
%20 = call i32 @itoa(i32 %19, i8* %5, i32 10)
%21 = call i32 @kprint(i8* %5)
%22 = getelementptr inbounds i8*, i8** %8, i64 4
br label %29
23: ; preds = %10
%24 = bitcast i8** %8 to i32*
%25 = load i32, i32* %24
%26 = call i32 @itoa(i32 %25, i8* %5, i32 16)
%27 = call i32 @kprint(i8* %5)
%28 = getelementptr inbounds i8*, i8** %8, i64 4
br label %29
29: ; preds = %10, %17, %23, %13
%30 = phi i8** [ %16, %13 ], [ %22, %17 ], [ %28, %23 ], [ %8, %10 ]
br label %33
31: ; preds = %6
%32 = call i32 @kputc(i8 signext %9)
br label %33
33: ; preds = %31, %29
%34 = phi i8* [ %11, %29 ], [ %7, %31 ]
%35 = phi i8** [ %30, %29 ], [ %8, %31 ]
%36 = getelementptr inbounds i8, i8* %34, i64 1
br label %6
37: ; preds = %6
ret void
}