#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 /*<<< orphan*/ sprintf(char *, char *, int);
int /*<<< orphan*/ strcat(char *, char *);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
void spfn_test(char *id, char *fmt, int v, char *res) {
  char buf[256];
  sprintf(buf, fmt, v);
  if (strcmp(buf, res)) {
    strcpy(buf, "sprintf(");
    strcat(buf, fmt);
    strcat(buf, ")-");
    strcat(buf, id);
    fail(buf);
  }
}


x86 assembly (clang, -O0):
<spfn_test>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
lea    -0x120(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1070 <sprintf@plt>
lea    -0x120(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
je     11e9 <spfn_test+0x99>
lea    -0x120(%rbp),%rdi
lea    0xe5b(%rip),%rsi
call   1030 <strcpy@plt>
lea    -0x120(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1060 <strcat@plt>
lea    -0x120(%rbp),%rdi
lea    0xe41(%rip),%rsi
call   1060 <strcat@plt>
lea    -0x120(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1060 <strcat@plt>
lea    -0x120(%rbp),%rdi
call   1040 <fail@plt>
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<spfn_test>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x108,%rsp
mov    %rcx,%rbx
mov    %rsi,%r15
mov    %rdi,%r14
mov    %rsp,%r12
mov    %r12,%rdi
call   1070 <sprintf@plt>
mov    %r12,%rdi
mov    %rbx,%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
je     11c1 <spfn_test+0x71>
lea    0xe77(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1030 <strcpy@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1060 <strcat@plt>
lea    0xe63(%rip),%rsi
mov    %rbx,%rdi
call   1060 <strcat@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1060 <strcat@plt>
mov    %rbx,%rdi
call   1040 <fail@plt>
add    $0x108,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [9 x i8] c"sprintf(\00"
@.str.1 = [3 x i8] c")-\00"
define void @spfn_test(i8* %0, i8* %1, i32 %2, i8* %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca [256 x i8]
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
store i8* %3, i8** %8
%10 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%11 = load i8*, i8** %6
%12 = load i32, i32* %7
%13 = call i32 @sprintf(i8* %10, i8* %11, i32 %12)
%14 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%15 = load i8*, i8** %8
%16 = call i64 @strcmp(i8* %14, i8* %15)
%17 = icmp ne i64 %16, 0
br i1 %17, label %18, label %31
18: ; preds = %4
%19 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%20 = call i32 @strcpy(i8* %19, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%21 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%22 = load i8*, i8** %6
%23 = call i32 @strcat(i8* %21, i8* %22)
%24 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%25 = call i32 @strcat(i8* %24, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%26 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%27 = load i8*, i8** %5
%28 = call i32 @strcat(i8* %26, i8* %27)
%29 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%30 = call i32 @fail(i8* %29)
br label %31
31: ; preds = %18, %4
ret void
}

LLVM IR (-O2):
@.str = [9 x i8] c"sprintf(\00"
@.str.1 = [3 x i8] c")-\00"
define void @spfn_test(i8* %0, i8* %1, i32 %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) %1, i32 %2)
%8 = call i64 @strcmp(i8* %6, i8* %3)
%9 = icmp eq i64 %8, 0
br i1 %9, label %16, label %10
10: ; preds = %4
%11 = call i32 @strcpy(i8* %6, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%12 = call i32 @strcat(i8* %6, i8* %1)
%13 = call i32 @strcat(i8* %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%14 = call i32 @strcat(i8* %6, i8* %0)
%15 = call i32 @fail(i8* %6)
br label %16
16: ; preds = %10, %4
ret void
}