#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 *, short *);
scalar_t__ strlen(char const *);
void DoShortCountTest(const char *formatstr, int param, const char *checkstr) {
  char buf[256] = {0};
  short 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):
<DoShortCountTest>:
push   %rbp
mov    %rsp,%rbp
sub    $0x140,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
lea    -0x120(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1050 <memset@plt>
movw   $0xffff,-0x122(%rbp)
ff ff
lea    -0x120(%rbp),%rax
mov    %rax,-0x130(%rbp)
lea    -0x120(%rbp),%rdi
call   1070 <_countof@plt>
mov    -0x130(%rbp),%rdi
mov    %eax,%esi
mov    -0x8(%rbp),%rdx
lea    -0x122(%rbp),%rcx
call   1030 <sprintf_s@plt>
movswl -0x122(%rbp),%eax
cmp    -0xc(%rbp),%eax
je     11ed <DoShortCountTest+0x8d>
mov    -0xc(%rbp),%esi
movswl -0x122(%rbp),%edx
lea    0xe1a(%rip),%rdi
mov    $0x0,%al
call   1080 <Fail@plt>
lea    -0x120(%rbp),%rax
mov    %rax,-0x140(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x138(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x140(%rbp),%rdi
mov    -0x138(%rbp),%rsi
mov    %rax,%rdx
add    $0x1,%rdx
call   1060 <memcmp@plt>
cmp    $0x0,%rax
je     124c <DoShortCountTest+0xec>
mov    -0x18(%rbp),%rsi
lea    -0x120(%rbp),%rdx
lea    0xdf5(%rip),%rdi
mov    $0x0,%al
call   1080 <Fail@plt>
add    $0x140,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<DoShortCountTest>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x118,%rsp
mov    %rdx,%r15
mov    %esi,%r14d
mov    %rdi,%rbp
xorps  %xmm0,%xmm0
movaps %xmm0,0x100(%rsp)
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)
movw   $0xffff,0xe(%rsp)
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
call   1060 <_countof@plt>
lea    0xe(%rsp),%rcx
mov    %rbx,%rdi
mov    %eax,%esi
mov    %rbp,%rdx
call   1030 <sprintf_s@plt>
movswl 0xe(%rsp),%edx
cmp    %r14d,%edx
je     1215 <DoShortCountTest+0xc5>
lea    0xdf5(%rip),%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1070 <Fail@plt>
mov    %r15,%rdi
call   1040 <strlen@plt>
lea    0x1(%rax),%rdx
lea    0x10(%rsp),%rdi
mov    %r15,%rsi
call   1050 <memcmp@plt>
test   %rax,%rax
je     1249 <DoShortCountTest+0xf9>
lea    0xe00(%rip),%rdi
lea    0x10(%rsp),%rdx
mov    %r15,%rsi
xor    %eax,%eax
call   1070 <Fail@plt>
add    $0x118,%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 @DoShortCountTest(i8* %0, i32 %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca [256 x i8]
%8 = alloca i16
store i8* %0, i8** %4
store i32 %1, i32* %5
store i8* %2, i8** %6
%9 = bitcast [256 x i8]* %7 to i8*
store i16 -1, i16* %8
%10 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%11 = getelementptr inbounds [256 x i8], [256 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, i16* %8)
%15 = load i16, i16* %8
%16 = sext i16 %15 to i32
%17 = load i32, i32* %5
%18 = icmp ne i32 %16, %17
br i1 %18, label %19, label %24
19: ; preds = %3
%20 = load i32, i32* %5
%21 = load i16, i16* %8
%22 = sext i16 %21 to i32
%23 = call i32 (i8*, ...) @Fail(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str, i64 0, i64 0), i32 %20, i32 %22)
br label %24
24: ; preds = %19, %3
%25 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%26 = load i8*, i8** %6
%27 = load i8*, i8** %6
%28 = call i64 @strlen(i8* %27)
%29 = add nsw i64 %28, 1
%30 = call i64 @memcmp(i8* %25, i8* %26, i64 %29)
%31 = icmp ne i64 %30, 0
br i1 %31, label %32, label %36
32: ; preds = %24
%33 = load i8*, i8** %6
%34 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%35 = call i32 (i8*, ...) @Fail(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i8* %33, i8* %34)
br label %36
36: ; preds = %32, %24
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 @DoShortCountTest(i8* %0, i32 %1, i8* %2) {
%4 = alloca [256 x i8]
%5 = alloca i16
%6 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%7 = bitcast i16* %5 to i8*
store i16 -1, i16* %5
%8 = call i32 @_countof(i8* %6)
%9 = call i32 @sprintf_s(i8* %6, i32 %8, i8* %0, i16* %5)
%10 = load i16, i16* %5
%11 = sext i16 %10 to i32
%12 = icmp eq i32 %11, %1
br i1 %12, label %15, label %13
13: ; preds = %3
%14 = call i32 (i8*, ...) @Fail(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str, i64 0, i64 0), i32 %1, i32 %11)
br label %15
15: ; preds = %13, %3
%16 = call i64 @strlen(i8* dereferenceable(1) %2)
%17 = add nsw i64 %16, 1
%18 = call i64 @memcmp(i8* %6, i8* %2, i64 %17)
%19 = icmp eq i64 %18, 0
br i1 %19, label %22, label %20
20: ; preds = %15
%21 = 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 %22
22: ; preds = %20, %15
ret void
}