#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 fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fwrite(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, char);
int main(int argc, char **argv) {
  char *fname = argv[1];
  FILE *f;
  char mydata_start[10] = "abcDEFghi";
  char mydata_end[10];
  int num;
  f = fopen(fname, "w");
  fwrite(mydata_start, 1, 4, f);
  fclose(f);
  f = fopen(fname, "a");
  fwrite(mydata_start, 1, 4, f);
  fclose(f);
  f = fopen(fname, "r");
  num = fread(mydata_end, 1, 15, f);
  printf("Read %i bytes: \n", num);
  for (int i = 0; i < num; i++) {
    printf("%c\n", mydata_end[i]);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    0xe87(%rip),%rax
mov    %rax,-0x2a(%rbp)
mov    0xe84(%rip),%ax
mov    %ax,-0x22(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe77(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
lea    -0x2a(%rbp),%rdi
mov    -0x20(%rbp),%rcx
mov    $0x1,%esi
mov    $0x4,%edx
call   1070 <fwrite@plt>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x18(%rbp),%rdi
lea    0xe45(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
lea    -0x2a(%rbp),%rdi
mov    -0x20(%rbp),%rcx
mov    $0x1,%esi
mov    $0x4,%edx
call   1070 <fwrite@plt>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x18(%rbp),%rdi
lea    0xe13(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
lea    -0x34(%rbp),%rdi
mov    -0x20(%rbp),%rcx
mov    $0x1,%esi
mov    $0xf,%edx
call   1030 <fread@plt>
mov    %eax,-0x38(%rbp)
mov    -0x38(%rbp),%eax
lea    0xde8(%rip),%rdi
movsbl %al,%esi
call   1050 <printf@plt>
movl   $0x0,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0x38(%rbp),%eax
jge    1266 <main+0x116>
movslq -0x3c(%rbp),%rax
lea    0xdd3(%rip),%rdi
movsbl -0x34(%rbp,%rax,1),%esi
call   1050 <printf@plt>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    1237 <main+0xe7>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    0x8(%rsi),%r14
movabs $0x6867464544636261,%rax
46 67 68
mov    %rax,0x8(%rsp)
movw   $0x69,0x10(%rsp)
lea    0xe90(%rip),%rsi
mov    %r14,%rdi
call   1060 <fopen@plt>
mov    %rax,%rbx
lea    0x8(%rsp),%r15
mov    %r15,%rdi
mov    $0x1,%esi
mov    $0x4,%edx
mov    %rax,%rcx
call   1070 <fwrite@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
lea    0xe5e(%rip),%rsi
mov    %r14,%rdi
call   1060 <fopen@plt>
mov    %rax,%rbx
mov    %r15,%rdi
mov    $0x1,%esi
mov    $0x4,%edx
mov    %rax,%rcx
call   1070 <fwrite@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
lea    0xe31(%rip),%rsi
mov    %r14,%rdi
call   1060 <fopen@plt>
lea    0x16(%rsp),%rdi
mov    $0x1,%esi
mov    $0xf,%edx
mov    %rax,%rcx
call   1030 <fread@plt>
mov    %eax,%ebx
movsbl %bl,%esi
lea    0xe08(%rip),%rdi
call   1050 <printf@plt>
test   %ebx,%ebx
jle    1236 <main+0xe6>
mov    %ebx,%r15d
xor    %ebx,%ebx
lea    0xe04(%rip),%r14
nopl   (%rax)
movsbl 0x16(%rsp,%rbx,1),%esi
mov    %r14,%rdi
call   1050 <printf@plt>
add    $0x1,%rbx
cmp    %rbx,%r15
jne    1220 <main+0xd0>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@__const.main.mydata_start = [10 x i8] c"abcDEFghi\00"
@.str = [2 x i8] c"w\00"
@.str.1 = [2 x i8] c"a\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [17 x i8] c"Read %i bytes: \0A\00"
@.str.4 = [4 x i8] c"%c\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32*
%8 = alloca [10 x i8]
%9 = alloca [10 x i8]
%10 = alloca i32
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 1
%14 = load i8*, i8** %13
store i8* %14, i8** %6
%15 = bitcast [10 x i8]* %8 to i8*
%16 = load i8*, i8** %6
%17 = call i32* @fopen(i8* %16, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %17, i32** %7
%18 = getelementptr inbounds [10 x i8], [10 x i8]* %8, i64 0, i64 0
%19 = load i32*, i32** %7
%20 = call i32 @fwrite(i8* %18, i32 1, i32 4, i32* %19)
%21 = load i32*, i32** %7
%22 = call i32 @fclose(i32* %21)
%23 = load i8*, i8** %6
%24 = call i32* @fopen(i8* %23, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %24, i32** %7
%25 = getelementptr inbounds [10 x i8], [10 x i8]* %8, i64 0, i64 0
%26 = load i32*, i32** %7
%27 = call i32 @fwrite(i8* %25, i32 1, i32 4, i32* %26)
%28 = load i32*, i32** %7
%29 = call i32 @fclose(i32* %28)
%30 = load i8*, i8** %6
%31 = call i32* @fopen(i8* %30, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %31, i32** %7
%32 = getelementptr inbounds [10 x i8], [10 x i8]* %9, i64 0, i64 0
%33 = load i32*, i32** %7
%34 = call i32 @fread(i8* %32, i32 1, i32 15, i32* %33)
store i32 %34, i32* %10
%35 = load i32, i32* %10
%36 = trunc i32 %35 to i8
%37 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), i8 signext %36)
store i32 0, i32* %11
br label %38
38: ; preds = %48, %2
%39 = load i32, i32* %11
%40 = load i32, i32* %10
%41 = icmp slt i32 %39, %40
br i1 %41, label %42, label %51
42: ; preds = %38
%43 = load i32, i32* %11
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds [10 x i8], [10 x i8]* %9, i64 0, i64 %44
%46 = load i8, i8* %45
%47 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8 signext %46)
br label %48
48: ; preds = %42
%49 = load i32, i32* %11
%50 = add nsw i32 %49, 1
store i32 %50, i32* %11
br label %38
51: ; preds = %38
ret i32 0
}

LLVM IR (-O2):
@__const.main.mydata_start = [10 x i8] c"abcDEFghi\00"
@.str = [2 x i8] c"w\00"
@.str.1 = [2 x i8] c"a\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [17 x i8] c"Read %i bytes: \0A\00"
@.str.4 = [4 x i8] c"%c\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [10 x i8]
%4 = alloca [10 x i8]
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%8 = getelementptr inbounds [10 x i8], [10 x i8]* %4, i64 0, i64 0
%9 = tail call i32* @fopen(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%10 = call i32 @fwrite(i8* %7, i32 1, i32 4, i32* %9)
%11 = tail call i32 @fclose(i32* %9)
%12 = tail call i32* @fopen(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%13 = call i32 @fwrite(i8* %7, i32 1, i32 4, i32* %12)
%14 = tail call i32 @fclose(i32* %12)
%15 = tail call i32* @fopen(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%16 = call i32 @fread(i8* %8, i32 1, i32 15, i32* %15)
%17 = trunc i32 %16 to i8
%18 = tail call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), i8 signext %17)
%19 = icmp sgt i32 %16, 0
br i1 %19, label %20, label %22
20: ; preds = %2
%21 = zext i32 %16 to i64
br label %23
22: ; preds = %23, %2
ret i32 0
23: ; preds = %20, %23
%24 = phi i64 [ 0, %20 ], [ %28, %23 ]
%25 = getelementptr inbounds [10 x i8], [10 x i8]* %4, i64 0, i64 %24
%26 = load i8, i8* %25
%27 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8 signext %26)
%28 = add nuw nsw i64 %24, 1
%29 = icmp eq i64 %28, %21
br i1 %29, label %22, label %23
}