#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*/ buf;

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int, char *);
int /*<<< orphan*/ stdout;
int tfp_snprintf(char *, int, char *, int);
int main(void) {
  char buf[64];
  int ret = tfp_snprintf(buf, sizeof(buf), "foobar: %d\n", 2);
  fprintf(stdout, "ret: %d, string: %s\n", ret, buf);
  ret = tfp_snprintf(buf, sizeof(buf), "foobar: %d|\n", 2);
  fprintf(stdout, "ret: %d, string: %s\n", ret, buf);
  ret = tfp_snprintf(buf, 4, "foobar: %d|\n", 2);
  fprintf(stdout, "ret: %d, string: %s\n", ret, buf);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x50(%rbp),%rdi
mov    $0x40,%esi
lea    0xec1(%rip),%rdx
mov    $0x2,%ecx
call   1040 <tfp_snprintf@plt>
mov    %eax,-0x54(%rbp)
mov    0x2e8d(%rip),%rax
mov    (%rax),%edi
mov    -0x54(%rbp),%edx
lea    -0x50(%rbp),%rcx
lea    0xea9(%rip),%rsi
call   1030 <fprintf@plt>
lea    -0x50(%rbp),%rdi
mov    $0x40,%esi
lea    0xea9(%rip),%rdx
mov    $0x2,%ecx
call   1040 <tfp_snprintf@plt>
mov    %eax,-0x54(%rbp)
mov    0x2e54(%rip),%rax
mov    (%rax),%edi
mov    -0x54(%rbp),%edx
lea    -0x50(%rbp),%rcx
lea    0xe70(%rip),%rsi
call   1030 <fprintf@plt>
lea    -0x50(%rbp),%rdi
mov    $0x4,%esi
lea    0xe70(%rip),%rdx
mov    $0x2,%ecx
call   1040 <tfp_snprintf@plt>
mov    %eax,-0x54(%rbp)
mov    0x2e1b(%rip),%rax
mov    (%rax),%edi
mov    -0x54(%rbp),%edx
lea    -0x50(%rbp),%rcx
lea    0xe37(%rip),%rsi
call   1030 <fprintf@plt>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x48,%rsp
lea    0xece(%rip),%rdx
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x40,%esi
mov    $0x2,%ecx
call   1040 <tfp_snprintf@plt>
mov    0x2e92(%rip),%r12
mov    (%r12),%edi
lea    0xeb3(%rip),%r14
mov    %r14,%rsi
mov    %eax,%edx
mov    %rbx,%rcx
call   1030 <fprintf@plt>
lea    0xeb4(%rip),%r15
mov    %rbx,%rdi
mov    $0x40,%esi
mov    %r15,%rdx
mov    $0x2,%ecx
call   1040 <tfp_snprintf@plt>
mov    (%r12),%edi
mov    %r14,%rsi
mov    %eax,%edx
mov    %rbx,%rcx
call   1030 <fprintf@plt>
mov    %rbx,%rdi
mov    $0x4,%esi
mov    %r15,%rdx
mov    $0x2,%ecx
call   1040 <tfp_snprintf@plt>
mov    (%r12),%edi
mov    %r14,%rsi
mov    %eax,%edx
mov    %rbx,%rcx
call   1030 <fprintf@plt>
xor    %eax,%eax
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [12 x i8] c"foobar: %d\0A\00"
@stdout = global i32 0
@.str.1 = [21 x i8] c"ret: %d, string: %s\0A\00"
@.str.2 = [13 x i8] c"foobar: %d|\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [64 x i8]
%3 = alloca i32
store i32 0, i32* %1
%4 = getelementptr inbounds [64 x i8], [64 x i8]* %2, i64 0, i64 0
%5 = call i32 @tfp_snprintf(i8* %4, i32 64, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 2)
store i32 %5, i32* %3
%6 = load i32, i32* @stdout
%7 = load i32, i32* %3
%8 = getelementptr inbounds [64 x i8], [64 x i8]* %2, i64 0, i64 0
%9 = call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i32 %7, i8* %8)
%10 = getelementptr inbounds [64 x i8], [64 x i8]* %2, i64 0, i64 0
%11 = call i32 @tfp_snprintf(i8* %10, i32 64, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i32 2)
store i32 %11, i32* %3
%12 = load i32, i32* @stdout
%13 = load i32, i32* %3
%14 = getelementptr inbounds [64 x i8], [64 x i8]* %2, i64 0, i64 0
%15 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i32 %13, i8* %14)
%16 = getelementptr inbounds [64 x i8], [64 x i8]* %2, i64 0, i64 0
%17 = call i32 @tfp_snprintf(i8* %16, i32 4, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i32 2)
store i32 %17, i32* %3
%18 = load i32, i32* @stdout
%19 = load i32, i32* %3
%20 = getelementptr inbounds [64 x i8], [64 x i8]* %2, i64 0, i64 0
%21 = call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i32 %19, i8* %20)
ret i32 0
}

LLVM IR (-O2):
@.str = [12 x i8] c"foobar: %d\0A\00"
@stdout = global i32 0
@.str.1 = [21 x i8] c"ret: %d, string: %s\0A\00"
@.str.2 = [13 x i8] c"foobar: %d|\0A\00"
define i32 @main() {
%1 = alloca [64 x i8]
%2 = getelementptr inbounds [64 x i8], [64 x i8]* %1, i64 0, i64 0
%3 = call i32 @tfp_snprintf(i8* %2, i32 64, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 2)
%4 = load i32, i32* @stdout
%5 = call i32 @fprintf(i32 %4, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i32 %3, i8* %2)
%6 = call i32 @tfp_snprintf(i8* %2, i32 64, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i32 2)
%7 = load i32, i32* @stdout
%8 = call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i32 %6, i8* %2)
%9 = call i32 @tfp_snprintf(i8* %2, i32 4, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i32 2)
%10 = load i32, i32* @stdout
%11 = call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i32 %9, i8* %2)
ret i32 0
}