#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\0";
  char mydata_end[10];
  int num;
  f = fopen(fname, "w");
  fwrite(mydata_start, 1, 10, f);
  fclose(f);
  f = fopen(fname, "r");
  num = fread(mydata_end, 1, 10, f);
  printf("Read %i bytes: \n", num);
  for (int i = 0; i < num - 1; 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    $0xa,%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    -0x34(%rbp),%rdi
mov    -0x20(%rbp),%rcx
mov    $0x1,%esi
mov    $0xa,%edx
call   1030 <fread@plt>
mov    %eax,-0x38(%rbp)
mov    -0x38(%rbp),%eax
lea    0xe1a(%rip),%rdi
movsbl %al,%esi
call   1050 <printf@plt>
movl   $0x0,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
mov    -0x38(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    1237 <main+0xe7>
movslq -0x3c(%rbp),%rax
lea    0xe00(%rip),%rdi
movsbl -0x34(%rbp,%rax,1),%esi
call   1050 <printf@plt>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    1203 <main+0xb3>
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),%rdi
mov    $0x1,%esi
mov    $0xa,%edx
mov    %rax,%rcx
call   1070 <fwrite@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
lea    0xe61(%rip),%rsi
mov    %r14,%rdi
call   1060 <fopen@plt>
lea    0x16(%rsp),%rdi
mov    $0x1,%esi
mov    $0xa,%edx
mov    %rax,%rcx
call   1030 <fread@plt>
mov    %eax,%r15d
movsbl %r15b,%esi
lea    0xe36(%rip),%rdi
call   1050 <printf@plt>
cmp    $0x2,%r15d
jl     1206 <main+0xb6>
add    $0xffffffff,%r15d
xor    %ebx,%ebx
lea    0xe2f(%rip),%r14
movsbl 0x16(%rsp,%rbx,1),%esi
mov    %r14,%rdi
call   1050 <printf@plt>
add    $0x1,%rbx
cmp    %rbx,%r15
jne    11f0 <main+0xa0>
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"r\00"
@.str.2 = [17 x i8] c"Read %i bytes: \0A\00"
@.str.3 = [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 10, 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]* %9, i64 0, i64 0
%26 = load i32*, i32** %7
%27 = call i32 @fread(i8* %25, i32 1, i32 10, i32* %26)
store i32 %27, i32* %10
%28 = load i32, i32* %10
%29 = trunc i32 %28 to i8
%30 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8 signext %29)
store i32 0, i32* %11
br label %31
31: ; preds = %42, %2
%32 = load i32, i32* %11
%33 = load i32, i32* %10
%34 = sub nsw i32 %33, 1
%35 = icmp slt i32 %32, %34
br i1 %35, label %36, label %45
36: ; preds = %31
%37 = load i32, i32* %11
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds [10 x i8], [10 x i8]* %9, i64 0, i64 %38
%40 = load i8, i8* %39
%41 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8 signext %40)
br label %42
42: ; preds = %36
%43 = load i32, i32* %11
%44 = add nsw i32 %43, 1
store i32 %44, i32* %11
br label %31
45: ; preds = %31
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"r\00"
@.str.2 = [17 x i8] c"Read %i bytes: \0A\00"
@.str.3 = [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 10, 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 @fread(i8* %8, i32 1, i32 10, i32* %12)
%14 = trunc i32 %13 to i8
%15 = tail call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8 signext %14)
%16 = icmp sgt i32 %13, 1
br i1 %16, label %17, label %20
17: ; preds = %2
%18 = add nsw i32 %13, -1
%19 = zext i32 %18 to i64
br label %21
20: ; preds = %21, %2
ret i32 0
21: ; preds = %17, %21
%22 = phi i64 [ 0, %17 ], [ %26, %21 ]
%23 = getelementptr inbounds [10 x i8], [10 x i8]* %4, i64 0, i64 %22
%24 = load i8, i8* %23
%25 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8 signext %24)
%26 = add nuw nsw i64 %22, 1
%27 = icmp eq i64 %26, %19
br i1 %27, label %20, label %21
}