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


x86 assembly (clang, -O0):
<DoPointerTest>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
lea    -0x120(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1040 <memset@plt>
lea    -0x120(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rdx
call   1070 <sprintf@plt>
lea    -0x120(%rbp),%rax
mov    %rax,-0x130(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x128(%rbp)
mov    -0x20(%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     11f7 <DoPointerTest+0xa7>
mov    -0x18(%rbp),%rsi
mov    -0x8(%rbp),%rdx
mov    -0x20(%rbp),%rcx
lea    -0x120(%rbp),%r8
lea    0xe0e(%rip),%rdi
call   1060 <Fail@plt>
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<DoPointerTest>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x108,%rsp
mov    %rcx,%rbx
mov    %rdx,%r14
mov    %rsi,%rdx
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,%r12
mov    %r12,%rdi
mov    %r15,%rsi
call   1060 <sprintf@plt>
mov    %rbx,%rdi
call   1030 <strlen@plt>
lea    0x1(%rax),%rdx
mov    %r12,%rdi
mov    %rbx,%rsi
call   1040 <memcmp@plt>
test   %rax,%rax
je     1206 <DoPointerTest+0xc6>
lea    0xe0b(%rip),%rdi
mov    %rsp,%r8
mov    %r14,%rsi
mov    %r15,%rdx
mov    %rbx,%rcx
call   1050 <Fail@plt>
add    $0x108,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [62 x i8] c"ERROR: failed to insert %s into \22%s\22\0AExpected \22%s\22 got \22%s\22.\0A\00"
define void @DoPointerTest(i8* %0, i8* %1, i8* %2, i8* %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca [256 x i8]
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
store i8* %3, i8** %8
%10 = bitcast [256 x i8]* %9 to i8*
%11 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%12 = load i8*, i8** %5
%13 = load i8*, i8** %6
%14 = call i32 @sprintf(i8* %11, i8* %12, i8* %13)
%15 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%16 = load i8*, i8** %8
%17 = load i8*, i8** %8
%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 %28
22: ; preds = %4
%23 = load i8*, i8** %7
%24 = load i8*, i8** %5
%25 = load i8*, i8** %8
%26 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%27 = call i32 @Fail(i8* getelementptr inbounds ([62 x i8], [62 x i8]* @.str, i64 0, i64 0), i8* %23, i8* %24, i8* %25, i8* %26)
br label %28
28: ; preds = %22, %4
ret void
}

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