#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_CUR;
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 *);
int read(int, char *, int);
int main(int argc, char *argv[]) {
  int fd;
  int de = 1;
  int c = 0;
  int bs = 1;
  char buff[bs];
  fd = open(argv[1], O_RDONLY);
  lseek(fd, 0, SEEK_SET);
  while (de) {
    c = c + 1;
    de = read(fd, buff, bs);
    printf("%s", buff);
    lseek(fd, de, SEEK_CUR);
  }
  close(fd);
  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)
movl   $0x1,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x1,-0x20(%rbp)
mov    -0x20(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x28(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x38(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e30(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
mov    0x2e0c(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1040 <lseek@plt>
cmpl   $0x0,-0x18(%rbp)
je     121b <main+0xcb>
mov    -0x38(%rbp),%rsi
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x14(%rbp),%edi
mov    -0x20(%rbp),%edx
call   1060 <read@plt>
mov    -0x38(%rbp),%rsi
mov    %eax,-0x18(%rbp)
lea    0xe03(%rip),%rdi
call   1030 <printf@plt>
mov    -0x14(%rbp),%edi
mov    -0x18(%rbp),%esi
mov    0x2dd9(%rip),%rax
mov    (%rax),%edx
call   1040 <lseek@plt>
jmp    11cd <main+0x7d>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    0x8(%rsi),%rdi
mov    0x2e79(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
mov    %eax,%ebx
mov    0x2e59(%rip),%rax
mov    (%rax),%edx
mov    %ebx,%edi
xor    %esi,%esi
call   1040 <lseek@plt>
mov    %rsp,%r14
lea    0xe74(%rip),%r15
mov    0x2e55(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x1,%edx
call   1060 <read@plt>
mov    %eax,%ebp
mov    %r15,%rdi
mov    %r14,%rsi
call   1030 <printf@plt>
mov    (%r12),%edx
mov    %ebx,%edi
mov    %ebp,%esi
call   1040 <lseek@plt>
test   %ebp,%ebp
jne    11a0 <main+0x50>
mov    %ebx,%edi
call   1050 <close@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@O_RDONLY = global i32 0
@SEEK_SET = global i32 0
@.str = [3 x i8] c"%s\00"
@SEEK_CUR = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 1, i32* %7
store i32 0, i32* %8
store i32 1, i32* %9
%12 = load i32, i32* %9
%13 = zext i32 %12 to i64
%14 = call i8* @llvm.stacksave()
store i8* %14, i8** %10
%15 = alloca i8, i64 %13
store i64 %13, i64* %11
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = load i8*, i8** %17
%19 = load i32, i32* @O_RDONLY
%20 = call i32 @open(i8* %18, i32 %19)
store i32 %20, i32* %6
%21 = load i32, i32* %6
%22 = load i32, i32* @SEEK_SET
%23 = call i32 @lseek(i32 %21, i32 0, i32 %22)
br label %24
24: ; preds = %27, %2
%25 = load i32, i32* %7
%26 = icmp ne i32 %25, 0
br i1 %26, label %27, label %38
27: ; preds = %24
%28 = load i32, i32* %8
%29 = add nsw i32 %28, 1
store i32 %29, i32* %8
%30 = load i32, i32* %6
%31 = load i32, i32* %9
%32 = call i32 @read(i32 %30, i8* %15, i32 %31)
store i32 %32, i32* %7
%33 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %15)
%34 = load i32, i32* %6
%35 = load i32, i32* %7
%36 = load i32, i32* @SEEK_CUR
%37 = call i32 @lseek(i32 %34, i32 %35, i32 %36)
br label %24
38: ; preds = %24
%39 = load i32, i32* %6
%40 = call i32 @close(i32 %39)
store i32 0, i32* %3
%41 = load i8*, i8** %10
%42 = load i32, i32* %3
ret i32 %42
}

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