#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 *, char, char, char const *, char const *, char *);
int /*<<< orphan*/ _countof(char *);
scalar_t__ memcmp(char *, char const *, scalar_t__);
int /*<<< orphan*/ sprintf_s(char *, int /*<<< orphan*/, char const *, char);
scalar_t__ strlen(char const *);
void DoCharTest(const char *formatstr, char param, const char *checkstr) {
  char buf[256] = {0};
  sprintf_s(buf, _countof(buf), formatstr, param);
  if (memcmp(buf, checkstr, strlen(checkstr) + 1) != 0) {
    Fail("ERROR: failed to insert char \'%c\' (%d) into \"%s\"\n"
         "Expected \"%s\" got \"%s\".\n",
         param, param, formatstr, checkstr, buf);
  }
}


x86 assembly (clang, -O0):
<DoCharTest>:
push   %rbp
mov    %rsp,%rbp
sub    $0x140,%rsp
mov    %sil,%al
mov    %rdi,-0x8(%rbp)
mov    %al,-0x9(%rbp)
mov    %rdx,-0x18(%rbp)
lea    -0x120(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1050 <memset@plt>
lea    -0x120(%rbp),%rax
mov    %rax,-0x138(%rbp)
lea    -0x120(%rbp),%rdi
call   1070 <_countof@plt>
mov    -0x138(%rbp),%rdi
mov    %eax,%esi
mov    -0x8(%rbp),%rdx
movsbl -0x9(%rbp),%ecx
call   1030 <sprintf_s@plt>
lea    -0x120(%rbp),%rax
mov    %rax,-0x130(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x128(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x130(%rbp),%rdi
mov    -0x128(%rbp),%rsi
mov    %rax,%rdx
add    $0x1,%rdx
call   1060 <memcmp@plt>
cmp    $0x0,%rax
je     1229 <DoCharTest+0xc9>
mov    -0x9(%rbp),%dl
mov    -0x9(%rbp),%al
mov    -0x8(%rbp),%rcx
mov    -0x18(%rbp),%r8
lea    -0x120(%rbp),%r9
lea    0xde2(%rip),%rdi
movsbl %dl,%esi
movsbl %al,%edx
call   1080 <Fail@plt>
add    $0x140,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<DoCharTest>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x108,%rsp
mov    %rdx,%rbx
mov    %esi,%r15d
mov    %rdi,%r14
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,%rbp
mov    %rbp,%rdi
call   1060 <_countof@plt>
mov    %rbp,%rdi
mov    %eax,%esi
mov    %r14,%rdx
mov    %r15d,%ecx
call   1030 <sprintf_s@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
lea    0x1(%rax),%rdx
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1050 <memcmp@plt>
test   %rax,%rax
je     1222 <DoCharTest+0xd2>
movsbl %r15b,%edx
lea    0xdee(%rip),%rdi
mov    %rsp,%r9
mov    %edx,%esi
mov    %r14,%rcx
mov    %rbx,%r8
call   1070 <Fail@plt>
add    $0x108,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [74 x i8] c"ERROR: failed to insert char '%c' (%d) into \22%s\22\0AExpected \22%s\22 got \22%s\22.\0A\00"
define void @DoCharTest(i8* %0, i8 signext %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i8
%6 = alloca i8*
%7 = alloca [256 x i8]
store i8* %0, i8** %4
store i8 %1, i8* %5
store i8* %2, i8** %6
%8 = bitcast [256 x i8]* %7 to i8*
%9 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%10 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%11 = call i32 @_countof(i8* %10)
%12 = load i8*, i8** %4
%13 = load i8, i8* %5
%14 = call i32 @sprintf_s(i8* %9, i32 %11, i8* %12, i8 signext %13)
%15 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%16 = load i8*, i8** %6
%17 = load i8*, i8** %6
%18 = call i64 @strlen(i8* %17)
%19 = add nsw i64 %18, 1
%20 = call i64 @memcmp(i8* %15, i8* %16, i64 %19)
%21 = icmp ne i64 %20, 0
br i1 %21, label %22, label %29
22: ; preds = %3
%23 = load i8, i8* %5
%24 = load i8, i8* %5
%25 = load i8*, i8** %4
%26 = load i8*, i8** %6
%27 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%28 = call i32 @Fail(i8* getelementptr inbounds ([74 x i8], [74 x i8]* @.str, i64 0, i64 0), i8 signext %23, i8 signext %24, i8* %25, i8* %26, i8* %27)
br label %29
29: ; preds = %22, %3
ret void
}

LLVM IR (-O2):
@.str = [74 x i8] c"ERROR: failed to insert char '%c' (%d) into \22%s\22\0AExpected \22%s\22 got \22%s\22.\0A\00"
define void @DoCharTest(i8* %0, i8 signext %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 @sprintf_s(i8* %5, i32 %6, i8* %0, i8 signext %1)
%8 = call i64 @strlen(i8* dereferenceable(1) %2)
%9 = add nsw i64 %8, 1
%10 = call i64 @memcmp(i8* %5, i8* %2, i64 %9)
%11 = icmp eq i64 %10, 0
br i1 %11, label %14, label %12
12: ; preds = %3
%13 = call i32 @Fail(i8* getelementptr inbounds ([74 x i8], [74 x i8]* @.str, i64 0, i64 0), i8 signext %1, i8 signext %1, i8* %0, i8* %2, i8* %5)
br label %14
14: ; preds = %12, %3
ret void
}