#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_s(char *, char const *, short *);
void DoShortNumTest(char *inputstr, const char *formatstr, short checknum) {
  short num;
  int ret;
  ret = sscanf_s(inputstr, formatstr, &num);
  if (ret != 1) {
    Fail("ERROR: Expected sscanf_s 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 %hd, got %hd.\n",
         inputstr, formatstr, checknum, num);
  }
}


x86 assembly (clang, -O0):
<DoShortNumTest>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %dx,%ax
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %ax,-0x12(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
lea    -0x14(%rbp),%rdx
call   1040 <sscanf_s@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x1,-0x18(%rbp)
je     116e <DoShortNumTest+0x4e>
mov    -0x18(%rbp),%esi
mov    -0x8(%rbp),%rdx
mov    -0x10(%rbp),%rcx
lea    0xe99(%rip),%rdi
mov    $0x0,%al
call   1030 <Fail@plt>
movswl -0x12(%rbp),%eax
movswl -0x14(%rbp),%ecx
cmp    %ecx,%eax
je     119d <DoShortNumTest+0x7d>
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rdx
movswl -0x12(%rbp),%ecx
movswl -0x14(%rbp),%r8d
lea    0xead(%rip),%rdi
mov    $0x0,%al
call   1030 <Fail@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<DoShortNumTest>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %edx,%ebp
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0xe(%rsp),%rdx
call   1040 <sscanf_s@plt>
cmp    $0x1,%eax
je     1155 <DoShortNumTest+0x35>
lea    0xeba(%rip),%rdi
mov    %eax,%esi
mov    %rbx,%rdx
mov    %r14,%rcx
xor    %eax,%eax
call   1030 <Fail@plt>
movswl 0xe(%rsp),%r8d
cmp    %bp,%r8w
je     1178 <DoShortNumTest+0x58>
movswl %bp,%ecx
lea    0xed8(%rip),%rdi
mov    %rbx,%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   1030 <Fail@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [67 x i8] c"ERROR: Expected sscanf_s to return 1, got %d.\0AUsing \22%s\22 in \22%s\22.\0A\00"
@.str.1 = [80 x i8] c"ERROR: scanned number incorrectly from \22%s\22 using \22%s\22.\0AExpected %hd, got %hd.\0A\00"
define void @DoShortNumTest(i8* %0, i8* %1, i16 signext %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i16
%7 = alloca i16
%8 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i16 %2, i16* %6
%9 = load i8*, i8** %4
%10 = load i8*, i8** %5
%11 = call i32 @sscanf_s(i8* %9, i8* %10, i16* %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 ([67 x i8], [67 x i8]* @.str, i64 0, i64 0), i32 %15, i8* %16, i8* %17)
br label %19
19: ; preds = %14, %3
%20 = load i16, i16* %6
%21 = sext i16 %20 to i32
%22 = load i16, i16* %7
%23 = sext i16 %22 to i32
%24 = icmp ne i32 %21, %23
br i1 %24, label %25, label %33
25: ; preds = %19
%26 = load i8*, i8** %4
%27 = load i8*, i8** %5
%28 = load i16, i16* %6
%29 = sext i16 %28 to i32
%30 = load i16, i16* %7
%31 = sext i16 %30 to i32
%32 = call i32 (i8*, ...) @Fail(i8* getelementptr inbounds ([80 x i8], [80 x i8]* @.str.1, i64 0, i64 0), i8* %26, i8* %27, i32 %29, i32 %31)
br label %33
33: ; preds = %25, %19
ret void
}

LLVM IR (-O2):
@.str = [67 x i8] c"ERROR: Expected sscanf_s to return 1, got %d.\0AUsing \22%s\22 in \22%s\22.\0A\00"
@.str.1 = [80 x i8] c"ERROR: scanned number incorrectly from \22%s\22 using \22%s\22.\0AExpected %hd, got %hd.\0A\00"
define void @DoShortNumTest(i8* %0, i8* %1, i16 signext %2) {
%4 = alloca i16
%5 = bitcast i16* %4 to i8*
%6 = call i32 @sscanf_s(i8* %0, i8* %1, i16* %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 ([67 x i8], [67 x i8]* @.str, i64 0, i64 0), i32 %6, i8* %0, i8* %1)
br label %10
10: ; preds = %8, %3
%11 = load i16, i16* %4
%12 = icmp eq i16 %11, %2
br i1 %12, label %17, label %13
13: ; preds = %10
%14 = sext i16 %11 to i32
%15 = sext i16 %2 to i32
%16 = call i32 (i8*, ...) @Fail(i8* getelementptr inbounds ([80 x i8], [80 x i8]* @.str.1, i64 0, i64 0), i8* %0, i8* %1, i32 %15, i32 %14)
br label %17
17: ; preds = %13, %10
ret void
}