#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 */
float _atof(char const **);
int _atoi(char const **);
int sscanf(const char *buffer, const char *fmt, ...) {
  int cmd;
  int **arg;
  int count;
  arg = (int **)&fmt + 1;
  count = 0;
  while (*fmt) {
    if (fmt[0] != '%') {
      fmt++;
      continue;
    }
    cmd = fmt[1];
    fmt += 2;
    switch (cmd) {
    case 'i':
    case 'd':
    case 'u':
      **arg = _atoi(&buffer);
      break;
    case 'f':
      *(float *)*arg = _atof(&buffer);
      break;
    }
    arg++;
  }
  return count;
}


x86 assembly (clang, -O0):
<sscanf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x10(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x10(%rbp),%rax
cmpb   $0x0,(%rax)
je     11ef <sscanf+0xcf>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x25,%eax
je     1171 <sscanf+0x51>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1143 <sscanf+0x23>
mov    -0x10(%rbp),%rax
movsbl 0x1(%rax),%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x10(%rbp)
mov    -0x14(%rbp),%eax
add    $0xffffff9c,%eax
mov    %eax,%ecx
mov    %rcx,-0x30(%rbp)
sub    $0x11,%eax
ja     11de <sscanf+0xbe>
mov    -0x30(%rbp),%rax
lea    0xe58(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    -0x8(%rbp),%rdi
call   1030 <_atoi@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
mov    %ecx,(%rax)
jmp    11de <sscanf+0xbe>
lea    -0x8(%rbp),%rdi
call   1040 <_atof@plt>
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
movss  %xmm0,(%rax)
mov    -0x20(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x20(%rbp)
jmp    1143 <sscanf+0x23>
mov    -0x24(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sscanf>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbx
mov    %rdi,0x10(%rsp)
mov    %rsi,0x8(%rsp)
lea    0x10(%rsp),%r15
lea    0xebc(%rip),%r12
lea    0x10(%rsp),%r14
nopl   0x0(%rax)
movzbl (%rbx),%eax
test   %al,%al
je     11ac <sscanf+0x8c>
cmp    $0x25,%al
je     1161 <sscanf+0x41>
add    $0x1,%rbx
jmp    1150 <sscanf+0x30>
mov    %rbx,0x8(%rsp)
movsbl 0x1(%rbx),%eax
add    $0x2,%rbx
mov    %rbx,0x8(%rsp)
add    $0xffffff9c,%eax
cmp    $0x11,%eax
ja     11a6 <sscanf+0x86>
movslq (%r12,%rax,4),%rax
add    %r12,%rax
jmp    *%rax
mov    %r14,%rdi
call   1030 <_atoi@plt>
mov    (%r15),%rcx
mov    %eax,(%rcx)
add    $0x8,%r15
jmp    1150 <sscanf+0x30>
mov    %r14,%rdi
call   1040 <_atof@plt>
mov    (%r15),%rax
movss  %xmm0,(%rax)
add    $0x8,%r15
jmp    1150 <sscanf+0x30>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @sscanf(i8* %0, i8* %1, ...) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32**
%7 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
%8 = bitcast i8** %4 to i32**
%9 = getelementptr inbounds i32*, i32** %8, i64 1
store i32** %9, i32*** %6
store i32 0, i32* %7
br label %10
10: ; preds = %40, %20, %2
%11 = load i8*, i8** %4
%12 = load i8, i8* %11
%13 = icmp ne i8 %12, 0
br i1 %13, label %14, label %43
14: ; preds = %10
%15 = load i8*, i8** %4
%16 = getelementptr inbounds i8, i8* %15, i64 0
%17 = load i8, i8* %16
%18 = sext i8 %17 to i32
%19 = icmp ne i32 %18, 37
br i1 %19, label %20, label %23
20: ; preds = %14
%21 = load i8*, i8** %4
%22 = getelementptr inbounds i8, i8* %21, i32 1
store i8* %22, i8** %4
br label %10
23: ; preds = %14
%24 = load i8*, i8** %4
%25 = getelementptr inbounds i8, i8* %24, i64 1
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
store i32 %27, i32* %5
%28 = load i8*, i8** %4
%29 = getelementptr inbounds i8, i8* %28, i64 2
store i8* %29, i8** %4
%30 = load i32, i32* %5
switch i32 %30, label %40 [
i32 105, label %31
i32 100, label %31
i32 117, label %31
i32 102, label %35
]
31: ; preds = %23, %23, %23
%32 = call i32 @_atoi(i8** %3)
%33 = load i32**, i32*** %6
%34 = load i32*, i32** %33
store i32 %32, i32* %34
br label %40
35: ; preds = %23
%36 = call float @_atof(i8** %3)
%37 = load i32**, i32*** %6
%38 = load i32*, i32** %37
%39 = bitcast i32* %38 to float*
store float %36, float* %39
br label %40
40: ; preds = %23, %35, %31
%41 = load i32**, i32*** %6
%42 = getelementptr inbounds i32*, i32** %41, i32 1
store i32** %42, i32*** %6
br label %10
43: ; preds = %10
%44 = load i32, i32* %7
ret i32 %44
}

LLVM IR (-O2):
define i32 @sscanf(i8* %0, i8* %1, ...) {
%3 = alloca i8*
%4 = alloca i8*
store i8* %0, i8** %3
store i8* %1, i8** %4
%5 = getelementptr inbounds i8*, i8** %4, i64 1
%6 = bitcast i8** %5 to i32**
br label %7
7: ; preds = %27, %2
%8 = phi i8* [ %19, %27 ], [ %1, %2 ]
%9 = phi i32** [ %28, %27 ], [ %6, %2 ]
br label %10
10: ; preds = %7, %13
%11 = phi i8* [ %8, %7 ], [ %14, %13 ]
%12 = load i8, i8* %11
switch i8 %12, label %13 [
i8 0, label %29
i8 37, label %15
]
13: ; preds = %10
%14 = getelementptr inbounds i8, i8* %11, i64 1
br label %10
15: ; preds = %10
store i8* %11, i8** %4
%16 = getelementptr inbounds i8, i8* %11, i64 1
%17 = load i8, i8* %16
%18 = sext i8 %17 to i32
%19 = getelementptr inbounds i8, i8* %11, i64 2
store i8* %19, i8** %4
switch i32 %18, label %27 [
i32 105, label %20
i32 100, label %20
i32 117, label %20
i32 102, label %23
]
20: ; preds = %15, %15, %15
%21 = call i32 @_atoi(i8** %3)
%22 = load i32*, i32** %9
store i32 %21, i32* %22
br label %27
23: ; preds = %15
%24 = call float @_atof(i8** %3)
%25 = bitcast i32** %9 to float**
%26 = load float*, float** %25
store float %24, float* %26
br label %27
27: ; preds = %15, %23, %20
%28 = getelementptr inbounds i32*, i32** %9, i64 1
br label %7
29: ; preds = %10
ret i32 0
}