#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 DoVprintf(char *, int *);
int /*<<< orphan*/ Fail(char *, int, int);
int strlen(char *);
void DoCountTest(char *formatstr, int param, char *checkstr) {
  int ret;
  int n = -1;
  ret = DoVprintf(formatstr, &n);
  if (n != param) {
    Fail("Expected count parameter to resolve to %d, got %d\n", param, n);
  }
  if (ret != strlen(checkstr)) {
    Fail("Expected vprintf to return %d, got %d.\n", strlen(checkstr), ret);
  }
}


x86 assembly (clang, -O0):
<DoCountTest>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0xffffffff,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1040 <DoVprintf@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0xc(%rbp),%eax
je     1178 <DoCountTest+0x48>
mov    -0xc(%rbp),%esi
mov    -0x20(%rbp),%edx
lea    0xe8d(%rip),%rdi
call   1050 <Fail@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x24(%rbp),%eax
cmp    %ecx,%eax
je     11ae <DoCountTest+0x7e>
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%esi
mov    -0x1c(%rbp),%edx
lea    0xe8a(%rip),%rdi
call   1050 <Fail@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<DoCountTest>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdx,%r14
mov    %esi,%ebx
movl   $0xffffffff,0xc(%rsp)
ff
lea    0xc(%rsp),%rsi
call   1040 <DoVprintf@plt>
mov    %eax,%ebp
mov    0xc(%rsp),%edx
cmp    %ebx,%edx
je     1167 <DoCountTest+0x37>
lea    0xea0(%rip),%rdi
mov    %ebx,%esi
call   1050 <Fail@plt>
mov    %r14,%rdi
call   1030 <strlen@plt>
cmp    %eax,%ebp
je     118b <DoCountTest+0x5b>
mov    %r14,%rdi
call   1030 <strlen@plt>
lea    0xeb1(%rip),%rdi
mov    %eax,%esi
mov    %ebp,%edx
call   1050 <Fail@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [51 x i8] c"Expected count parameter to resolve to %d, got %d\0A\00"
@.str.1 = [40 x i8] c"Expected vprintf to return %d, got %d.\0A\00"
define void @DoCountTest(i8* %0, i32 %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
store i8* %2, i8** %6
store i32 -1, i32* %8
%9 = load i8*, i8** %4
%10 = call i32 @DoVprintf(i8* %9, i32* %8)
store i32 %10, i32* %7
%11 = load i32, i32* %8
%12 = load i32, i32* %5
%13 = icmp ne i32 %11, %12
br i1 %13, label %14, label %18
14: ; preds = %3
%15 = load i32, i32* %5
%16 = load i32, i32* %8
%17 = call i32 @Fail(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str, i64 0, i64 0), i32 %15, i32 %16)
br label %18
18: ; preds = %14, %3
%19 = load i32, i32* %7
%20 = load i8*, i8** %6
%21 = call i32 @strlen(i8* %20)
%22 = icmp ne i32 %19, %21
br i1 %22, label %23, label %28
23: ; preds = %18
%24 = load i8*, i8** %6
%25 = call i32 @strlen(i8* %24)
%26 = load i32, i32* %7
%27 = call i32 @Fail(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0), i32 %25, i32 %26)
br label %28
28: ; preds = %23, %18
ret void
}

LLVM IR (-O2):
@.str = [51 x i8] c"Expected count parameter to resolve to %d, got %d\0A\00"
@.str.1 = [40 x i8] c"Expected vprintf to return %d, got %d.\0A\00"
define void @DoCountTest(i8* %0, i32 %1, i8* %2) {
%4 = alloca i32
%5 = bitcast i32* %4 to i8*
store i32 -1, i32* %4
%6 = call i32 @DoVprintf(i8* %0, i32* %4)
%7 = load i32, i32* %4
%8 = icmp eq i32 %7, %1
br i1 %8, label %11, label %9
9: ; preds = %3
%10 = call i32 @Fail(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str, i64 0, i64 0), i32 %1, i32 %7)
br label %11
11: ; preds = %9, %3
%12 = call i32 @strlen(i8* %2)
%13 = icmp eq i32 %6, %12
br i1 %13, label %17, label %14
14: ; preds = %11
%15 = call i32 @strlen(i8* %2)
%16 = call i32 @Fail(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0), i32 %15, i32 %6)
br label %17
17: ; preds = %14, %11
ret void
}