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

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ SEEK_SET;
scalar_t__ lseek(int, int, int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char *);
int read(int, char *, int);
int main() {
  int file = 0;
  if ((file = open("dir.c", O_RDONLY)) < -1)
    return 1;
  char buffer[19];
  if (read(file, buffer, 19) != 19)
    return 1;
  printf("%s\n", buffer);
  if (lseek(file, 10, SEEK_SET) < 0)
    return 1;
  if (read(file, buffer, 19) != 19)
    return 1;
  printf("%s\n", buffer);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
mov    0x2e8b(%rip),%rax
mov    (%rax),%esi
lea    0xe9a(%rip),%rdi
call   1060 <open@plt>
mov    %eax,-0x8(%rbp)
cmp    $0xffffffff,%eax
jge    1183 <main+0x43>
movl   $0x1,-0x4(%rbp)
jmp    1222 <main+0xe2>
mov    -0x8(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0x13,%edx
call   1050 <read@plt>
cmp    $0x13,%eax
je     11a9 <main+0x69>
movl   $0x1,-0x4(%rbp)
jmp    1222 <main+0xe2>
lea    -0x20(%rbp),%rsi
lea    0xe52(%rip),%rdi
call   1030 <printf@plt>
mov    -0x8(%rbp),%edi
mov    0x2e15(%rip),%rax
mov    (%rax),%edx
mov    $0xa,%esi
call   1040 <lseek@plt>
cmp    $0x0,%rax
jge    11e5 <main+0xa5>
movl   $0x1,-0x4(%rbp)
jmp    1222 <main+0xe2>
mov    -0x8(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0x13,%edx
call   1050 <read@plt>
cmp    $0x13,%eax
je     120b <main+0xcb>
movl   $0x1,-0x4(%rbp)
jmp    1222 <main+0xe2>
lea    -0x20(%rbp),%rsi
lea    0xdf0(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
mov    0x2e9b(%rip),%rax
mov    (%rax),%esi
lea    0xeaa(%rip),%rdi
call   1060 <open@plt>
mov    $0x1,%ebx
cmp    $0xffffffff,%eax
jl     11ce <main+0x8e>
mov    %eax,%ebp
mov    %rsp,%rsi
mov    %eax,%edi
mov    $0x13,%edx
call   1050 <read@plt>
mov    $0x1,%ebx
cmp    $0x13,%eax
jne    11ce <main+0x8e>
lea    0xe7f(%rip),%rdi
mov    %rsp,%rsi
call   1030 <printf@plt>
mov    0x2e42(%rip),%rax
mov    (%rax),%edx
mov    %ebp,%edi
mov    $0xa,%esi
call   1040 <lseek@plt>
test   %rax,%rax
js     11ce <main+0x8e>
mov    %rsp,%rsi
mov    %ebp,%edi
mov    $0x13,%edx
call   1050 <read@plt>
cmp    $0x13,%eax
jne    11ce <main+0x8e>
lea    0xe42(%rip),%rdi
mov    %rsp,%rsi
call   1030 <printf@plt>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [6 x i8] c"dir.c\00"
@O_RDONLY = global i32 0
@.str.1 = [4 x i8] c"%s\0A\00"
@SEEK_SET = global i32 0
define i32 @main() {
%1 = alloca [19 x i8]
%2 = load i32, i32* @O_RDONLY
%3 = tail call i32 @open(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %2)
%4 = icmp slt i32 %3, -1
br i1 %4, label %21, label %5
5: ; preds = %0
%6 = getelementptr inbounds [19 x i8], [19 x i8]* %1, i64 0, i64 0
%7 = call i32 @read(i32 %3, i8* %6, i32 19)
%8 = icmp eq i32 %7, 19
br i1 %8, label %9, label %19
9: ; preds = %5
%10 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %6)
%11 = load i32, i32* @SEEK_SET
%12 = call i64 @lseek(i32 %3, i32 10, i32 %11)
%13 = icmp slt i64 %12, 0
br i1 %13, label %19, label %14
14: ; preds = %9
%15 = call i32 @read(i32 %3, i8* %6, i32 19)
%16 = icmp eq i32 %15, 19
br i1 %16, label %17, label %19
17: ; preds = %14
%18 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %6)
br label %19
19: ; preds = %14, %9, %5, %17
%20 = phi i32 [ 0, %17 ], [ 1, %5 ], [ 1, %9 ], [ 1, %14 ]
br label %21
21: ; preds = %0, %19
%22 = phi i32 [ %20, %19 ], [ 1, %0 ]
ret i32 %22
}