#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 const *, scalar_t__);
int /*<<< orphan*/ sprintf_s(char *, int /*<<< orphan*/, char const *, int *);
scalar_t__ strlen(char const *);
void DoCountTest(const char *formatstr, int param, const char *checkstr) {
  char buf[512] = {0};
  int n = -1;
  sprintf_s(buf, _countof(buf), formatstr, &n);
  if (n != param) {
    Fail("ERROR: Expected count parameter to resolve to %d, got %X\n", param,
         n);
  }
  if (memcmp(buf, checkstr, strlen(checkstr) + 1) != 0) {
    Fail("ERROR: Expected \"%s\" got \"%s\".\n", checkstr, buf);
  }
}


x86 assembly (clang, -O0):
<DoCountTest>:
push   %rbp
mov    %rsp,%rbp
sub    $0x240,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
lea    -0x220(%rbp),%rdi
xor    %esi,%esi
mov    $0x200,%edx
call   1050 <memset@plt>
movl   $0xffffffff,-0x224(%rbp)
ff ff ff
lea    -0x220(%rbp),%rax
mov    %rax,-0x230(%rbp)
lea    -0x220(%rbp),%rdi
call   1070 <_countof@plt>
mov    -0x230(%rbp),%rdi
mov    %eax,%esi
mov    -0x8(%rbp),%rdx
lea    -0x224(%rbp),%rcx
call   1030 <sprintf_s@plt>
mov    -0x224(%rbp),%eax
cmp    -0xc(%rbp),%eax
je     11ec <DoCountTest+0x8c>
mov    -0xc(%rbp),%esi
mov    -0x224(%rbp),%edx
lea    0xe1b(%rip),%rdi
mov    $0x0,%al
call   1080 <Fail@plt>
lea    -0x220(%rbp),%rax
mov    %rax,-0x240(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x238(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x240(%rbp),%rdi
mov    -0x238(%rbp),%rsi
mov    %rax,%rdx
add    $0x1,%rdx
call   1060 <memcmp@plt>
cmp    $0x0,%rax
je     124b <DoCountTest+0xeb>
mov    -0x18(%rbp),%rsi
lea    -0x220(%rbp),%rdx
lea    0xdf6(%rip),%rdi
mov    $0x0,%al
call   1080 <Fail@plt>
add    $0x240,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<DoCountTest>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x218,%rsp
mov    %rdx,%r14
mov    %esi,%r15d
mov    %rdi,%rbx
lea    0x10(%rsp),%rbp
mov    $0x200,%edx
mov    %rbp,%rdi
xor    %esi,%esi
call   1050 <memset@plt>
movl   $0xffffffff,0xc(%rsp)
ff
mov    %rbp,%rdi
call   1070 <_countof@plt>
lea    0xc(%rsp),%rcx
mov    %rbp,%rdi
mov    %eax,%esi
mov    %rbx,%rdx
call   1030 <sprintf_s@plt>
mov    0xc(%rsp),%edx
cmp    %r15d,%edx
je     11c6 <DoCountTest+0x66>
lea    0xe44(%rip),%rdi
mov    %r15d,%esi
xor    %eax,%eax
call   1080 <Fail@plt>
mov    %r14,%rdi
call   1040 <strlen@plt>
lea    0x1(%rax),%rdx
lea    0x10(%rsp),%rdi
mov    %r14,%rsi
call   1060 <memcmp@plt>
test   %rax,%rax
je     11fa <DoCountTest+0x9a>
lea    0xe4f(%rip),%rdi
lea    0x10(%rsp),%rdx
mov    %r14,%rsi
xor    %eax,%eax
call   1080 <Fail@plt>
add    $0x218,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [58 x i8] c"ERROR: Expected count parameter to resolve to %d, got %X\0A\00"
@.str.1 = [32 x i8] c"ERROR: Expected \22%s\22 got \22%s\22.\0A\00"
define void @DoCountTest(i8* %0, i32 %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca [512 x i8]
%8 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
store i8* %2, i8** %6
%9 = bitcast [512 x i8]* %7 to i8*
store i32 -1, i32* %8
%10 = getelementptr inbounds [512 x i8], [512 x i8]* %7, i64 0, i64 0
%11 = getelementptr inbounds [512 x i8], [512 x i8]* %7, i64 0, i64 0
%12 = call i32 @_countof(i8* %11)
%13 = load i8*, i8** %4
%14 = call i32 @sprintf_s(i8* %10, i32 %12, i8* %13, i32* %8)
%15 = load i32, i32* %8
%16 = load i32, i32* %5
%17 = icmp ne i32 %15, %16
br i1 %17, label %18, label %22
18: ; preds = %3
%19 = load i32, i32* %5
%20 = load i32, i32* %8
%21 = call i32 (i8*, ...) @Fail(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str, i64 0, i64 0), i32 %19, i32 %20)
br label %22
22: ; preds = %18, %3
%23 = getelementptr inbounds [512 x i8], [512 x i8]* %7, i64 0, i64 0
%24 = load i8*, i8** %6
%25 = load i8*, i8** %6
%26 = call i64 @strlen(i8* %25)
%27 = add nsw i64 %26, 1
%28 = call i64 @memcmp(i8* %23, i8* %24, i64 %27)
%29 = icmp ne i64 %28, 0
br i1 %29, label %30, label %34
30: ; preds = %22
%31 = load i8*, i8** %6
%32 = getelementptr inbounds [512 x i8], [512 x i8]* %7, i64 0, i64 0
%33 = call i32 (i8*, ...) @Fail(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i8* %31, i8* %32)
br label %34
34: ; preds = %30, %22
ret void
}

LLVM IR (-O2):
@.str = [58 x i8] c"ERROR: Expected count parameter to resolve to %d, got %X\0A\00"
@.str.1 = [32 x i8] c"ERROR: Expected \22%s\22 got \22%s\22.\0A\00"
define void @DoCountTest(i8* %0, i32 %1, i8* %2) {
%4 = alloca [512 x i8]
%5 = alloca i32
%6 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 0
%7 = bitcast i32* %5 to i8*
store i32 -1, i32* %5
%8 = call i32 @_countof(i8* %6)
%9 = call i32 @sprintf_s(i8* %6, i32 %8, i8* %0, i32* %5)
%10 = load i32, i32* %5
%11 = icmp eq i32 %10, %1
br i1 %11, label %14, label %12
12: ; preds = %3
%13 = call i32 (i8*, ...) @Fail(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str, i64 0, i64 0), i32 %1, i32 %10)
br label %14
14: ; preds = %12, %3
%15 = call i64 @strlen(i8* dereferenceable(1) %2)
%16 = add nsw i64 %15, 1
%17 = call i64 @memcmp(i8* %6, i8* %2, i64 %16)
%18 = icmp eq i64 %17, 0
br i1 %18, label %21, label %19
19: ; preds = %14
%20 = call i32 (i8*, ...) @Fail(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i8* %2, i8* %6)
br label %21
21: ; preds = %19, %14
ret void
}