#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*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, char const *, ...);
int /*<<< orphan*/ puts(char *);
scalar_t__ sprintf(char *, char const *, int, int, int, char *);
scalar_t__ strcmp(char *, char const *);
int format_failed(const char *fmt, const char *expected) {
  char output[80];
  printf("%s : ", fmt);
  memset(output, 0, sizeof output);
  if (sprintf(output, fmt, 1, 2, 3, "test") > 0 &&
      strcmp(output, expected) != 0) {
    printf("FAIL (output '%s' != expected '%s')\n", output, expected);
    return 1;
  }
  puts("ok");
  return 0;
}


x86 assembly (clang, -O0):
<format_failed>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xe95(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x70(%rbp),%rdi
xor    %esi,%esi
mov    $0x50,%edx
call   1050 <memset@plt>
lea    -0x70(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0x1,%edx
mov    $0x2,%ecx
mov    $0x3,%r8d
lea    0xe65(%rip),%r9
call   1070 <sprintf@plt>
cmp    $0x0,%rax
jle    11e9 <format_failed+0x99>
lea    -0x70(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
je     11e9 <format_failed+0x99>
lea    -0x70(%rbp),%rsi
mov    -0x18(%rbp),%rdx
lea    0xe35(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    11fc <format_failed+0xac>
lea    0xe40(%rip),%rdi
call   1030 <puts@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<format_failed>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x58,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0xe99(%rip),%rdi
xor    %r15d,%r15d
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rsp,%rbp
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0x50,%edx
call   1050 <memset@plt>
lea    0xe79(%rip),%r9
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    $0x1,%edx
mov    $0x2,%ecx
mov    $0x3,%r8d
call   1070 <sprintf@plt>
test   %rax,%rax
jle    11d9 <format_failed+0x89>
mov    %rsp,%rdi
mov    %r14,%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
je     11d9 <format_failed+0x89>
lea    0xe47(%rip),%rdi
mov    %rsp,%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%r15d
jmp    11e5 <format_failed+0x95>
lea    0xe50(%rip),%rdi
call   1030 <puts@plt>
mov    %r15d,%eax
add    $0x58,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [6 x i8] c"%s : \00"
@.str.1 = [5 x i8] c"test\00"
@.str.2 = [37 x i8] c"FAIL (output '%s' != expected '%s')\0A\00"
@.str.3 = [3 x i8] c"ok\00"
define i32 @format_failed(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca [80 x i8]
store i8* %0, i8** %4
store i8* %1, i8** %5
%7 = load i8*, i8** %4
%8 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %7)
%9 = getelementptr inbounds [80 x i8], [80 x i8]* %6, i64 0, i64 0
%10 = call i32 @memset(i8* %9, i32 0, i32 80)
%11 = getelementptr inbounds [80 x i8], [80 x i8]* %6, i64 0, i64 0
%12 = load i8*, i8** %4
%13 = call i64 @sprintf(i8* %11, i8* %12, i32 1, i32 2, i32 3, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%14 = icmp sgt i64 %13, 0
br i1 %14, label %15, label %24
15: ; preds = %2
%16 = getelementptr inbounds [80 x i8], [80 x i8]* %6, i64 0, i64 0
%17 = load i8*, i8** %5
%18 = call i64 @strcmp(i8* %16, i8* %17)
%19 = icmp ne i64 %18, 0
br i1 %19, label %20, label %24
20: ; preds = %15
%21 = getelementptr inbounds [80 x i8], [80 x i8]* %6, i64 0, i64 0
%22 = load i8*, i8** %5
%23 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0), i8* %21, i8* %22)
store i32 1, i32* %3
br label %26
24: ; preds = %15, %2
%25 = call i32 @puts(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %3
br label %26
26: ; preds = %24, %20
%27 = load i32, i32* %3
ret i32 %27
}

LLVM IR (-O2):
@.str = [6 x i8] c"%s : \00"
@.str.1 = [5 x i8] c"test\00"
@.str.2 = [37 x i8] c"FAIL (output '%s' != expected '%s')\0A\00"
@.str.3 = [3 x i8] c"ok\00"
define i32 @format_failed(i8* %0, i8* %1) {
%3 = alloca [80 x i8]
%4 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
%5 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %0)
%6 = call i32 @memset(i8* %4, i32 0, i32 80)
%7 = call i64 @sprintf(i8* %4, i8* %0, i32 1, i32 2, i32 3, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%8 = icmp sgt i64 %7, 0
br i1 %8, label %9, label %14
9: ; preds = %2
%10 = call i64 @strcmp(i8* %4, i8* %1)
%11 = icmp eq i64 %10, 0
br i1 %11, label %14, label %12
12: ; preds = %9
%13 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0), i8* %4, i8* %1)
br label %16
14: ; preds = %9, %2
%15 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
br label %16
16: ; preds = %14, %12
%17 = phi i32 [ 1, %12 ], [ 0, %14 ]
ret i32 %17
}