#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 */
typedef int /*<<< orphan*/ buffer;

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ errx(int /*<<< orphan*/, char *, ...);
scalar_t__ snprintf(char *, int, char *, char *, char *);
scalar_t__ strcmp(char *, char *);
void snprintf__two_formatters(void) {
  char buffer[128];
  if (snprintf(buffer, sizeof(buffer), "%s, %s!", "Hello", "tests") <= 0)
    errx(EXIT_FAILURE, "snprintf with two formatters failed");
  if (strcmp(buffer, "Hello, tests!") != 0)
    errx(EXIT_FAILURE, "Bad formatting: got %s", buffer);
}


x86 assembly (clang, -O0):
<snprintf__two_formatters>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
lea    -0x80(%rbp),%rdi
mov    $0x80,%esi
lea    0xeb5(%rip),%rdx
lea    0xeb6(%rip),%rcx
lea    0xeb5(%rip),%r8
call   1040 <snprintf@plt>
cmp    $0x0,%rax
jg     117f <snprintf__two_formatters+0x4f>
mov    0x2e71(%rip),%rax
mov    (%rax),%edi
lea    0xe9c(%rip),%rsi
mov    $0x0,%al
call   1030 <errx@plt>
lea    -0x80(%rbp),%rdi
lea    0xeae(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
je     11b4 <snprintf__two_formatters+0x84>
mov    0x2e40(%rip),%rax
mov    (%rax),%edi
lea    -0x80(%rbp),%rdx
lea    0xe99(%rip),%rsi
mov    $0x0,%al
call   1030 <errx@plt>
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<snprintf__two_formatters>:
sub    $0x88,%rsp
lea    0xec2(%rip),%rdx
lea    0xec3(%rip),%rcx
lea    0xec2(%rip),%r8
mov    %rsp,%rdi
mov    $0x80,%esi
call   1040 <snprintf@plt>
test   %rax,%rax
jg     1175 <snprintf__two_formatters+0x45>
mov    0x2e7b(%rip),%rax
mov    (%rax),%edi
lea    0xea6(%rip),%rsi
xor    %eax,%eax
call   1030 <errx@plt>
lea    0xebc(%rip),%rsi
mov    %rsp,%rdi
call   1050 <strcmp@plt>
test   %rax,%rax
je     11a3 <snprintf__two_formatters+0x73>
mov    0x2e50(%rip),%rax
mov    (%rax),%edi
lea    0xead(%rip),%rsi
mov    %rsp,%rdx
xor    %eax,%eax
call   1030 <errx@plt>
add    $0x88,%rsp
ret

LLVM IR (-O0):
@.str = [8 x i8] c"%s, %s!\00"
@.str.1 = [6 x i8] c"Hello\00"
@.str.2 = [6 x i8] c"tests\00"
@EXIT_FAILURE = global i32 0
@.str.3 = [36 x i8] c"snprintf with two formatters failed\00"
@.str.4 = [14 x i8] c"Hello, tests!\00"
@.str.5 = [23 x i8] c"Bad formatting: got %s\00"
define void @snprintf__two_formatters() {
%1 = alloca [128 x i8]
%2 = getelementptr inbounds [128 x i8], [128 x i8]* %1, i64 0, i64 0
%3 = call i64 @snprintf(i8* %2, i32 128, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%4 = icmp sle i64 %3, 0
br i1 %4, label %5, label %8
5: ; preds = %0
%6 = load i32, i32* @EXIT_FAILURE
%7 = call i32 (i32, i8*, ...) @errx(i32 %6, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0))
br label %8
8: ; preds = %5, %0
%9 = getelementptr inbounds [128 x i8], [128 x i8]* %1, i64 0, i64 0
%10 = call i64 @strcmp(i8* %9, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0))
%11 = icmp ne i64 %10, 0
br i1 %11, label %12, label %16
12: ; preds = %8
%13 = load i32, i32* @EXIT_FAILURE
%14 = getelementptr inbounds [128 x i8], [128 x i8]* %1, i64 0, i64 0
%15 = call i32 (i32, i8*, ...) @errx(i32 %13, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0), i8* %14)
br label %16
16: ; preds = %12, %8
ret void
}

LLVM IR (-O2):
@.str = [8 x i8] c"%s, %s!\00"
@.str.1 = [6 x i8] c"Hello\00"
@.str.2 = [6 x i8] c"tests\00"
@EXIT_FAILURE = global i32 0
@.str.3 = [36 x i8] c"snprintf with two formatters failed\00"
@.str.4 = [14 x i8] c"Hello, tests!\00"
@.str.5 = [23 x i8] c"Bad formatting: got %s\00"
define void @snprintf__two_formatters() {
%1 = alloca [128 x i8]
%2 = getelementptr inbounds [128 x i8], [128 x i8]* %1, i64 0, i64 0
%3 = call i64 @snprintf(i8* %2, i32 128, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%4 = icmp slt i64 %3, 1
br i1 %4, label %5, label %8
5: ; preds = %0
%6 = load i32, i32* @EXIT_FAILURE
%7 = call i32 (i32, i8*, ...) @errx(i32 %6, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0))
br label %8
8: ; preds = %5, %0
%9 = call i64 @strcmp(i8* %2, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0))
%10 = icmp eq i64 %9, 0
br i1 %10, label %14, label %11
11: ; preds = %8
%12 = load i32, i32* @EXIT_FAILURE
%13 = call i32 (i32, i8*, ...) @errx(i32 %12, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0), i8* %2)
br label %14
14: ; preds = %11, %8
ret void
}