#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, 10, 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    $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    $0xf,%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
cmp    -0x38(%rbp),%eax
jge    1232 <main+0xe2>
movslq -0x3c(%rbp),%rax
lea    0xe05(%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    $0xf,%edx
mov    %rax,%rcx
call   1030 <fread@plt>
mov    %eax,%ebx
movsbl %bl,%esi
lea    0xe38(%rip),%rdi
call   1050 <printf@plt>
test   %ebx,%ebx
jle    1206 <main+0xb6>
mov    %ebx,%r15d
xor    %ebx,%ebx
lea    0xe34(%rip),%r14
nopl   0x0(%rax,%rax,1)
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 15, 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 = %41, %2
%32 = load i32, i32* %11
%33 = load i32, i32* %10
%34 = icmp slt i32 %32, %33
br i1 %34, label %35, label %44
35: ; preds = %31
%36 = load i32, i32* %11
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds [10 x i8], [10 x i8]* %9, i64 0, i64 %37
%39 = load i8, i8* %38
%40 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8 signext %39)
br label %41
41: ; preds = %35
%42 = load i32, i32* %11
%43 = add nsw i32 %42, 1
store i32 %43, i32* %11
br label %31
44: ; 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 15, 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, 0
br i1 %16, label %17, label %19
17: ; preds = %2
%18 = zext i32 %13 to i64
br label %20
19: ; preds = %20, %2
ret i32 0
20: ; preds = %17, %20
%21 = phi i64 [ 0, %17 ], [ %25, %20 ]
%22 = getelementptr inbounds [10 x i8], [10 x i8]* %4, i64 0, i64 %21
%23 = load i8, i8* %22
%24 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8 signext %23)
%25 = add nuw nsw i64 %21, 1
%26 = icmp eq i64 %25, %18
br i1 %26, label %19, label %20
}