#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*/ fputs(char const *, int /*<<< orphan*/);
int /*<<< orphan*/ sprintf(char *, char *, char volatile, int volatile,
                           float volatile, char volatile *);
int /*<<< orphan*/ stderr;
int main() {
  volatile char c = '0';
  volatile int x = 12;
  volatile float f = 1.239;
  volatile char s[] = "34";
  volatile char buf[2];
  fputs("before sprintf\n", stderr);
  sprintf((char *)buf, "%c %d %.3f %s\n", c, x, f, s);
  fputs("after sprintf", stderr);
  fputs((const char *)buf, stderr);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movb   $0x30,-0x5(%rbp)
movl   $0xc,-0xc(%rbp)
movss  0xebe(%rip),%xmm0
movss  %xmm0,-0x10(%rbp)
lea    -0x13(%rbp),%rax
mov    0xeb5(%rip),%cl
mov    %cl,0x2(%rax)
mov    0xea9(%rip),%cx
mov    %cx,(%rax)
mov    0x2e7b(%rip),%rax
mov    (%rax),%esi
lea    0xe99(%rip),%rdi
call   1030 <fputs@plt>
lea    -0x15(%rbp),%rdi
mov    -0x5(%rbp),%al
mov    -0xc(%rbp),%ecx
movss  -0x10(%rbp),%xmm0
lea    -0x13(%rbp),%r8
lea    0xe8a(%rip),%rsi
movsbl %al,%edx
call   1040 <sprintf@plt>
mov    0x2e44(%rip),%rax
mov    (%rax),%esi
lea    0xe81(%rip),%rdi
call   1030 <fputs@plt>
lea    -0x15(%rbp),%rdi
mov    0x2e2b(%rip),%rax
mov    (%rax),%esi
call   1030 <fputs@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x18,%rsp
movb   $0x30,0x7(%rsp)
movl   $0xc,0x10(%rsp)
movl   $0x3f9e978d,0xc(%rsp)
3f
mov    0xec0(%rip),%al
mov    %al,0xa(%rsp)
movzwl 0xeb3(%rip),%eax
mov    %ax,0x8(%rsp)
mov    0x2e87(%rip),%rbx
mov    (%rbx),%esi
lea    0xea1(%rip),%rdi
call   1030 <fputs@plt>
movsbl 0x7(%rsp),%edx
mov    0x10(%rsp),%ecx
movss  0xc(%rsp),%xmm0
lea    0xe96(%rip),%rsi
lea    0x16(%rsp),%r14
lea    0x8(%rsp),%r8
mov    %r14,%rdi
call   1040 <sprintf@plt>
mov    (%rbx),%esi
lea    0xe8a(%rip),%rdi
call   1030 <fputs@plt>
mov    (%rbx),%esi
mov    %r14,%rdi
call   1030 <fputs@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@__const.main.s = [3 x i8] c"34\00"
@.str = [16 x i8] c"before sprintf\0A\00"
@stderr = global i32 0
@.str.1 = [15 x i8] c"%c %d %.3f %s\0A\00"
@.str.2 = [14 x i8] c"after sprintf\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8
%3 = alloca i32
%4 = alloca float
%5 = alloca [3 x i8]
%6 = alloca [2 x i8]
store i32 0, i32* %1
store volatile i8 48, i8* %2
store volatile i32 12, i32* %3
store volatile float 0x3FF3D2F1A0000000, float* %4
%7 = bitcast [3 x i8]* %5 to i8*
%8 = load i32, i32* @stderr
%9 = call i32 @fputs(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 %8)
%10 = getelementptr inbounds [2 x i8], [2 x i8]* %6, i64 0, i64 0
%11 = load volatile i8, i8* %2
%12 = load volatile i32, i32* %3
%13 = load volatile float, float* %4
%14 = getelementptr inbounds [3 x i8], [3 x i8]* %5, i64 0, i64 0
%15 = call i32 @sprintf(i8* %10, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8 signext %11, i32 %12, float %13, i8* %14)
%16 = load i32, i32* @stderr
%17 = call i32 @fputs(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32 %16)
%18 = getelementptr inbounds [2 x i8], [2 x i8]* %6, i64 0, i64 0
%19 = load i32, i32* @stderr
%20 = call i32 @fputs(i8* %18, i32 %19)
ret i32 0
}

LLVM IR (-O2):
@__const.main.s = [3 x i8] c"34\00"
@.str = [16 x i8] c"before sprintf\0A\00"
@stderr = global i32 0
@.str.1 = [15 x i8] c"%c %d %.3f %s\0A\00"
@.str.2 = [14 x i8] c"after sprintf\00"
define i32 @main() {
%1 = alloca i8
%2 = alloca i32
%3 = alloca float
%4 = alloca [3 x i8]
%5 = alloca [2 x i8]
store volatile i8 48, i8* %1
%6 = bitcast i32* %2 to i8*
store volatile i32 12, i32* %2
%7 = bitcast float* %3 to i8*
store volatile float 0x3FF3D2F1A0000000, float* %3
%8 = getelementptr inbounds [3 x i8], [3 x i8]* %4, i64 0, i64 0
%9 = getelementptr inbounds [2 x i8], [2 x i8]* %5, i64 0, i64 0
%10 = load i32, i32* @stderr
%11 = tail call i32 @fputs(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 %10)
%12 = load volatile i8, i8* %1
%13 = load volatile i32, i32* %2
%14 = load volatile float, float* %3
%15 = call i32 @sprintf(i8* %9, i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8 signext %12, i32 %13, float %14, i8* %8)
%16 = load i32, i32* @stderr
%17 = call i32 @fputs(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32 %16)
%18 = load i32, i32* @stderr
%19 = call i32 @fputs(i8* %9, i32 %18)
ret i32 0
}