#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*/ SEEK_CUR;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, 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");
  fread(mydata_end, 1, 10, f);
  fseek(f, -5, SEEK_CUR);
  num = fread(mydata_end, 1, 3, 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    0xe77(%rip),%rax
mov    %rax,-0x2a(%rbp)
mov    0xe74(%rip),%ax
mov    %ax,-0x22(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe67(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x20(%rbp)
lea    -0x2a(%rbp),%rdi
mov    -0x20(%rbp),%rcx
mov    $0x1,%esi
mov    $0xa,%edx
call   1080 <fwrite@plt>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x18(%rbp),%rdi
lea    0xe35(%rip),%rsi
call   1070 <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    -0x20(%rbp),%rdi
mov    0x2de6(%rip),%rax
mov    (%rax),%edx
mov    $0xfffffffb,%esi
call   1060 <fseek@plt>
lea    -0x34(%rbp),%rdi
mov    -0x20(%rbp),%rcx
mov    $0x1,%esi
mov    $0x3,%edx
call   1030 <fread@plt>
mov    %eax,-0x38(%rbp)
mov    -0x38(%rbp),%eax
lea    0xddc(%rip),%rdi
movsbl %al,%esi
call   1050 <printf@plt>
movl   $0x0,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0x38(%rbp),%eax
jge    1270 <main+0x110>
movslq -0x3c(%rbp),%rax
lea    0xdc7(%rip),%rdi
movsbl -0x34(%rbp,%rax,1),%esi
call   1050 <printf@plt>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    1241 <main+0xe1>
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    0xe80(%rip),%rsi
mov    %r14,%rdi
call   1070 <fopen@plt>
mov    %rax,%rbx
lea    0x8(%rsp),%rdi
mov    $0x1,%esi
mov    $0xa,%edx
mov    %rax,%rcx
call   1080 <fwrite@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
lea    0xe51(%rip),%rsi
mov    %r14,%rdi
call   1070 <fopen@plt>
mov    %rax,%rbx
lea    0x16(%rsp),%r14
mov    %r14,%rdi
mov    $0x1,%esi
mov    $0xa,%edx
mov    %rax,%rcx
call   1030 <fread@plt>
mov    0x2e01(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
mov    $0xfffffffb,%esi
call   1060 <fseek@plt>
mov    %r14,%rdi
mov    $0x1,%esi
mov    $0x3,%edx
mov    %rbx,%rcx
call   1030 <fread@plt>
mov    %eax,%ebx
movsbl %bl,%esi
lea    0xdf7(%rip),%rdi
call   1050 <printf@plt>
test   %ebx,%ebx
jle    1246 <main+0xe6>
mov    %ebx,%r15d
xor    %ebx,%ebx
lea    0xdf3(%rip),%r14
nopl   0x0(%rax)
movsbl 0x16(%rsp,%rbx,1),%esi
mov    %r14,%rdi
call   1050 <printf@plt>
add    $0x1,%rbx
cmp    %rbx,%r15
jne    1230 <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"r\00"
@SEEK_CUR = global i32 0
@.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)
%28 = load i32*, i32** %7
%29 = load i32, i32* @SEEK_CUR
%30 = call i32 @fseek(i32* %28, i32 -5, i32 %29)
%31 = getelementptr inbounds [10 x i8], [10 x i8]* %9, i64 0, i64 0
%32 = load i32*, i32** %7
%33 = call i32 @fread(i8* %31, i32 1, i32 3, i32* %32)
store i32 %33, i32* %10
%34 = load i32, i32* %10
%35 = trunc i32 %34 to i8
%36 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8 signext %35)
store i32 0, i32* %11
br label %37
37: ; preds = %47, %2
%38 = load i32, i32* %11
%39 = load i32, i32* %10
%40 = icmp slt i32 %38, %39
br i1 %40, label %41, label %50
41: ; preds = %37
%42 = load i32, i32* %11
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds [10 x i8], [10 x i8]* %9, i64 0, i64 %43
%45 = load i8, i8* %44
%46 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8 signext %45)
br label %47
47: ; preds = %41
%48 = load i32, i32* %11
%49 = add nsw i32 %48, 1
store i32 %49, i32* %11
br label %37
50: ; preds = %37
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"
@SEEK_CUR = global i32 0
@.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 = load i32, i32* @SEEK_CUR
%15 = tail call i32 @fseek(i32* %12, i32 -5, i32 %14)
%16 = call i32 @fread(i8* %8, i32 1, i32 3, i32* %12)
%17 = trunc i32 %16 to i8
%18 = tail call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, 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.3, 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
}