#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 ReadChar();
int ReadInt();
int /*<<< orphan*/ ReadString(char *, int);
void Scanf(char *formatSpecifier, ...) {
  char *argPtr = (char *)(&formatSpecifier) + sizeof(char *);
  int *argInt;
  char *argChar;
  char *argString;
  while ((*formatSpecifier) != '\0') {
    if ((*formatSpecifier) == '%') {
      formatSpecifier++;
      if ((*formatSpecifier) == 'd') {
        argInt = (int *)(*((int *)argPtr));
        (*argInt) = ReadInt();
        argPtr += sizeof(int *);
      } else if ((*formatSpecifier) == 'c') {
        argChar = (char *)(*((int *)argPtr));
        (*argChar) = ReadChar();
        argPtr += sizeof(char *);
      } else if ((*formatSpecifier) == 's') {
        argString = (char *)(*((int *)argPtr));
        ReadString(argString, 1000);
        argPtr += sizeof(char *);
      } else {
        return;
      }
    }
    formatSpecifier++;
  }
}


x86 assembly (clang, -O0):
<Scanf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0x8(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1249 <Scanf+0x119>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x25,%eax
jne    1238 <Scanf+0x108>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x64,%eax
jne    11af <Scanf+0x7f>
mov    -0x10(%rbp),%rax
movslq (%rax),%rax
mov    %rax,-0x18(%rbp)
mov    $0x0,%al
call   1040 <ReadInt@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x10(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x10(%rbp)
jmp    1233 <Scanf+0x103>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x63,%eax
jne    11ea <Scanf+0xba>
mov    -0x10(%rbp),%rax
movslq (%rax),%rax
mov    %rax,-0x20(%rbp)
mov    $0x0,%al
call   1050 <ReadChar@plt>
mov    %al,%cl
mov    -0x20(%rbp),%rax
mov    %cl,(%rax)
mov    -0x10(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x10(%rbp)
jmp    122e <Scanf+0xfe>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x73,%eax
jne    1224 <Scanf+0xf4>
mov    -0x10(%rbp),%rax
movslq (%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    $0x3e8,%esi
call   1030 <ReadString@plt>
mov    -0x10(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x10(%rbp)
jmp    1229 <Scanf+0xf9>
jmp    1249 <Scanf+0x119>
jmp    122e <Scanf+0xfe>
jmp    1233 <Scanf+0x103>
jmp    1238 <Scanf+0x108>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    1148 <Scanf+0x18>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Scanf>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
mov    %rdi,0x8(%rsp)
lea    0x10(%rsp),%r14
jmp    1158 <Scanf+0x28>
nopl   0x0(%rax,%rax,1)
test   %al,%al
je     11a4 <Scanf+0x74>
add    $0x1,%rbx
movzbl (%rbx),%eax
cmp    $0x25,%al
jne    1150 <Scanf+0x20>
movzbl 0x1(%rbx),%eax
add    $0x1,%rbx
cmp    $0x63,%al
je     1182 <Scanf+0x52>
cmp    $0x73,%al
je     1191 <Scanf+0x61>
cmp    $0x64,%al
jne    11a4 <Scanf+0x74>
movslq (%r14),%r15
xor    %eax,%eax
call   1040 <ReadInt@plt>
mov    %eax,(%r15)
jmp    119e <Scanf+0x6e>
movslq (%r14),%r15
xor    %eax,%eax
call   1050 <ReadChar@plt>
mov    %al,(%r15)
jmp    119e <Scanf+0x6e>
movslq (%r14),%rdi
mov    $0x3e8,%esi
call   1030 <ReadString@plt>
add    $0x8,%r14
jmp    1154 <Scanf+0x24>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

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

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