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


x86 assembly (clang, -O0):
<DoNumTest>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
lea    -0x120(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1040 <memset@plt>
lea    -0x120(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0xc(%rbp),%edx
call   1070 <sprintf@plt>
lea    -0x120(%rbp),%rax
mov    %rax,-0x130(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x128(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x130(%rbp),%rdi
mov    -0x128(%rbp),%rsi
mov    %rax,%rdx
add    $0x1,%rdx
call   1050 <memcmp@plt>
cmp    $0x0,%rax
je     11f0 <DoNumTest+0xa0>
mov    -0xc(%rbp),%esi
mov    -0x8(%rbp),%rdx
mov    -0x18(%rbp),%rcx
lea    -0x120(%rbp),%r8
lea    0xe15(%rip),%rdi
call   1060 <Fail@plt>
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<DoNumTest>:
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
mov    %r14,%rsi
mov    %r15d,%edx
call   1060 <sprintf@plt>
mov    %rbx,%rdi
call   1030 <strlen@plt>
lea    0x1(%rax),%rdx
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1040 <memcmp@plt>
test   %rax,%rax
je     1205 <DoNumTest+0xc5>
lea    0xe0c(%rip),%rdi
mov    %rsp,%r8
mov    %r15d,%esi
mov    %r14,%rdx
mov    %rbx,%rcx
call   1050 <Fail@plt>
add    $0x108,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [63 x i8] c"ERROR: failed to insert %#x into \22%s\22\0AExpected \22%s\22 got \22%s\22.\0A\00"
define void @DoNumTest(i8* %0, i32 %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca [256 x i8]
store i8* %0, i8** %4
store i32 %1, i32* %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 = load i8*, i8** %4
%11 = load i32, i32* %5
%12 = call i32 @sprintf(i8* %9, i8* %10, i32 %11)
%13 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%14 = load i8*, i8** %6
%15 = load i8*, i8** %6
%16 = call i64 @strlen(i8* %15)
%17 = add nsw i64 %16, 1
%18 = call i64 @memcmp(i8* %13, i8* %14, i64 %17)
%19 = icmp ne i64 %18, 0
br i1 %19, label %20, label %26
20: ; preds = %3
%21 = load i32, i32* %5
%22 = load i8*, i8** %4
%23 = load i8*, i8** %6
%24 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%25 = call i32 @Fail(i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str, i64 0, i64 0), i32 %21, i8* %22, i8* %23, i8* %24)
br label %26
26: ; preds = %20, %3
ret void
}

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