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


x86 assembly (clang, -O0):
<DoShortCountTest>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
movw   $0xffff,-0x1e(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x1e(%rbp),%rsi
call   1040 <printf@plt>
mov    %eax,-0x1c(%rbp)
movswl -0x1e(%rbp),%eax
cmp    -0xc(%rbp),%eax
je     1179 <DoShortCountTest+0x49>
mov    -0xc(%rbp),%esi
movswl -0x1e(%rbp),%edx
lea    0xe8c(%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     11af <DoShortCountTest+0x7f>
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%esi
mov    -0x1c(%rbp),%edx
lea    0xe89(%rip),%rdi
call   1050 <Fail@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<DoShortCountTest>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdx,%r14
mov    %esi,%ebx
movw   $0xffff,0xe(%rsp)
lea    0xe(%rsp),%rsi
call   1040 <printf@plt>
mov    %eax,%ebp
movswl 0xe(%rsp),%edx
cmp    %ebx,%edx
je     1167 <DoShortCountTest+0x37>
lea    0xea0(%rip),%rdi
mov    %ebx,%esi
call   1050 <Fail@plt>
mov    %r14,%rdi
call   1030 <strlen@plt>
cmp    %eax,%ebp
je     118b <DoShortCountTest+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 = [39 x i8] c"Expected printf to return %d, got %d.\0A\00"
define void @DoShortCountTest(i8* %0, i32 %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i16
store i8* %0, i8** %4
store i32 %1, i32* %5
store i8* %2, i8** %6
store i16 -1, i16* %8
%9 = load i8*, i8** %4
%10 = call i32 @printf(i8* %9, i16* %8)
store i32 %10, i32* %7
%11 = load i16, i16* %8
%12 = sext i16 %11 to i32
%13 = load i32, i32* %5
%14 = icmp ne i32 %12, %13
br i1 %14, label %15, label %20
15: ; preds = %3
%16 = load i32, i32* %5
%17 = load i16, i16* %8
%18 = sext i16 %17 to i32
%19 = call i32 @Fail(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str, i64 0, i64 0), i32 %16, i32 %18)
br label %20
20: ; preds = %15, %3
%21 = load i32, i32* %7
%22 = load i8*, i8** %6
%23 = call i32 @strlen(i8* %22)
%24 = icmp ne i32 %21, %23
br i1 %24, label %25, label %30
25: ; preds = %20
%26 = load i8*, i8** %6
%27 = call i32 @strlen(i8* %26)
%28 = load i32, i32* %7
%29 = call i32 @Fail(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0), i32 %27, i32 %28)
br label %30
30: ; preds = %25, %20
ret void
}

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