#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 const *, char *, scalar_t__);
int sscanf_s(char *, char const *, char *, int /*<<< orphan*/);
scalar_t__ strlen(char const *);
void DoStrTest(char *inputstr, const char *formatstr, const char *checkstr) {
  char buf[256] = {0};
  int ret;
  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(checkstr, buf, strlen(checkstr) + 1) != 0) {
    Fail("ERROR: scanned string incorrectly from \"%s\" using \"%s\".\n"
         "Expected \"%s\", got \"%s\".\n",
         inputstr, formatstr, checkstr, buf);
  }
}


x86 assembly (clang, -O0):
<DoStrTest>:
push   %rbp
mov    %rsp,%rbp
sub    $0x150,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
lea    -0x120(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1040 <memset@plt>
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   1060 <_countof@plt>
mov    -0x140(%rbp),%rdi
mov    -0x138(%rbp),%rsi
mov    -0x130(%rbp),%rdx
mov    %eax,%ecx
call   1080 <sscanf_s@plt>
mov    %eax,-0x124(%rbp)
cmpl   $0x1,-0x124(%rbp)
je     1205 <DoStrTest+0xa5>
mov    -0x124(%rbp),%esi
mov    -0x8(%rbp),%rdx
mov    -0x10(%rbp),%rcx
lea    0xe02(%rip),%rdi
mov    $0x0,%al
call   1070 <Fail@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x150(%rbp)
lea    -0x120(%rbp),%rax
mov    %rax,-0x148(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x150(%rbp),%rdi
mov    -0x148(%rbp),%rsi
mov    %rax,%rdx
add    $0x1,%rdx
call   1050 <memcmp@plt>
cmp    $0x0,%rax
je     126c <DoStrTest+0x10c>
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
lea    -0x120(%rbp),%r8
lea    0xdde(%rip),%rdi
mov    $0x0,%al
call   1070 <Fail@plt>
add    $0x150,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<DoStrTest>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x108,%rsp
mov    %rdx,%r12
mov    %rsi,%r14
mov    %rdi,%r15
xorps  %xmm0,%xmm0
movaps %xmm0,0xf0(%rsp)
movaps %xmm0,0xe0(%rsp)
movaps %xmm0,0xd0(%rsp)
movaps %xmm0,0xc0(%rsp)
movaps %xmm0,0xb0(%rsp)
movaps %xmm0,0xa0(%rsp)
movaps %xmm0,0x90(%rsp)
movaps %xmm0,0x80(%rsp)
movaps %xmm0,0x70(%rsp)
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movaps %xmm0,(%rsp)
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1050 <_countof@plt>
mov    %r15,%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
mov    %eax,%ecx
call   1070 <sscanf_s@plt>
cmp    $0x1,%eax
je     1207 <DoStrTest+0xb7>
lea    0xe08(%rip),%rdi
mov    %eax,%esi
mov    %r15,%rdx
mov    %r14,%rcx
xor    %eax,%eax
call   1060 <Fail@plt>
mov    %r12,%rdi
call   1030 <strlen@plt>
lea    0x1(%rax),%rdx
mov    %rsp,%rsi
mov    %r12,%rdi
call   1040 <memcmp@plt>
test   %rax,%rax
je     123d <DoStrTest+0xed>
lea    0xe19(%rip),%rdi
mov    %rsp,%r8
mov    %r15,%rsi
mov    %r14,%rdx
mov    %r12,%rcx
xor    %eax,%eax
call   1060 <Fail@plt>
add    $0x108,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
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 = [82 x i8] c"ERROR: scanned string incorrectly from \22%s\22 using \22%s\22.\0AExpected \22%s\22, got \22%s\22.\0A\00"
define void @DoStrTest(i8* %0, i8* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca [256 x i8]
%8 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8* %2, i8** %6
%9 = bitcast [256 x i8]* %7 to i8*
%10 = load i8*, i8** %4
%11 = load i8*, i8** %5
%12 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%13 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%14 = call i32 @_countof(i8* %13)
%15 = call i32 @sscanf_s(i8* %10, i8* %11, i8* %12, i32 %14)
store i32 %15, i32* %8
%16 = load i32, i32* %8
%17 = icmp ne i32 %16, 1
br i1 %17, label %18, label %23
18: ; preds = %3
%19 = load i32, i32* %8
%20 = load i8*, i8** %4
%21 = load i8*, i8** %5
%22 = call i32 (i8*, ...) @Fail(i8* getelementptr inbounds ([67 x i8], [67 x i8]* @.str, i64 0, i64 0), i32 %19, i8* %20, i8* %21)
br label %23
23: ; preds = %18, %3
%24 = load i8*, i8** %6
%25 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%26 = load i8*, i8** %6
%27 = call i64 @strlen(i8* %26)
%28 = add nsw i64 %27, 1
%29 = call i64 @memcmp(i8* %24, i8* %25, i64 %28)
%30 = icmp ne i64 %29, 0
br i1 %30, label %31, label %37
31: ; preds = %23
%32 = load i8*, i8** %4
%33 = load i8*, i8** %5
%34 = load i8*, i8** %6
%35 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%36 = call i32 (i8*, ...) @Fail(i8* getelementptr inbounds ([82 x i8], [82 x i8]* @.str.1, i64 0, i64 0), i8* %32, i8* %33, i8* %34, i8* %35)
br label %37
37: ; preds = %31, %23
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 = [82 x i8] c"ERROR: scanned string incorrectly from \22%s\22 using \22%s\22.\0AExpected \22%s\22, got \22%s\22.\0A\00"
define void @DoStrTest(i8* %0, i8* %1, i8* %2) {
%4 = alloca [256 x i8]
%5 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%6 = call i32 @_countof(i8* %5)
%7 = call i32 @sscanf_s(i8* %0, i8* %1, i8* %5, i32 %6)
%8 = icmp eq i32 %7, 1
br i1 %8, label %11, label %9
9: ; preds = %3
%10 = call i32 (i8*, ...) @Fail(i8* getelementptr inbounds ([67 x i8], [67 x i8]* @.str, i64 0, i64 0), i32 %7, i8* %0, i8* %1)
br label %11
11: ; preds = %9, %3
%12 = call i64 @strlen(i8* dereferenceable(1) %2)
%13 = add nsw i64 %12, 1
%14 = call i64 @memcmp(i8* %2, i8* %5, i64 %13)
%15 = icmp eq i64 %14, 0
br i1 %15, label %18, label %16
16: ; preds = %11
%17 = call i32 (i8*, ...) @Fail(i8* getelementptr inbounds ([82 x i8], [82 x i8]* @.str.1, i64 0, i64 0), i8* %0, i8* %1, i8* %2, i8* %5)
br label %18
18: ; preds = %16, %11
ret void
}