#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fputc(unsigned char, int /*<<< orphan*/ *);
int /*<<< orphan*/ miniprintn(unsigned int, int /*<<< orphan*/ *, int);
int vfprintf_mini(FILE *fp, unsigned char *fmt, void *ap) {
  unsigned char c;
  unsigned char k;
  unsigned char *s;
  while ((c = *fmt++) != '\0') {
    if (c != '%')
      fputc(c, fp);
    else {
      c = *fmt++;
      switch (c) {
      case 'd':
      case 'i':
        miniprintn((unsigned int)*(int *)ap, fp, 1);
        ap -= sizeof(int);
        break;
      case 'u':
        miniprintn((unsigned int)*(unsigned int *)ap, fp, 0);
        ap -= sizeof(int);
        break;
      case 's':
        s = *(char **)ap;
        while ((k = *s++) != '\0')
          fputc(k, fp);
        ap -= sizeof(char *);
        break;
      case 'c':
        fputc(*(int *)ap, fp);
        ap -= sizeof(int);
        break;
      default:
        fputc(c, fp);
      }
    }
  }
  return (0);
}


x86 assembly (clang, -O0):
<vfprintf_mini>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
mov    (%rax),%al
mov    %al,-0x19(%rbp)
movzbl %al,%eax
cmp    $0x0,%eax
je     1286 <vfprintf_mini+0x166>
movzbl -0x19(%rbp),%eax
cmp    $0x25,%eax
je     1175 <vfprintf_mini+0x55>
mov    -0x19(%rbp),%al
mov    -0x8(%rbp),%rsi
movzbl %al,%edi
call   1040 <fputc@plt>
jmp    1281 <vfprintf_mini+0x161>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
mov    (%rax),%al
mov    %al,-0x19(%rbp)
movzbl -0x19(%rbp),%eax
add    $0xffffff9d,%eax
mov    %eax,%ecx
mov    %rcx,-0x30(%rbp)
sub    $0x12,%eax
ja     126d <vfprintf_mini+0x14d>
mov    -0x30(%rbp),%rax
lea    0xe56(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x18(%rbp),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rsi
mov    $0x1,%edx
call   1030 <miniprintn@plt>
mov    -0x18(%rbp),%rax
add    $0xfffffffffffffffc,%rax
mov    %rax,-0x18(%rbp)
jmp    127c <vfprintf_mini+0x15c>
mov    -0x18(%rbp),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rsi
xor    %edx,%edx
call   1030 <miniprintn@plt>
mov    -0x18(%rbp),%rax
add    $0xfffffffffffffffc,%rax
mov    %rax,-0x18(%rbp)
jmp    127c <vfprintf_mini+0x15c>
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x28(%rbp)
mov    (%rax),%al
mov    %al,-0x1a(%rbp)
movzbl %al,%eax
cmp    $0x0,%eax
je     1239 <vfprintf_mini+0x119>
mov    -0x1a(%rbp),%al
mov    -0x8(%rbp),%rsi
movzbl %al,%edi
call   1040 <fputc@plt>
jmp    1205 <vfprintf_mini+0xe5>
mov    -0x18(%rbp),%rax
add    $0xfffffffffffffff8,%rax
mov    %rax,-0x18(%rbp)
jmp    127c <vfprintf_mini+0x15c>
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
mov    -0x8(%rbp),%rsi
movzbl %al,%edi
call   1040 <fputc@plt>
mov    -0x18(%rbp),%rax
add    $0xfffffffffffffffc,%rax
mov    %rax,-0x18(%rbp)
jmp    127c <vfprintf_mini+0x15c>
mov    -0x19(%rbp),%al
mov    -0x8(%rbp),%rsi
movzbl %al,%edi
call   1040 <fputc@plt>
jmp    1281 <vfprintf_mini+0x161>
jmp    1134 <vfprintf_mini+0x14>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<vfprintf_mini>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdx,%r14
mov    %rsi,%r13
mov    %rdi,%r15
lea    0xec7(%rip),%r12
jmp    114b <vfprintf_mini+0x2b>
nopl   0x0(%rax,%rax,1)
movzbl %al,%edi
mov    %r15,%rsi
call   1040 <fputc@plt>
mov    0x0(%r13),%al
cmp    $0x25,%al
je     1170 <vfprintf_mini+0x50>
test   %al,%al
je     11f5 <vfprintf_mini+0xd5>
add    $0x1,%r13
movzbl %al,%edi
jmp    1143 <vfprintf_mini+0x23>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    0x1(%r13),%al
add    $0x2,%r13
lea    -0x63(%rax),%ecx
cmp    $0x12,%cl
ja     1140 <vfprintf_mini+0x20>
movzbl %cl,%ecx
movslq (%r12,%rcx,4),%rcx
add    %r12,%rcx
jmp    *%rcx
mov    (%r14),%edi
mov    %r15,%rsi
mov    $0x1,%edx
jmp    11e7 <vfprintf_mini+0xc7>
movzbl (%r14),%edi
mov    %r15,%rsi
call   1040 <fputc@plt>
add    $0xfffffffffffffffc,%r14
jmp    114b <vfprintf_mini+0x2b>
mov    (%r14),%rbx
mov    (%rbx),%al
test   %al,%al
je     11d6 <vfprintf_mini+0xb6>
add    $0x1,%rbx
nopl   0x0(%rax,%rax,1)
movzbl %al,%edi
mov    %r15,%rsi
call   1040 <fputc@plt>
movzbl (%rbx),%eax
add    $0x1,%rbx
test   %al,%al
jne    11c0 <vfprintf_mini+0xa0>
add    $0xfffffffffffffff8,%r14
jmp    114b <vfprintf_mini+0x2b>
mov    (%r14),%edi
mov    %r15,%rsi
xor    %edx,%edx
call   1030 <miniprintn@plt>
add    $0xfffffffffffffffc,%r14
jmp    114b <vfprintf_mini+0x2b>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @vfprintf_mini(i32* %0, i8* %1, i8* %2) {
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8
%8 = alloca i8
%9 = alloca i8*
store i32* %0, i32** %4
store i8* %1, i8** %5
store i8* %2, i8** %6
br label %10
10: ; preds = %77, %3
%11 = load i8*, i8** %5
%12 = getelementptr inbounds i8, i8* %11, i32 1
store i8* %12, i8** %5
%13 = load i8, i8* %11
store i8 %13, i8* %7
%14 = zext i8 %13 to i32
%15 = icmp ne i32 %14, 0
br i1 %15, label %16, label %78
16: ; preds = %10
%17 = load i8, i8* %7
%18 = zext i8 %17 to i32
%19 = icmp ne i32 %18, 37
br i1 %19, label %20, label %24
20: ; preds = %16
%21 = load i8, i8* %7
%22 = load i32*, i32** %4
%23 = call i32 @fputc(i8 zeroext %21, i32* %22)
br label %77
24: ; preds = %16
%25 = load i8*, i8** %5
%26 = getelementptr inbounds i8, i8* %25, i32 1
store i8* %26, i8** %5
%27 = load i8, i8* %25
store i8 %27, i8* %7
%28 = load i8, i8* %7
%29 = zext i8 %28 to i32
switch i32 %29, label %72 [
i32 100, label %30
i32 105, label %30
i32 117, label %38
i32 115, label %46
i32 99, label %63
]
30: ; preds = %24, %24
%31 = load i8*, i8** %6
%32 = bitcast i8* %31 to i32*
%33 = load i32, i32* %32
%34 = load i32*, i32** %4
%35 = call i32 @miniprintn(i32 %33, i32* %34, i32 1)
%36 = load i8*, i8** %6
%37 = getelementptr i8, i8* %36, i64 -4
store i8* %37, i8** %6
br label %76
38: ; preds = %24
%39 = load i8*, i8** %6
%40 = bitcast i8* %39 to i32*
%41 = load i32, i32* %40
%42 = load i32*, i32** %4
%43 = call i32 @miniprintn(i32 %41, i32* %42, i32 0)
%44 = load i8*, i8** %6
%45 = getelementptr i8, i8* %44, i64 -4
store i8* %45, i8** %6
br label %76
46: ; preds = %24
%47 = load i8*, i8** %6
%48 = bitcast i8* %47 to i8**
%49 = load i8*, i8** %48
store i8* %49, i8** %9
br label %50
50: ; preds = %56, %46
%51 = load i8*, i8** %9
%52 = getelementptr inbounds i8, i8* %51, i32 1
store i8* %52, i8** %9
%53 = load i8, i8* %51
store i8 %53, i8* %8
%54 = zext i8 %53 to i32
%55 = icmp ne i32 %54, 0
br i1 %55, label %56, label %60
56: ; preds = %50
%57 = load i8, i8* %8
%58 = load i32*, i32** %4
%59 = call i32 @fputc(i8 zeroext %57, i32* %58)
br label %50
60: ; preds = %50
%61 = load i8*, i8** %6
%62 = getelementptr i8, i8* %61, i64 -8
store i8* %62, i8** %6
br label %76
63: ; preds = %24
%64 = load i8*, i8** %6
%65 = bitcast i8* %64 to i32*
%66 = load i32, i32* %65
%67 = trunc i32 %66 to i8
%68 = load i32*, i32** %4
%69 = call i32 @fputc(i8 zeroext %67, i32* %68)
%70 = load i8*, i8** %6
%71 = getelementptr i8, i8* %70, i64 -4
store i8* %71, i8** %6
br label %76
72: ; preds = %24
%73 = load i8, i8* %7
%74 = load i32*, i32** %4
%75 = call i32 @fputc(i8 zeroext %73, i32* %74)
br label %76
76: ; preds = %72, %63, %60, %38, %30
br label %77
77: ; preds = %76, %20
br label %10
78: ; preds = %10
ret i32 0
}

LLVM IR (-O2):
define i32 @vfprintf_mini(i32* %0, i8* nocapture %1, i8* nocapture %2) {
br label %4
4: ; preds = %46, %3
%5 = phi i8* [ %2, %3 ], [ %47, %46 ]
%6 = phi i8* [ %1, %3 ], [ %14, %46 ]
br label %7
7: ; preds = %50, %4
%8 = phi i8* [ %6, %4 ], [ %51, %50 ]
%9 = getelementptr inbounds i8, i8* %8, i64 1
%10 = load i8, i8* %8
switch i8 %10, label %11 [
i8 0, label %52
i8 37, label %13
]
11: ; preds = %7
%12 = tail call i32 @fputc(i8 zeroext %10, i32* %0)
br label %50
13: ; preds = %7
%14 = getelementptr inbounds i8, i8* %8, i64 2
%15 = load i8, i8* %9
switch i8 %15, label %48 [
i8 100, label %16
i8 105, label %16
i8 117, label %21
i8 115, label %26
i8 99, label %40
]
16: ; preds = %13, %13
%17 = bitcast i8* %5 to i32*
%18 = load i32, i32* %17
%19 = tail call i32 @miniprintn(i32 %18, i32* %0, i32 1)
%20 = getelementptr i8, i8* %5, i64 -4
br label %46
21: ; preds = %13
%22 = bitcast i8* %5 to i32*
%23 = load i32, i32* %22
%24 = tail call i32 @miniprintn(i32 %23, i32* %0, i32 0)
%25 = getelementptr i8, i8* %5, i64 -4
br label %46
26: ; preds = %13
%27 = bitcast i8* %5 to i8**
%28 = load i8*, i8** %27
%29 = load i8, i8* %28
%30 = icmp eq i8 %29, 0
br i1 %30, label %38, label %31
31: ; preds = %26, %31
%32 = phi i8 [ %36, %31 ], [ %29, %26 ]
%33 = phi i8* [ %34, %31 ], [ %28, %26 ]
%34 = getelementptr inbounds i8, i8* %33, i64 1
%35 = tail call i32 @fputc(i8 zeroext %32, i32* %0)
%36 = load i8, i8* %34
%37 = icmp eq i8 %36, 0
br i1 %37, label %38, label %31
38: ; preds = %31, %26
%39 = getelementptr i8, i8* %5, i64 -8
br label %46
40: ; preds = %13
%41 = bitcast i8* %5 to i32*
%42 = load i32, i32* %41
%43 = trunc i32 %42 to i8
%44 = tail call i32 @fputc(i8 zeroext %43, i32* %0)
%45 = getelementptr i8, i8* %5, i64 -4
br label %46
46: ; preds = %40, %38, %21, %16
%47 = phi i8* [ %20, %16 ], [ %25, %21 ], [ %39, %38 ], [ %45, %40 ]
br label %4
48: ; preds = %13
%49 = tail call i32 @fputc(i8 zeroext %15, i32* %0)
br label %50
50: ; preds = %48, %11
%51 = phi i8* [ %9, %11 ], [ %14, %48 ]
br label %7
52: ; preds = %7
ret i32 0
}