#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*/ Fail(char *, ...);
int sscanf(char *, char *, int *);
void DoNumTest(char *inputstr, char *formatstr, int checknum) {
  int num;
  int ret;
  ret = sscanf(inputstr, formatstr, &num);
  if (ret != 1) {
    Fail("ERROR: Expected sscanf to return 1, got %d.\n"
         "Using \"%s\" in \"%s\".\n",
         ret, inputstr, formatstr);
  }
  if (checknum != num) {
    Fail("ERROR: scanned number incorrectly from \"%s\" using \"%s\".\n"
         "Expected %d, got %d.\n",
         inputstr, formatstr, checknum, num);
  }
}


x86 assembly (clang, -O0):
<DoNumTest>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
lea    -0x18(%rbp),%rdx
call   1030 <sscanf@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x1,-0x1c(%rbp)
je     116a <DoNumTest+0x4a>
mov    -0x1c(%rbp),%esi
mov    -0x8(%rbp),%rdx
mov    -0x10(%rbp),%rcx
lea    0xe9d(%rip),%rdi
mov    $0x0,%al
call   1040 <Fail@plt>
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
je     1193 <DoNumTest+0x73>
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rdx
mov    -0x14(%rbp),%ecx
mov    -0x18(%rbp),%r8d
lea    0xeb5(%rip),%rdi
mov    $0x0,%al
call   1040 <Fail@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<DoNumTest>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %edx,%r14d
mov    %rsi,%rbx
mov    %rdi,%rbp
lea    0xc(%rsp),%rdx
call   1030 <sscanf@plt>
cmp    $0x1,%eax
je     1156 <DoNumTest+0x36>
lea    0xeb9(%rip),%rdi
mov    %eax,%esi
mov    %rbp,%rdx
mov    %rbx,%rcx
xor    %eax,%eax
call   1040 <Fail@plt>
mov    0xc(%rsp),%r8d
cmp    %r14d,%r8d
je     1177 <DoNumTest+0x57>
lea    0xeda(%rip),%rdi
mov    %rbp,%rsi
mov    %rbx,%rdx
mov    %r14d,%ecx
xor    %eax,%eax
call   1040 <Fail@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [65 x i8] c"ERROR: Expected sscanf to return 1, got %d.\0AUsing \22%s\22 in \22%s\22.\0A\00"
@.str.1 = [78 x i8] c"ERROR: scanned number incorrectly from \22%s\22 using \22%s\22.\0AExpected %d, got %d.\0A\00"
define void @DoNumTest(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%9 = load i8*, i8** %4
%10 = load i8*, i8** %5
%11 = call i32 @sscanf(i8* %9, i8* %10, i32* %7)
store i32 %11, i32* %8
%12 = load i32, i32* %8
%13 = icmp ne i32 %12, 1
br i1 %13, label %14, label %19
14: ; preds = %3
%15 = load i32, i32* %8
%16 = load i8*, i8** %4
%17 = load i8*, i8** %5
%18 = call i32 (i8*, ...) @Fail(i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str, i64 0, i64 0), i32 %15, i8* %16, i8* %17)
br label %19
19: ; preds = %14, %3
%20 = load i32, i32* %6
%21 = load i32, i32* %7
%22 = icmp ne i32 %20, %21
br i1 %22, label %23, label %29
23: ; preds = %19
%24 = load i8*, i8** %4
%25 = load i8*, i8** %5
%26 = load i32, i32* %6
%27 = load i32, i32* %7
%28 = call i32 (i8*, ...) @Fail(i8* getelementptr inbounds ([78 x i8], [78 x i8]* @.str.1, i64 0, i64 0), i8* %24, i8* %25, i32 %26, i32 %27)
br label %29
29: ; preds = %23, %19
ret void
}

LLVM IR (-O2):
@.str = [65 x i8] c"ERROR: Expected sscanf to return 1, got %d.\0AUsing \22%s\22 in \22%s\22.\0A\00"
@.str.1 = [78 x i8] c"ERROR: scanned number incorrectly from \22%s\22 using \22%s\22.\0AExpected %d, got %d.\0A\00"
define void @DoNumTest(i8* %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = bitcast i32* %4 to i8*
%6 = call i32 @sscanf(i8* %0, i8* %1, i32* %4)
%7 = icmp eq i32 %6, 1
br i1 %7, label %10, label %8
8: ; preds = %3
%9 = call i32 (i8*, ...) @Fail(i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str, i64 0, i64 0), i32 %6, i8* %0, i8* %1)
br label %10
10: ; preds = %8, %3
%11 = load i32, i32* %4
%12 = icmp eq i32 %11, %2
br i1 %12, label %15, label %13
13: ; preds = %10
%14 = call i32 (i8*, ...) @Fail(i8* getelementptr inbounds ([78 x i8], [78 x i8]* @.str.1, i64 0, i64 0), i8* %0, i8* %1, i32 %2, i32 %11)
br label %15
15: ; preds = %13, %10
ret void
}