#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 *, char *);
int /*<<< orphan*/ sprintf(char *, char *, ...);
int main(void) {
  int i = 123;
  double d = 99.99;
  char *name = "furong";
  char buf[1024] = {};
  sprintf(buf, "name=%s|i=%d|d=%f|", name, i, d);
  sprintf(buf, "%d", 123);
  printf("buf=%s\n", buf);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
movl   $0x7b,-0x4(%rbp)
movsd  0xeb6(%rip),%xmm0
movsd  %xmm0,-0x10(%rbp)
lea    0xeb2(%rip),%rax
mov    %rax,-0x18(%rbp)
lea    -0x420(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1040 <memset@plt>
lea    -0x420(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    -0x4(%rbp),%ecx
movsd  -0x10(%rbp),%xmm0
lea    0xe88(%rip),%rsi
mov    $0x1,%al
call   1050 <sprintf@plt>
lea    -0x420(%rbp),%rdi
lea    0xe86(%rip),%rsi
mov    $0x7b,%edx
mov    $0x0,%al
call   1050 <sprintf@plt>
lea    -0x420(%rbp),%rsi
lea    0xe6f(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x400,%rsp
mov    %rsp,%rbx
mov    $0x400,%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1040 <memset@plt>
lea    0xebe(%rip),%rsi
lea    0xeb0(%rip),%rdx
movsd  0xea0(%rip),%xmm0
mov    %rbx,%rdi
mov    $0x7b,%ecx
mov    $0x1,%al
call   1050 <sprintf@plt>
lea    0xeac(%rip),%rsi
mov    %rbx,%rdi
mov    $0x7b,%edx
xor    %eax,%eax
call   1050 <sprintf@plt>
lea    0xe99(%rip),%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x400,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [7 x i8] c"furong\00"
@.str.1 = [19 x i8] c"name=%s|i=%d|d=%f|\00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [8 x i8] c"buf=%s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca double
%3 = alloca i8*
%4 = alloca [1024 x i8]
store i32 123, i32* %1
store double 0x4058FF5C28F5C28F, double* %2
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8** %3
%5 = bitcast [1024 x i8]* %4 to i8*
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%7 = load i8*, i8** %3
%8 = load i32, i32* %1
%9 = load double, double* %2
%10 = call i32 (i8*, i8*, ...) @sprintf(i8* %6, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* %7, i32 %8, double %9)
%11 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%12 = call i32 (i8*, i8*, ...) @sprintf(i8* %11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 123)
%13 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%14 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i8* %13)
ret i32 0
}

LLVM IR (-O2):
@.str = [7 x i8] c"furong\00"
@.str.1 = [19 x i8] c"name=%s|i=%d|d=%f|\00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [8 x i8] c"buf=%s\0A\00"
define i32 @main() {
%1 = alloca [1024 x i8]
%2 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 0
%3 = call i32 (i8*, i8*, ...) @sprintf(i8* %2, i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 123, double 0x4058FF5C28F5C28F)
%4 = call i32 (i8*, i8*, ...) @sprintf(i8* %2, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 123)
%5 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i8* %2)
ret i32 0
}