#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 fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char *, int);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ fwrite(char *, int, int, int /*<<< orphan*/ *);
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\n", "TESTSTR", 47);
  fclose(pFile);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0xe83(%rip),%ax
mov    %ax,-0x1a(%rbp)
lea    0xe7a(%rip),%rdi
lea    0xe80(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
lea    -0x1a(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
mov    $0x2,%edx
call   1080 <fwrite@plt>
mov    -0x18(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%rsi
lea    0xe4c(%rip),%rdi
call   1040 <fputs@plt>
mov    -0x18(%rbp),%rdi
lea    0xe41(%rip),%rsi
lea    0xe41(%rip),%rdx
mov    $0x2f,%ecx
call   1060 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
movw   $0x6261,0xe(%rsp)
lea    0xe9d(%rip),%rdi
lea    0xea3(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%rbx
lea    0xe(%rsp),%rdi
mov    $0x1,%esi
mov    $0x2,%edx
mov    %rax,%rcx
call   1070 <fwrite@plt>
mov    %rbx,%rdi
call   1040 <fgetc@plt>
lea    0xe78(%rip),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1070 <fwrite@plt>
lea    0xe64(%rip),%rsi
lea    0xe64(%rip),%rdx
mov    %rbx,%rdi
mov    $0x2f,%ecx
call   1050 <fprintf@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@__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 = [7 x i8] c"%s %d\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
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = bitcast [2 x i8]* %7 to i8*
%10 = 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* %10, i32** %6
%11 = getelementptr inbounds [2 x i8], [2 x i8]* %7, i64 0, i64 0
%12 = load i32*, i32** %6
%13 = call i32 @fwrite(i8* %11, i32 1, i32 2, i32* %12)
%14 = load i32*, i32** %6
%15 = call i32 @fgetc(i32* %14)
store i32 %15, i32* %8
%16 = load i32*, i32** %6
%17 = call i32 @fputs(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32* %16)
%18 = load i32*, i32** %6
%19 = call i32 @fprintf(i32* %18, i8* getelementptr inbounds ([7 x i8], [7 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)
%20 = load i32*, i32** %6
%21 = call i32 @fclose(i32* %20)
ret i32 0
}

LLVM IR (-O2):
@.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 = [7 x i8] c"%s %d\0A\00"
@.str.4 = [8 x i8] c"TESTSTR\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i16
%4 = bitcast i16* %3 to i8*
store i16 25185, i16* %3
%5 = 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))
%6 = call i32 @fwrite(i8* %4, i32 1, i32 2, i32* %5)
%7 = tail call i32 @fgetc(i32* %5)
%8 = 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* %5)
%9 = tail call i32 @fprintf(i32* %5, i8* getelementptr inbounds ([7 x i8], [7 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)
%10 = tail call i32 @fclose(i32* %5)
ret i32 0
}