#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 /*<<< orphan*/ _countof(char *);
scalar_t__ memcmp(char *, char *, int);
int sscanf_s(char *, char const *, char *, int /*<<< orphan*/);
void DoCharTest(char *inputstr, const char *formatstr, char *checkchars,
                int numchars) {
  char buf[256];
  int ret;
  int i;
  for (i = 0; i < 256; i++)
    buf[i] = (char)-1;
  ret = sscanf_s(inputstr, formatstr, buf, _countof(buf));
  if (ret != 1) {
    Fail("ERROR: Expected sscanf_s to return 1, got %d.\n"
         "Using \"%s\" in \"%s\".\n",
         ret, inputstr, formatstr);
  }
  if (memcmp(buf, checkchars, numchars) != 0) {
    buf[numchars] = 0;
    Fail("ERROR: scanned character(s) incorrectly from \"%s\" using \"%s\".\n"
         "Expected %s, got %s.\n",
         inputstr, formatstr, checkchars, buf);
  }
  if (buf[numchars] != (char)-1) {
    Fail("ERROR: overflow occurred in scanning character(s) from \"%s\" "
         "using \"%s\".\nExpected %d character(s)\n",
         inputstr, formatstr, numchars);
  }
}


x86 assembly (clang, -O0):
<DoCharTest>:
push   %rbp
mov    %rsp,%rbp
sub    $0x140,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
movl   $0x0,-0x128(%rbp)
cmpl   $0x100,-0x128(%rbp)
jge    1197 <DoCharTest+0x57>
movslq -0x128(%rbp),%rax
movb   $0xff,-0x120(%rbp,%rax,1)
ff
mov    -0x128(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x128(%rbp)
jmp    1164 <DoCharTest+0x24>
mov    -0x8(%rbp),%rax
mov    %rax,-0x140(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x138(%rbp)
lea    -0x120(%rbp),%rax
mov    %rax,-0x130(%rbp)
lea    -0x120(%rbp),%rdi
call   1040 <_countof@plt>
mov    -0x140(%rbp),%rdi
mov    -0x138(%rbp),%rsi
mov    -0x130(%rbp),%rdx
mov    %eax,%ecx
call   1060 <sscanf_s@plt>
mov    %eax,-0x124(%rbp)
cmpl   $0x1,-0x124(%rbp)
je     1212 <DoCharTest+0xd2>
mov    -0x124(%rbp),%esi
mov    -0x8(%rbp),%rdx
mov    -0x10(%rbp),%rcx
lea    0xdf5(%rip),%rdi
mov    $0x0,%al
call   1050 <Fail@plt>
lea    -0x120(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1030 <memcmp@plt>
cmp    $0x0,%rax
je     125c <DoCharTest+0x11c>
movslq -0x1c(%rbp),%rax
movb   $0x0,-0x120(%rbp,%rax,1)
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
lea    -0x120(%rbp),%r8
lea    0xdee(%rip),%rdi
mov    $0x0,%al
call   1050 <Fail@plt>
movslq -0x1c(%rbp),%rax
movsbl -0x120(%rbp,%rax,1),%eax
ff
cmp    $0xffffffff,%eax
je     128a <DoCharTest+0x14a>
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rdx
mov    -0x1c(%rbp),%ecx
lea    0xe14(%rip),%rdi
mov    $0x0,%al
call   1050 <Fail@plt>
add    $0x140,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<DoCharTest>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x100,%rsp
mov    %ecx,%r14d
mov    %rdx,%r15
mov    %rsi,%r12
mov    %rdi,%rbp
pcmpeqd %xmm0,%xmm0
movdqa %xmm0,0xf0(%rsp)
movdqa %xmm0,0xe0(%rsp)
movdqa %xmm0,0xd0(%rsp)
movdqa %xmm0,0xc0(%rsp)
movdqa %xmm0,0xb0(%rsp)
movdqa %xmm0,0xa0(%rsp)
movdqa %xmm0,0x90(%rsp)
movdqa %xmm0,0x80(%rsp)
movdqa %xmm0,0x70(%rsp)
movdqa %xmm0,0x60(%rsp)
movdqa %xmm0,0x50(%rsp)
movdqa %xmm0,0x40(%rsp)
movdqa %xmm0,0x30(%rsp)
movdqa %xmm0,0x20(%rsp)
movdqa %xmm0,0x10(%rsp)
movdqa %xmm0,(%rsp)
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1040 <_countof@plt>
mov    %rbp,%rdi
mov    %r12,%rsi
mov    %rbx,%rdx
mov    %eax,%ecx
call   1060 <sscanf_s@plt>
cmp    $0x1,%eax
je     120c <DoCharTest+0xcc>
lea    0xe03(%rip),%rdi
mov    %eax,%esi
mov    %rbp,%rdx
mov    %r12,%rcx
xor    %eax,%eax
call   1050 <Fail@plt>
mov    %rsp,%rdi
mov    %r15,%rsi
mov    %r14d,%edx
call   1030 <memcmp@plt>
movslq %r14d,%rbx
test   %rax,%rax
je     1240 <DoCharTest+0x100>
movb   $0x0,(%rsp,%rbx,1)
lea    0xe16(%rip),%rdi
mov    %rsp,%r8
mov    %rbp,%rsi
mov    %r12,%rdx
mov    %r15,%rcx
xor    %eax,%eax
call   1050 <Fail@plt>
cmpb   $0xff,(%rsp,%rbx,1)
je     125d <DoCharTest+0x11d>
lea    0xe4a(%rip),%rdi
mov    %rbp,%rsi
mov    %r12,%rdx
mov    %r14d,%ecx
xor    %eax,%eax
call   1050 <Fail@plt>
add    $0x100,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
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 = [84 x i8] c"ERROR: scanned character(s) incorrectly from \22%s\22 using \22%s\22.\0AExpected %s, got %s.\0A\00"
@.str.2 = [98 x i8] c"ERROR: overflow occurred in scanning character(s) from \22%s\22 using \22%s\22.\0AExpected %d character(s)\0A\00"
define void @DoCharTest(i8* %0, i8* %1, i8* %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca [256 x i8]
%10 = alloca i32
%11 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
store i32 %3, i32* %8
store i32 0, i32* %11
br label %12
12: ; preds = %19, %4
%13 = load i32, i32* %11
%14 = icmp slt i32 %13, 256
br i1 %14, label %15, label %22
15: ; preds = %12
%16 = load i32, i32* %11
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 %17
store i8 -1, i8* %18
br label %19
19: ; preds = %15
%20 = load i32, i32* %11
%21 = add nsw i32 %20, 1
store i32 %21, i32* %11
br label %12
22: ; preds = %12
%23 = load i8*, i8** %5
%24 = load i8*, i8** %6
%25 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%26 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%27 = call i32 @_countof(i8* %26)
%28 = call i32 @sscanf_s(i8* %23, i8* %24, i8* %25, i32 %27)
store i32 %28, i32* %10
%29 = load i32, i32* %10
%30 = icmp ne i32 %29, 1
br i1 %30, label %31, label %36
31: ; preds = %22
%32 = load i32, i32* %10
%33 = load i8*, i8** %5
%34 = load i8*, i8** %6
%35 = call i32 (i8*, ...) @Fail(i8* getelementptr inbounds ([67 x i8], [67 x i8]* @.str, i64 0, i64 0), i32 %32, i8* %33, i8* %34)
br label %36
36: ; preds = %31, %22
%37 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%38 = load i8*, i8** %7
%39 = load i32, i32* %8
%40 = call i64 @memcmp(i8* %37, i8* %38, i32 %39)
%41 = icmp ne i64 %40, 0
br i1 %41, label %42, label %51
42: ; preds = %36
%43 = load i32, i32* %8
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 %44
store i8 0, i8* %45
%46 = load i8*, i8** %5
%47 = load i8*, i8** %6
%48 = load i8*, i8** %7
%49 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%50 = call i32 (i8*, ...) @Fail(i8* getelementptr inbounds ([84 x i8], [84 x i8]* @.str.1, i64 0, i64 0), i8* %46, i8* %47, i8* %48, i8* %49)
br label %51
51: ; preds = %42, %36
%52 = load i32, i32* %8
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 %53
%55 = load i8, i8* %54
%56 = sext i8 %55 to i32
%57 = icmp ne i32 %56, -1
br i1 %57, label %58, label %63
58: ; preds = %51
%59 = load i8*, i8** %5
%60 = load i8*, i8** %6
%61 = load i32, i32* %8
%62 = call i32 (i8*, ...) @Fail(i8* getelementptr inbounds ([98 x i8], [98 x i8]* @.str.2, i64 0, i64 0), i8* %59, i8* %60, i32 %61)
br label %63
63: ; preds = %58, %51
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 = [84 x i8] c"ERROR: scanned character(s) incorrectly from \22%s\22 using \22%s\22.\0AExpected %s, got %s.\0A\00"
@.str.2 = [98 x i8] c"ERROR: overflow occurred in scanning character(s) from \22%s\22 using \22%s\22.\0AExpected %d character(s)\0A\00"
define void @DoCharTest(i8* %0, i8* %1, i8* %2, i32 %3) {
%5 = alloca [256 x i8]
%6 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%7 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%8 = call i32 @_countof(i8* %7)
%9 = call i32 @sscanf_s(i8* %0, i8* %1, i8* %7, i32 %8)
%10 = icmp eq i32 %9, 1
br i1 %10, label %13, label %11
11: ; preds = %4
%12 = call i32 (i8*, ...) @Fail(i8* getelementptr inbounds ([67 x i8], [67 x i8]* @.str, i64 0, i64 0), i32 %9, i8* %0, i8* %1)
br label %13
13: ; preds = %11, %4
%14 = call i64 @memcmp(i8* %7, i8* %2, i32 %3)
%15 = icmp eq i64 %14, 0
%16 = sext i32 %3 to i64
br i1 %15, label %20, label %17
17: ; preds = %13
%18 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 %16
store i8 0, i8* %18
%19 = call i32 (i8*, ...) @Fail(i8* getelementptr inbounds ([84 x i8], [84 x i8]* @.str.1, i64 0, i64 0), i8* %0, i8* %1, i8* %2, i8* %7)
br label %20
20: ; preds = %13, %17
%21 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 %16
%22 = load i8, i8* %21
%23 = icmp eq i8 %22, -1
br i1 %23, label %26, label %24
24: ; preds = %20
%25 = call i32 (i8*, ...) @Fail(i8* getelementptr inbounds ([98 x i8], [98 x i8]* @.str.2, i64 0, i64 0), i8* %0, i8* %1, i32 %3)
br label %26
26: ; preds = %24, %20
ret void
}