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

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/ *);
int main() {
  FILE *fp;
  int i = 617;
  char *s = "that is a good new";
  fp = fopen("text.dat", "w");
  fputs("total", fp);
  fputs(":", fp);
  fprintf(fp, "%d\n", i);
  fprintf(fp, "%s", s);
  fclose(fp);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x269,-0x14(%rbp)
lea    0xea3(%rip),%rax
mov    %rax,-0x20(%rbp)
lea    0xeab(%rip),%rdi
lea    0xea2(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xe99(%rip),%rdi
call   1040 <fputs@plt>
mov    -0x10(%rbp),%rsi
lea    0xe8f(%rip),%rdi
call   1040 <fputs@plt>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%edx
lea    0xe7e(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rdx
lea    0xe6c(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
lea    0xebb(%rip),%rdi
lea    0xeb2(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%rbx
lea    0xeae(%rip),%rdi
mov    $0x5,%esi
mov    $0x1,%edx
mov    %rax,%rcx
call   1070 <fwrite@plt>
mov    $0x3a,%edi
mov    %rbx,%rsi
call   1040 <fputc@plt>
lea    0xe8e(%rip),%rsi
mov    %rbx,%rdi
mov    $0x269,%edx
xor    %eax,%eax
call   1050 <fprintf@plt>
lea    0xe56(%rip),%rdi
mov    $0x12,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1070 <fwrite@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [19 x i8] c"that is a good new\00"
@.str.1 = [9 x i8] c"text.dat\00"
@.str.2 = [2 x i8] c"w\00"
@.str.3 = [6 x i8] c"total\00"
@.str.4 = [2 x i8] c":\00"
@.str.5 = [4 x i8] c"%d\0A\00"
@.str.6 = [3 x i8] c"%s\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32
%4 = alloca i8*
store i32 0, i32* %1
store i32 617, i32* %3
store i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8** %4
%5 = call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %5, i32** %2
%6 = load i32*, i32** %2
%7 = call i32 @fputs(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32* %6)
%8 = load i32*, i32** %2
%9 = call i32 @fputs(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0), i32* %8)
%10 = load i32*, i32** %2
%11 = load i32, i32* %3
%12 = call i32 (i32*, i8*, ...) @fprintf(i32* %10, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32 %11)
%13 = load i32*, i32** %2
%14 = load i8*, i8** %4
%15 = call i32 (i32*, i8*, ...) @fprintf(i32* %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i8* %14)
%16 = load i32*, i32** %2
%17 = call i32 @fclose(i32* %16)
ret i32 0
}

LLVM IR (-O2):
@.str = [19 x i8] c"that is a good new\00"
@.str.1 = [9 x i8] c"text.dat\00"
@.str.2 = [2 x i8] c"w\00"
@.str.3 = [6 x i8] c"total\00"
@.str.5 = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = tail call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%2 = tail call i64 @fwrite(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i64 5, i64 1, i32* %1)
%3 = tail call i32 @fputc(i32 58, i32* %1)
%4 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %1, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32 617)
%5 = tail call i64 @fwrite(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i64 18, i64 1, i32* %1)
%6 = tail call i32 @fclose(i32* %1)
ret i32 0
}