#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 size_t ssize_t;

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ lseek(int, int, int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char *);
size_t read(int, char *, int);
int main(int argc, char **argv) {
  int fd;
  ssize_t n1, n2;
  char buf1[10], buf2[10];
  fd = open("file.dat", O_RDONLY);
  n1 = read(fd, buf1, 8);
  buf1[n1] = 0;
  lseek(fd, 5, SEEK_SET);
  n2 = read(fd, buf2, 8);
  buf2[n2] = 0;
  close(fd);
  printf("buf1 = %s\n", buf1);
  printf("buf2 = %s\n", buf2);
  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    0x2e7b(%rip),%rax
mov    (%rax),%esi
lea    0xe8a(%rip),%rdi
call   1070 <open@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x32(%rbp),%rsi
mov    $0x8,%edx
call   1060 <read@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movb   $0x0,-0x32(%rbp,%rax,1)
mov    -0x14(%rbp),%edi
mov    0x2e32(%rip),%rax
mov    (%rax),%edx
mov    $0x5,%esi
call   1040 <lseek@plt>
mov    -0x14(%rbp),%edi
lea    -0x3c(%rbp),%rsi
mov    $0x8,%edx
call   1060 <read@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
movb   $0x0,-0x3c(%rbp,%rax,1)
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
lea    -0x32(%rbp),%rsi
lea    0xe26(%rip),%rdi
call   1030 <printf@plt>
lea    -0x3c(%rbp),%rsi
lea    0xe21(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    0x2e89(%rip),%rax
mov    (%rax),%esi
lea    0xe98(%rip),%rdi
call   1070 <open@plt>
mov    %eax,%ebp
lea    0x16(%rsp),%r14
mov    %eax,%edi
mov    %r14,%rsi
mov    $0x8,%edx
call   1060 <read@plt>
movb   $0x0,0x16(%rsp,%rax,1)
mov    0x2e49(%rip),%rax
mov    (%rax),%edx
mov    %ebp,%edi
mov    $0x5,%esi
call   1040 <lseek@plt>
lea    0xc(%rsp),%rbx
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x8,%edx
call   1060 <read@plt>
movb   $0x0,0xc(%rsp,%rax,1)
mov    %ebp,%edi
call   1050 <close@plt>
lea    0xe45(%rip),%rdi
mov    %r14,%rsi
call   1030 <printf@plt>
lea    0xe41(%rip),%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [9 x i8] c"file.dat\00"
@O_RDONLY = global i32 0
@SEEK_SET = global i32 0
@.str.1 = [11 x i8] c"buf1 = %s\0A\00"
@.str.2 = [11 x i8] c"buf2 = %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i64
%8 = alloca i64
%9 = alloca [10 x i8]
%10 = alloca [10 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* @O_RDONLY
%12 = call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %11)
store i32 %12, i32* %6
%13 = load i32, i32* %6
%14 = getelementptr inbounds [10 x i8], [10 x i8]* %9, i64 0, i64 0
%15 = call i64 @read(i32 %13, i8* %14, i32 8)
store i64 %15, i64* %7
%16 = load i64, i64* %7
%17 = getelementptr inbounds [10 x i8], [10 x i8]* %9, i64 0, i64 %16
store i8 0, i8* %17
%18 = load i32, i32* %6
%19 = load i32, i32* @SEEK_SET
%20 = call i32 @lseek(i32 %18, i32 5, i32 %19)
%21 = load i32, i32* %6
%22 = getelementptr inbounds [10 x i8], [10 x i8]* %10, i64 0, i64 0
%23 = call i64 @read(i32 %21, i8* %22, i32 8)
store i64 %23, i64* %8
%24 = load i64, i64* %8
%25 = getelementptr inbounds [10 x i8], [10 x i8]* %10, i64 0, i64 %24
store i8 0, i8* %25
%26 = load i32, i32* %6
%27 = call i32 @close(i32 %26)
%28 = getelementptr inbounds [10 x i8], [10 x i8]* %9, i64 0, i64 0
%29 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* %28)
%30 = getelementptr inbounds [10 x i8], [10 x i8]* %10, i64 0, i64 0
%31 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8* %30)
ret i32 0
}

LLVM IR (-O2):
@.str = [9 x i8] c"file.dat\00"
@O_RDONLY = global i32 0
@SEEK_SET = global i32 0
@.str.1 = [11 x i8] c"buf1 = %s\0A\00"
@.str.2 = [11 x i8] c"buf2 = %s\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [10 x i8]
%4 = alloca [10 x i8]
%5 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [10 x i8], [10 x i8]* %4, i64 0, i64 0
%7 = load i32, i32* @O_RDONLY
%8 = tail call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %7)
%9 = call i64 @read(i32 %8, i8* %5, i32 8)
%10 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 %9
store i8 0, i8* %10
%11 = load i32, i32* @SEEK_SET
%12 = tail call i32 @lseek(i32 %8, i32 5, i32 %11)
%13 = call i64 @read(i32 %8, i8* %6, i32 8)
%14 = getelementptr inbounds [10 x i8], [10 x i8]* %4, i64 0, i64 %13
store i8 0, i8* %14
%15 = tail call i32 @close(i32 %8)
%16 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* %5)
%17 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8* %6)
ret i32 0
}