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

/* Variables and functions */
int /*<<< orphan*/ _IOLBF;
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ memset(char *, char, int);
int /*<<< orphan*/ setvbuf(int /*<<< orphan*/, char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ stdout;
int main() {
  char buff[1024];
  memset(buff, '\0', sizeof(buff));
  fprintf(stdout, "start with no buff\n");
  sleep(2);
  setvbuf(stdout, buff, _IOLBF, 1024);
  fprintf(stdout, "Hellow my name is jia");
  fprintf(stdout, " Li please let me know whtat\n");
  fflush(stdout);
  fprintf(stdout, "another thing is ");
  fprintf(stdout, "going to appear after 3 sec");
  sleep(3);
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x410,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x410(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1030 <memset@plt>
mov    0x2e5c(%rip),%rax
mov    (%rax),%edi
lea    0xe7b(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x2,%edi
call   1070 <sleep@plt>
mov    0x2e3d(%rip),%rax
mov    (%rax),%edi
lea    -0x410(%rbp),%rsi
mov    0x2e35(%rip),%rax
mov    (%rax),%edx
mov    $0x400,%ecx
call   1060 <setvbuf@plt>
mov    0x2e1a(%rip),%rax
mov    (%rax),%edi
lea    0xe4d(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2e05(%rip),%rax
mov    (%rax),%edi
lea    0xe4e(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2df0(%rip),%rax
mov    (%rax),%edi
call   1050 <fflush@plt>
mov    0x2de2(%rip),%rax
mov    (%rax),%edi
lea    0xe49(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2dcd(%rip),%rax
mov    (%rax),%edi
lea    0xe46(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x3,%edi
call   1070 <sleep@plt>
xor    %eax,%eax
add    $0x410,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x408,%rsp
mov    %rsp,%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1030 <memset@plt>
mov    0x2e65(%rip),%rbx
mov    (%rbx),%edi
lea    0xe84(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x2,%edi
call   1070 <sleep@plt>
mov    (%rbx),%edi
mov    0x2e4c(%rip),%rax
mov    (%rax),%edx
mov    %r14,%rsi
mov    $0x400,%ecx
call   1060 <setvbuf@plt>
mov    (%rbx),%edi
lea    0xe68(%rip),%rsi
call   1040 <fprintf@plt>
mov    (%rbx),%edi
lea    0xe70(%rip),%rsi
call   1040 <fprintf@plt>
mov    (%rbx),%edi
call   1050 <fflush@plt>
mov    (%rbx),%edi
lea    0xe79(%rip),%rsi
call   1040 <fprintf@plt>
mov    (%rbx),%edi
lea    0xe7d(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x3,%edi
call   1070 <sleep@plt>
xor    %eax,%eax
add    $0x408,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@stdout = global i32 0
@.str = [20 x i8] c"start with no buff\0A\00"
@_IOLBF = global i32 0
@.str.1 = [22 x i8] c"Hellow my name is jia\00"
@.str.2 = [30 x i8] c" Li please let me know whtat\0A\00"
@.str.3 = [18 x i8] c"another thing is \00"
@.str.4 = [28 x i8] c"going to appear after 3 sec\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [1024 x i8]
store i32 0, i32* %1
%3 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%4 = call i32 @memset(i8* %3, i8 signext 0, i32 1024)
%5 = load i32, i32* @stdout
%6 = call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%7 = call i32 @sleep(i32 2)
%8 = load i32, i32* @stdout
%9 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%10 = load i32, i32* @_IOLBF
%11 = call i32 @setvbuf(i32 %8, i8* %9, i32 %10, i32 1024)
%12 = load i32, i32* @stdout
%13 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
%14 = load i32, i32* @stdout
%15 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0))
%16 = load i32, i32* @stdout
%17 = call i32 @fflush(i32 %16)
%18 = load i32, i32* @stdout
%19 = call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0))
%20 = load i32, i32* @stdout
%21 = call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0))
%22 = call i32 @sleep(i32 3)
ret i32 0
}

LLVM IR (-O2):
@stdout = global i32 0
@.str = [20 x i8] c"start with no buff\0A\00"
@_IOLBF = global i32 0
@.str.1 = [22 x i8] c"Hellow my name is jia\00"
@.str.2 = [30 x i8] c" Li please let me know whtat\0A\00"
@.str.3 = [18 x i8] c"another thing is \00"
@.str.4 = [28 x i8] c"going to appear after 3 sec\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 @memset(i8* %2, i8 signext 0, i32 1024)
%4 = load i32, i32* @stdout
%5 = call i32 @fprintf(i32 %4, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%6 = call i32 @sleep(i32 2)
%7 = load i32, i32* @stdout
%8 = load i32, i32* @_IOLBF
%9 = call i32 @setvbuf(i32 %7, i8* %2, i32 %8, i32 1024)
%10 = load i32, i32* @stdout
%11 = call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
%12 = load i32, i32* @stdout
%13 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0))
%14 = load i32, i32* @stdout
%15 = call i32 @fflush(i32 %14)
%16 = load i32, i32* @stdout
%17 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0))
%18 = load i32, i32* @stdout
%19 = call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0))
%20 = call i32 @sleep(i32 3)
ret i32 0
}