#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*/ content;

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ bzero(char *, int);
int errno;
int /*<<< orphan*/ lseek(int, int /*<<< orphan*/, int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int pread(int, char *, int, int);
int /*<<< orphan*/ printf(char *, ...);
int main() {
  int fd = open("Makefile", O_RDONLY);
  if (fd == -1) {
    perror("open");
    return errno;
  }
  char content[24] = {0};
  int ret = pread(fd, content, sizeof(content) - 1, 0);
  if (ret == -1) {
    perror("pread");
    return 0;
  }
  if (ret == 0) {
    printf("read over\n");
  } else {
    printf("%s\n", content);
  }
  lseek(fd, 0, SEEK_SET);
  bzero(content, sizeof(content));
  ret = pread(fd, content, sizeof(content) - 1, 5);
  if (ret == -1) {
    perror("pread");
    return 0;
  }
  if (ret == 0) {
    printf("read over\n");
  } else {
    printf("%s\n", content);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e62(%rip),%rax
mov    (%rax),%esi
lea    0xe71(%rip),%rdi
call   1060 <open@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
jne    11be <main+0x4e>
lea    0xe61(%rip),%rdi
call   1070 <perror@plt>
mov    0x2e24(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    12c7 <main+0x157>
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1050 <memset@plt>
mov    -0x8(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0x17,%edx
xor    %ecx,%ecx
call   1090 <pread@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0xffffffff,-0x24(%rbp)
jne    1206 <main+0x96>
lea    0xe19(%rip),%rdi
call   1070 <perror@plt>
movl   $0x0,-0x4(%rbp)
jmp    12c7 <main+0x157>
cmpl   $0x0,-0x24(%rbp)
jne    1223 <main+0xb3>
lea    0xdfd(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1235 <main+0xc5>
lea    -0x20(%rbp),%rsi
lea    0xdf1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%edi
mov    0x2d91(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1040 <lseek@plt>
lea    -0x20(%rbp),%rdi
mov    $0x18,%esi
call   1080 <bzero@plt>
mov    -0x8(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0x17,%edx
mov    $0x5,%ecx
call   1090 <pread@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0xffffffff,-0x24(%rbp)
jne    1291 <main+0x121>
lea    0xd8e(%rip),%rdi
call   1070 <perror@plt>
movl   $0x0,-0x4(%rbp)
jmp    12c7 <main+0x157>
cmpl   $0x0,-0x24(%rbp)
jne    12ae <main+0x13e>
lea    0xd72(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    12c0 <main+0x150>
lea    -0x20(%rbp),%rsi
lea    0xd66(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    0x2e7a(%rip),%rax
mov    (%rax),%esi
lea    0xe89(%rip),%rdi
call   1050 <open@plt>
cmp    $0xffffffff,%eax
je     1220 <main+0xc0>
mov    %eax,%ebx
xorps  %xmm0,%xmm0
movaps %xmm0,(%rsp)
movq   $0x0,0x10(%rsp)
mov    %rsp,%rsi
mov    %eax,%edi
mov    $0x17,%edx
xor    %ecx,%ecx
call   1080 <pread@plt>
test   %eax,%eax
je     11ba <main+0x5a>
cmp    $0xffffffff,%eax
je     1237 <main+0xd7>
mov    %rsp,%rdi
jmp    11c1 <main+0x61>
lea    0xe53(%rip),%rdi
call   1030 <puts@plt>
mov    0x2e03(%rip),%rax
mov    (%rax),%edx
mov    %ebx,%edi
xor    %esi,%esi
call   1040 <lseek@plt>
mov    %rsp,%r14
mov    %r14,%rdi
mov    $0x18,%esi
call   1070 <bzero@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x17,%edx
mov    $0x5,%ecx
call   1080 <pread@plt>
test   %eax,%eax
je     120a <main+0xaa>
cmp    $0xffffffff,%eax
je     1237 <main+0xd7>
mov    %rsp,%rdi
jmp    1211 <main+0xb1>
lea    0xe03(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret
lea    0xde2(%rip),%rdi
call   1060 <perror@plt>
mov    0x2da5(%rip),%rax
mov    (%rax),%eax
jmp    1218 <main+0xb8>
lea    0xdd0(%rip),%rdi
call   1060 <perror@plt>
jmp    1216 <main+0xb6>

LLVM IR (-O0):
@.str = [9 x i8] c"Makefile\00"
@O_RDONLY = global i32 0
@.str.1 = [5 x i8] c"open\00"
@errno = global i32 0
@.str.2 = [6 x i8] c"pread\00"
@.str.3 = [11 x i8] c"read over\0A\00"
@.str.4 = [4 x i8] c"%s\0A\00"
@SEEK_SET = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [24 x i8]
%4 = alloca i32
store i32 0, i32* %1
%5 = load i32, i32* @O_RDONLY
%6 = call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %5)
store i32 %6, i32* %2
%7 = load i32, i32* %2
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %12
9: ; preds = %0
%10 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%11 = load i32, i32* @errno
store i32 %11, i32* %1
br label %51
12: ; preds = %0
%13 = bitcast [24 x i8]* %3 to i8*
%14 = load i32, i32* %2
%15 = getelementptr inbounds [24 x i8], [24 x i8]* %3, i64 0, i64 0
%16 = call i32 @pread(i32 %14, i8* %15, i32 23, i32 0)
store i32 %16, i32* %4
%17 = load i32, i32* %4
%18 = icmp eq i32 %17, -1
br i1 %18, label %19, label %21
19: ; preds = %12
%20 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %1
br label %51
21: ; preds = %12
%22 = load i32, i32* %4
%23 = icmp eq i32 %22, 0
br i1 %23, label %24, label %26
24: ; preds = %21
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
br label %29
26: ; preds = %21
%27 = getelementptr inbounds [24 x i8], [24 x i8]* %3, i64 0, i64 0
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %27)
br label %29
29: ; preds = %26, %24
%30 = load i32, i32* %2
%31 = load i32, i32* @SEEK_SET
%32 = call i32 @lseek(i32 %30, i32 0, i32 %31)
%33 = getelementptr inbounds [24 x i8], [24 x i8]* %3, i64 0, i64 0
%34 = call i32 @bzero(i8* %33, i32 24)
%35 = load i32, i32* %2
%36 = getelementptr inbounds [24 x i8], [24 x i8]* %3, i64 0, i64 0
%37 = call i32 @pread(i32 %35, i8* %36, i32 23, i32 5)
store i32 %37, i32* %4
%38 = load i32, i32* %4
%39 = icmp eq i32 %38, -1
br i1 %39, label %40, label %42
40: ; preds = %29
%41 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %1
br label %51
42: ; preds = %29
%43 = load i32, i32* %4
%44 = icmp eq i32 %43, 0
br i1 %44, label %45, label %47
45: ; preds = %42
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
br label %50
47: ; preds = %42
%48 = getelementptr inbounds [24 x i8], [24 x i8]* %3, i64 0, i64 0
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %48)
br label %50
50: ; preds = %47, %45
store i32 0, i32* %1
br label %51
51: ; preds = %50, %40, %19, %9
%52 = load i32, i32* %1
ret i32 %52
}

LLVM IR (-O2):
@.str = [9 x i8] c"Makefile\00"
@O_RDONLY = global i32 0
@.str.1 = [5 x i8] c"open\00"
@errno = global i32 0
@.str.2 = [6 x i8] c"pread\00"
@SEEK_SET = global i32 0
@str.5 = [10 x i8] c"read over\00"
define i32 @main() {
%1 = alloca [24 x i8]
%2 = load i32, i32* @O_RDONLY
%3 = tail call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %2)
%4 = icmp eq i32 %3, -1
br i1 %4, label %5, label %8
5: ; preds = %0
%6 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%7 = load i32, i32* @errno
br label %29
8: ; preds = %0
%9 = getelementptr inbounds [24 x i8], [24 x i8]* %1, i64 0, i64 0
%10 = call i32 @pread(i32 %3, i8* %9, i32 23, i32 0)
switch i32 %10, label %15 [
i32 -1, label %11
i32 0, label %13
]
11: ; preds = %8
%12 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
br label %28
13: ; preds = %8
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str.5, i64 0, i64 0))
br label %17
15: ; preds = %8
%16 = call i32 @puts(i8* %9)
br label %17
17: ; preds = %15, %13
%18 = load i32, i32* @SEEK_SET
%19 = tail call i32 @lseek(i32 %3, i32 0, i32 %18)
%20 = call i32 @bzero(i8* %9, i32 24)
%21 = call i32 @pread(i32 %3, i8* %9, i32 23, i32 5)
switch i32 %21, label %26 [
i32 -1, label %22
i32 0, label %24
]
22: ; preds = %17
%23 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
br label %28
24: ; preds = %17
%25 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str.5, i64 0, i64 0))
br label %28
26: ; preds = %17
%27 = call i32 @puts(i8* %9)
br label %28
28: ; preds = %24, %26, %22, %11
br label %29
29: ; preds = %28, %5
%30 = phi i32 [ %7, %5 ], [ 0, %28 ]
ret i32 %30
}