#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 *, ...);
scalar_t__ memcmp(char *, char *, int);
int sscanf(char *, char *, char *);
void DoCharTest(char *inputstr, 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(inputstr, formatstr, buf);
  if (ret != 1) {
    Fail("ERROR: Expected sscanf 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    $0x130,%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    1187 <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    1154 <DoCharTest+0x24>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
lea    -0x120(%rbp),%rdx
call   1040 <sscanf@plt>
mov    %eax,-0x124(%rbp)
cmpl   $0x1,-0x124(%rbp)
je     11ca <DoCharTest+0x9a>
mov    -0x124(%rbp),%esi
mov    -0x8(%rbp),%rdx
mov    -0x10(%rbp),%rcx
lea    0xe3d(%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     1214 <DoCharTest+0xe4>
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    0xe34(%rip),%rdi
mov    $0x0,%al
call   1050 <Fail@plt>
movslq -0x1c(%rbp),%rax
movsbl -0x120(%rbp,%rax,1),%eax
ff
cmp    $0xffffffff,%eax
je     1242 <DoCharTest+0x112>
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rdx
mov    -0x1c(%rbp),%ecx
lea    0xe5a(%rip),%rdi
mov    $0x0,%al
call   1050 <Fail@plt>
add    $0x130,%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,%rdx
call   1040 <sscanf@plt>
cmp    $0x1,%eax
je     11e9 <DoCharTest+0xb9>
lea    0xe26(%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     121d <DoCharTest+0xed>
movb   $0x0,(%rsp,%rbx,1)
lea    0xe37(%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     123a <DoCharTest+0x10a>
lea    0xe6b(%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 = [65 x i8] c"ERROR: Expected sscanf 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 = call i32 @sscanf(i8* %23, i8* %24, i8* %25)
store i32 %26, i32* %10
%27 = load i32, i32* %10
%28 = icmp ne i32 %27, 1
br i1 %28, label %29, label %34
29: ; preds = %22
%30 = load i32, i32* %10
%31 = load i8*, i8** %5
%32 = load i8*, i8** %6
%33 = call i32 (i8*, ...) @Fail(i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str, i64 0, i64 0), i32 %30, i8* %31, i8* %32)
br label %34
34: ; preds = %29, %22
%35 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%36 = load i8*, i8** %7
%37 = load i32, i32* %8
%38 = call i64 @memcmp(i8* %35, i8* %36, i32 %37)
%39 = icmp ne i64 %38, 0
br i1 %39, label %40, label %49
40: ; preds = %34
%41 = load i32, i32* %8
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 %42
store i8 0, i8* %43
%44 = load i8*, i8** %5
%45 = load i8*, i8** %6
%46 = load i8*, i8** %7
%47 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%48 = call i32 (i8*, ...) @Fail(i8* getelementptr inbounds ([84 x i8], [84 x i8]* @.str.1, i64 0, i64 0), i8* %44, i8* %45, i8* %46, i8* %47)
br label %49
49: ; preds = %40, %34
%50 = load i32, i32* %8
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 %51
%53 = load i8, i8* %52
%54 = sext i8 %53 to i32
%55 = icmp ne i32 %54, -1
br i1 %55, label %56, label %61
56: ; preds = %49
%57 = load i8*, i8** %5
%58 = load i8*, i8** %6
%59 = load i32, i32* %8
%60 = call i32 (i8*, ...) @Fail(i8* getelementptr inbounds ([98 x i8], [98 x i8]* @.str.2, i64 0, i64 0), i8* %57, i8* %58, i32 %59)
br label %61
61: ; preds = %56, %49
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 = [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 @sscanf(i8* %0, i8* %1, i8* %7)
%9 = icmp eq i32 %8, 1
br i1 %9, label %12, label %10
10: ; preds = %4
%11 = call i32 (i8*, ...) @Fail(i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str, i64 0, i64 0), i32 %8, i8* %0, i8* %1)
br label %12
12: ; preds = %10, %4
%13 = call i64 @memcmp(i8* %7, i8* %2, i32 %3)
%14 = icmp eq i64 %13, 0
%15 = sext i32 %3 to i64
br i1 %14, label %19, label %16
16: ; preds = %12
%17 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 %15
store i8 0, i8* %17
%18 = 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 %19
19: ; preds = %12, %16
%20 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 %15
%21 = load i8, i8* %20
%22 = icmp eq i8 %21, -1
br i1 %22, label %25, label %23
23: ; preds = %19
%24 = 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 %25
25: ; preds = %23, %19
ret void
}