#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 printf(char *, ...);
int snprintf(char *, int, char *);
int sprintf(char *, char *, char *);
int main() {
  char buf[16] = {0};
  int n = printf("%d %x %s %c\n", 42, 99, "hello", 'x');
  printf("%d\n", n);
  n = sprintf(buf, "%s", "foobar");
  printf("%s %d\n", buf, n);
  n = snprintf(buf, 3, "hogefuga");
  printf("%s %d\n", buf, n);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1050 <memset@plt>
lea    0xe9a(%rip),%rdi
mov    $0x2a,%esi
mov    $0x63,%edx
lea    0xe96(%rip),%rcx
mov    $0x78,%r8d
mov    $0x0,%al
call   1030 <printf@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%esi
lea    0xe8f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x20(%rbp),%rdi
lea    0xe70(%rip),%rsi
lea    0xe6c(%rip),%rdx
call   1060 <sprintf@plt>
mov    %eax,-0x24(%rbp)
lea    -0x20(%rbp),%rsi
mov    -0x24(%rbp),%edx
lea    0xe5d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x20(%rbp),%rdi
mov    $0x3,%esi
lea    0xe4d(%rip),%rdx
call   1040 <snprintf@plt>
mov    %eax,-0x24(%rbp)
lea    -0x20(%rbp),%rsi
mov    -0x24(%rbp),%edx
lea    0xe30(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x18,%rsp
lea    0xed2(%rip),%rdi
lea    0xed8(%rip),%rcx
mov    $0x2a,%esi
mov    $0x63,%edx
mov    $0x78,%r8d
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xeca(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1030 <printf@plt>
movq   $0x0,0x7(%rsp)
movb   $0x0,0xf(%rsp)
movl   $0x626f6f66,(%rsp)
movl   $0x726162,0x3(%rsp)
lea    0xe9a(%rip),%r14
mov    %rsp,%rbx
mov    %r14,%rdi
mov    %rbx,%rsi
mov    $0x6,%edx
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xe85(%rip),%rdx
mov    %rbx,%rdi
mov    $0x3,%esi
call   1040 <snprintf@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [13 x i8] c"%d %x %s %c\0A\00"
@.str.1 = [6 x i8] c"hello\00"
@.str.2 = [4 x i8] c"%d\0A\00"
@.str.3 = [3 x i8] c"%s\00"
@.str.4 = [7 x i8] c"foobar\00"
@.str.5 = [7 x i8] c"%s %d\0A\00"
@.str.6 = [9 x i8] c"hogefuga\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [16 x i8]
%3 = alloca i32
store i32 0, i32* %1
%4 = bitcast [16 x i8]* %2 to i8*
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 42, i32 99, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 120)
store i32 %5, i32* %3
%6 = load i32, i32* %3
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %6)
%8 = getelementptr inbounds [16 x i8], [16 x i8]* %2, i64 0, i64 0
%9 = call i32 @sprintf(i8* %8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
store i32 %9, i32* %3
%10 = getelementptr inbounds [16 x i8], [16 x i8]* %2, i64 0, i64 0
%11 = load i32, i32* %3
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i8* %10, i32 %11)
%13 = getelementptr inbounds [16 x i8], [16 x i8]* %2, i64 0, i64 0
%14 = call i32 @snprintf(i8* %13, i32 3, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0))
store i32 %14, i32* %3
%15 = getelementptr inbounds [16 x i8], [16 x i8]* %2, i64 0, i64 0
%16 = load i32, i32* %3
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i8* %15, i32 %16)
ret i32 0
}

LLVM IR (-O2):
@.str = [13 x i8] c"%d %x %s %c\0A\00"
@.str.1 = [6 x i8] c"hello\00"
@.str.2 = [4 x i8] c"%d\0A\00"
@.str.4 = [7 x i8] c"foobar\00"
@.str.5 = [7 x i8] c"%s %d\0A\00"
@.str.6 = [9 x i8] c"hogefuga\00"
define i32 @main() {
%1 = alloca [16 x i8]
%2 = getelementptr inbounds [16 x i8], [16 x i8]* %1, i64 0, i64 0
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 42, i32 99, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 120)
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %3)
%5 = getelementptr inbounds [16 x i8], [16 x i8]* %1, i64 0, i64 7
%6 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i8* %2, i32 6)
%7 = call i32 @snprintf(i8* %2, i32 3, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0))
%8 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i8* %2, i32 %7)
ret i32 0
}