#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*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *, float *);
int snprintf(char *, int, char *, int, float);
scalar_t__ strlen(char *);
int main(void) {
  int x;
  float y;
  printf("Enter an integer and a float:\n");
  scanf("%d %f", &x, &y);
  int length = snprintf(NULL, 0, "integer: %d\tfloat: %.2f", x, y);
  int size = length + 1;
  printf("Creating a buffer of size: %d\n\n", size);
  char string[size];
  length = snprintf(string, size, "integer: %d\tfloat: %.2f", x, y);
  printf("Return value: %d\n", length);
  printf("String length: %d\n", (int)strlen(string));
  printf("Formatted string:\n%s\n", string);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeaa(%rip),%rdi
xor    %eax,%eax
mov    %eax,-0x38(%rbp)
mov    %al,-0x31(%rbp)
call   1040 <printf@plt>
lea    0xeb5(%rip),%rdi
lea    -0x8(%rbp),%rsi
lea    -0xc(%rbp),%rdx
call   1060 <scanf@plt>
mov    -0x38(%rbp),%esi
mov    -0x8(%rbp),%ecx
movss  -0xc(%rbp),%xmm0
lea    0xe9c(%rip),%rdx
mov    %esi,%edi
call   1050 <snprintf@plt>
mov    %eax,%ecx
mov    -0x31(%rbp),%al
mov    %ecx,-0x10(%rbp)
mov    -0x10(%rbp),%ecx
add    $0x1,%ecx
mov    %ecx,-0x14(%rbp)
mov    -0x14(%rbp),%esi
lea    0xe92(%rip),%rdi
call   1040 <printf@plt>
mov    -0x14(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x30(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x28(%rbp)
mov    -0x14(%rbp),%esi
mov    -0x8(%rbp),%ecx
movss  -0xc(%rbp),%xmm0
lea    0xe3d(%rip),%rdx
call   1050 <snprintf@plt>
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%esi
lea    0xe63(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x30(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%esi
lea    0xe5c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x30(%rbp),%rsi
lea    0xe5d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
lea    0xf13(%rip),%rdi
call   1030 <puts@plt>
lea    0xe8e(%rip),%rdi
lea    -0x28(%rbp),%rsi
lea    -0x24(%rbp),%rdx
call   1070 <scanf@plt>
mov    -0x28(%rbp),%ecx
movss  -0x24(%rbp),%xmm0
lea    0xe78(%rip),%r14
xor    %edi,%edi
xor    %esi,%esi
mov    %r14,%rdx
call   1060 <snprintf@plt>
lea    0x1(%rax),%r15d
lea    0xe79(%rip),%rdi
mov    %r15d,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rsp,%r12
lea    0xf(%r15),%rax
and    $0xfffffffffffffff0,%rax
mov    %rsp,%rbx
sub    %rax,%rbx
mov    %rbx,%rsp
mov    -0x28(%rbp),%ecx
movss  -0x24(%rbp),%xmm0
mov    %rbx,%rdi
mov    %r15d,%esi
mov    %r14,%rdx
call   1060 <snprintf@plt>
lea    0xe5e(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
lea    0xe58(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe5b(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r12,%rsp
xor    %eax,%eax
lea    -0x20(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [31 x i8] c"Enter an integer and a float:\0A\00"
@.str.1 = [6 x i8] c"%d %f\00"
@.str.2 = [24 x i8] c"integer: %d\09float: %.2f\00"
@.str.3 = [32 x i8] c"Creating a buffer of size: %d\0A\0A\00"
@.str.4 = [18 x i8] c"Return value: %d\0A\00"
@.str.5 = [19 x i8] c"String length: %d\0A\00"
@.str.6 = [22 x i8] c"Formatted string:\0A%s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca float
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i64
store i32 0, i32* %1
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
%9 = call i32 @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32* %2, float* %3)
%10 = load i32, i32* %2
%11 = load float, float* %3
%12 = call i32 @snprintf(i8* null, i32 0, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i32 %10, float %11)
store i32 %12, i32* %4
%13 = load i32, i32* %4
%14 = add nsw i32 %13, 1
store i32 %14, i32* %5
%15 = load i32, i32* %5
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0), i32 %15)
%17 = load i32, i32* %5
%18 = zext i32 %17 to i64
%19 = call i8* @llvm.stacksave()
store i8* %19, i8** %6
%20 = alloca i8, i64 %18
store i64 %18, i64* %7
%21 = load i32, i32* %5
%22 = load i32, i32* %2
%23 = load float, float* %3
%24 = call i32 @snprintf(i8* %20, i32 %21, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i32 %22, float %23)
store i32 %24, i32* %4
%25 = load i32, i32* %4
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), i32 %25)
%27 = call i64 @strlen(i8* %20)
%28 = trunc i64 %27 to i32
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0), i32 %28)
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.6, i64 0, i64 0), i8* %20)
store i32 0, i32* %1
%31 = load i8*, i8** %6
%32 = load i32, i32* %1
ret i32 %32
}

LLVM IR (-O2):
@.str.1 = [6 x i8] c"%d %f\00"
@.str.2 = [24 x i8] c"integer: %d\09float: %.2f\00"
@.str.3 = [32 x i8] c"Creating a buffer of size: %d\0A\0A\00"
@.str.4 = [18 x i8] c"Return value: %d\0A\00"
@.str.5 = [19 x i8] c"String length: %d\0A\00"
@.str.6 = [22 x i8] c"Formatted string:\0A%s\0A\00"
@str = [30 x i8] c"Enter an integer and a float:\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca float
%3 = bitcast i32* %1 to i8*
%4 = bitcast float* %2 to i8*
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str, i64 0, i64 0))
%6 = call i32 @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32* %1, float* %2)
%7 = load i32, i32* %1
%8 = load float, float* %2
%9 = call i32 @snprintf(i8* null, i32 0, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i32 %7, float %8)
%10 = add nsw i32 %9, 1
%11 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0), i32 %10)
%12 = zext i32 %10 to i64
%13 = call i8* @llvm.stacksave()
%14 = alloca i8, i64 %12
%15 = load i32, i32* %1
%16 = load float, float* %2
%17 = call i32 @snprintf(i8* %14, i32 %10, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i32 %15, float %16)
%18 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), i32 %17)
%19 = call i64 @strlen(i8* %14)
%20 = trunc i64 %19 to i32
%21 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0), i32 %20)
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.6, i64 0, i64 0), i8* %14)
ret i32 0
}