#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 */
char *printf_format_arg(char **, void *);
int /*<<< orphan*/ putchar(char);
int /*<<< orphan*/ putsn(char *);
int printf_(char *s, void *arg1, const void *arg2) {
  char *c;
  int arg_shift;
  while (*s) {
    if (*s == '%') {
      arg_shift = (s[1] != '%');
      c = printf_format_arg(&s, arg1);
      if (arg_shift) {
        arg1 = arg2;
      }
      putsn(c);
    } else {
      putchar(*s);
    }
    s++;
  }
  return 0;
}


x86 assembly (clang, -O0):
<printf_>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rax
cmpb   $0x0,(%rax)
je     11c5 <printf_+0x95>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x25,%eax
jne    11a8 <printf_+0x78>
mov    -0x8(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x25,%eax
setne  %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rsi
lea    -0x8(%rbp),%rdi
call   1050 <printf_format_arg@plt>
mov    %rax,-0x20(%rbp)
cmpl   $0x0,-0x24(%rbp)
je     119a <printf_+0x6a>
mov    -0x18(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <putsn@plt>
jmp    11b4 <printf_+0x84>
mov    -0x8(%rbp),%rax
movsbl (%rax),%edi
call   1030 <putchar@plt>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    1144 <printf_+0x14>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printf_>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%r12
mov    %rsp,%r15
jmp    1176 <printf_+0x46>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movzbl 0x1(%rdi),%ebx
mov    %r15,%rdi
mov    %r12,%rsi
call   1050 <printf_format_arg@plt>
cmp    $0x25,%bl
cmovne %r14,%r12
mov    %rax,%rdi
call   1040 <putsn@plt>
mov    (%rsp),%rdi
add    $0x1,%rdi
mov    %rdi,(%rsp)
movzbl (%rdi),%eax
cmp    $0x25,%al
je     1150 <printf_+0x20>
test   %al,%al
je     118f <printf_+0x5f>
movsbl %al,%edi
call   1030 <putchar@plt>
jmp    116e <printf_+0x3e>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @printf_(i8* %0, i8* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8* %2, i8** %6
br label %9
9: ; preds = %38, %3
%10 = load i8*, i8** %4
%11 = load i8, i8* %10
%12 = icmp ne i8 %11, 0
br i1 %12, label %13, label %41
13: ; preds = %9
%14 = load i8*, i8** %4
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
%17 = icmp eq i32 %16, 37
br i1 %17, label %18, label %34
18: ; preds = %13
%19 = load i8*, i8** %4
%20 = getelementptr inbounds i8, i8* %19, i64 1
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
%23 = icmp ne i32 %22, 37
%24 = zext i1 %23 to i32
store i32 %24, i32* %8
%25 = load i8*, i8** %5
%26 = call i8* @printf_format_arg(i8** %4, i8* %25)
store i8* %26, i8** %7
%27 = load i32, i32* %8
%28 = icmp ne i32 %27, 0
br i1 %28, label %29, label %31
29: ; preds = %18
%30 = load i8*, i8** %6
store i8* %30, i8** %5
br label %31
31: ; preds = %29, %18
%32 = load i8*, i8** %7
%33 = call i32 @putsn(i8* %32)
br label %38
34: ; preds = %13
%35 = load i8*, i8** %4
%36 = load i8, i8* %35
%37 = call i32 @putchar(i8 signext %36)
br label %38
38: ; preds = %34, %31
%39 = load i8*, i8** %4
%40 = getelementptr inbounds i8, i8* %39, i32 1
store i8* %40, i8** %4
br label %9
41: ; preds = %9
ret i32 0
}

LLVM IR (-O2):
define i32 @printf_(i8* %0, i8* %1, i8* %2) {
%4 = alloca i8*
br label %5
5: ; preds = %18, %3
%6 = phi i8* [ %0, %3 ], [ %21, %18 ]
%7 = phi i8* [ %1, %3 ], [ %19, %18 ]
store i8* %6, i8** %4
%8 = load i8, i8* %6
switch i8 %8, label %16 [
i8 0, label %22
i8 37, label %9
]
9: ; preds = %5
%10 = getelementptr inbounds i8, i8* %6, i64 1
%11 = load i8, i8* %10
%12 = icmp eq i8 %11, 37
%13 = call i8* @printf_format_arg(i8** %4, i8* %7)
%14 = select i1 %12, i8* %7, i8* %2
%15 = call i32 @putsn(i8* %13)
br label %18
16: ; preds = %5
%17 = call i32 @putchar(i8 signext %8)
br label %18
18: ; preds = %16, %9
%19 = phi i8* [ %14, %9 ], [ %7, %16 ]
%20 = load i8*, i8** %4
%21 = getelementptr inbounds i8, i8* %20, i64 1
br label %5
22: ; preds = %5
ret i32 0
}