#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 */
struct stat {
  int dummy;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char *, int, int);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ fwrite(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ stat(char *, struct stat *);
int main(int argc, char **argv) {
  FILE *pFile;
  char buffer[] = {'a', 'b'};
  pFile = fopen("testfile.bin", "wb");
  fwrite(buffer, sizeof(char), 2, pFile);
  int c = fgetc(pFile);
  fputs("Test", pFile);
  fprintf(pFile, "%s %d %c\n", "TESTSTR", 47, c);
  fclose(pFile);
  struct stat statRes;
  stat("testfile.bin", &statRes);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0xe73(%rip),%ax
mov    %ax,-0x1a(%rbp)
lea    0xe6a(%rip),%rdi
lea    0xe70(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
lea    -0x1a(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
mov    $0x2,%edx
call   1090 <fwrite@plt>
mov    -0x18(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%rsi
lea    0xe3c(%rip),%rdi
call   1040 <fputs@plt>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%r8d
lea    0xe2d(%rip),%rsi
lea    0xe30(%rip),%rdx
mov    $0x2f,%ecx
call   1060 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
lea    0xdf7(%rip),%rdi
lea    -0x28(%rbp),%rsi
call   1070 <stat@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
movw   $0x6261,0x6(%rsp)
lea    0xe8a(%rip),%r14
lea    0xe90(%rip),%rsi
mov    %r14,%rdi
call   1070 <fopen@plt>
mov    %rax,%rbx
lea    0x6(%rsp),%rdi
mov    $0x1,%esi
mov    $0x2,%edx
mov    %rax,%rcx
call   1080 <fwrite@plt>
mov    %rbx,%rdi
call   1040 <fgetc@plt>
mov    %eax,%ebp
lea    0xe60(%rip),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1080 <fwrite@plt>
lea    0xe4c(%rip),%rsi
lea    0xe4f(%rip),%rdx
mov    %rbx,%rdi
mov    $0x2f,%ecx
mov    %ebp,%r8d
call   1050 <fprintf@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
lea    0x8(%rsp),%rsi
mov    %r14,%rdi
call   1060 <stat@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@__const.main.buffer = [2 x i8] c"ab"
@.str = [13 x i8] c"testfile.bin\00"
@.str.1 = [3 x i8] c"wb\00"
@.str.2 = [5 x i8] c"Test\00"
@.str.3 = [10 x i8] c"%s %d %c\0A\00"
@.str.4 = [8 x i8] c"TESTSTR\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca [2 x i8]
%8 = alloca i32
%9 = alloca %struct.stat
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = bitcast [2 x i8]* %7 to i8*
%11 = call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %11, i32** %6
%12 = getelementptr inbounds [2 x i8], [2 x i8]* %7, i64 0, i64 0
%13 = load i32*, i32** %6
%14 = call i32 @fwrite(i8* %12, i32 1, i32 2, i32* %13)
%15 = load i32*, i32** %6
%16 = call i32 @fgetc(i32* %15)
store i32 %16, i32* %8
%17 = load i32*, i32** %6
%18 = call i32 @fputs(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32* %17)
%19 = load i32*, i32** %6
%20 = load i32, i32* %8
%21 = call i32 @fprintf(i32* %19, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i32 47, i32 %20)
%22 = load i32*, i32** %6
%23 = call i32 @fclose(i32* %22)
%24 = call i32 @stat(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), %struct.stat* %9)
ret i32 0
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [13 x i8] c"testfile.bin\00"
@.str.1 = [3 x i8] c"wb\00"
@.str.2 = [5 x i8] c"Test\00"
@.str.3 = [10 x i8] c"%s %d %c\0A\00"
@.str.4 = [8 x i8] c"TESTSTR\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i16
%4 = alloca %struct.stat
%5 = bitcast i16* %3 to i8*
store i16 25185, i16* %3
%6 = tail call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%7 = call i32 @fwrite(i8* %5, i32 1, i32 2, i32* %6)
%8 = tail call i32 @fgetc(i32* %6)
%9 = tail call i64 bitcast (i32 (i8*, i32, i32, i32*)* @fwrite to i64 (i8*, i64, i64, i32*)*)(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i64 4, i64 1, i32* %6)
%10 = tail call i32 @fprintf(i32* %6, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i32 47, i32 %8)
%11 = tail call i32 @fclose(i32* %6)
%12 = bitcast %struct.stat* %4 to i8*
%13 = call i32 @stat(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), %struct.stat* %4)
ret i32 0
}