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

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ assert(int);
int lseek(int, int /*<<< orphan*/, int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char *);
scalar_t__ read(int, char *, size_t);
int main() {
  int fd = open("/proc/uptime", O_RDONLY);
  assert(fd != -1);
  while (1) {
    size_t bufsize = 256;
    char buf[bufsize];
    ssize_t count_read = read(fd, buf, bufsize);
    printf("count_read is %ld\n", count_read);
    assert(count_read > 0);
    printf("we got [%s]\n", buf);
    int ret = lseek(fd, SEEK_SET, 0);
    assert(ret != -1);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e82(%rip),%rax
mov    (%rax),%esi
lea    0xe91(%rip),%rdi
call   1070 <open@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
movq   $0x100,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
mov    %rcx,-0x48(%rbp)
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rsi
sub    %rcx,%rsi
mov    %rsi,-0x38(%rbp)
mov    %rsi,%rsp
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rdx
call   1050 <read@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rsi
lea    0xe37(%rip),%rdi
call   1030 <printf@plt>
cmpq   $0x0,-0x28(%rbp)
setg   %al
and    $0x1,%al
mov    %al,-0x39(%rbp)
movzbl %al,%edi
call   1060 <assert@plt>
mov    -0x38(%rbp),%rsi
lea    0xe25(%rip),%rdi
call   1030 <printf@plt>
mov    -0x8(%rbp),%edi
mov    0x2dce(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1040 <lseek@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0xffffffff,-0x2c(%rbp)
setne  %al
and    $0x1,%al
mov    %al,-0x2d(%rbp)
movzbl %al,%edi
call   1060 <assert@plt>
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
jmp    1188 <main+0x38>

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    0x2e83(%rip),%rax
mov    (%rax),%esi
lea    0xe92(%rip),%rdi
call   1070 <open@plt>
mov    %eax,%r12d
xor    %edi,%edi
cmp    $0xffffffff,%eax
setne  %dil
call   1060 <assert@plt>
mov    0x2e4d(%rip),%r14
nopl   0x0(%rax,%rax,1)
mov    %rsp,%r15
lea    -0x100(%rsp),%r13
ff
mov    %r13,%rsp
mov    $0x100,%edx
mov    %r12d,%edi
mov    %r13,%rsi
call   1050 <read@plt>
mov    %rax,%rbx
lea    0xe55(%rip),%rdi
mov    %rax,%rsi
call   1030 <printf@plt>
xor    %edi,%edi
test   %rbx,%rbx
setg   %dil
call   1060 <assert@plt>
lea    0xe4b(%rip),%rdi
mov    %r13,%rsi
call   1030 <printf@plt>
mov    (%r14),%esi
mov    %r12d,%edi
xor    %edx,%edx
call   1040 <lseek@plt>
xor    %edi,%edi
cmp    $0xffffffff,%eax
setne  %dil
call   1060 <assert@plt>
mov    %r15,%rsp
jmp    1190 <main+0x40>

LLVM IR (-O0):
@.str = [13 x i8] c"/proc/uptime\00"
@O_RDONLY = global i32 0
@.str.1 = [19 x i8] c"count_read is %ld\0A\00"
@.str.2 = [13 x i8] c"we got [%s]\0A\00"
@SEEK_SET = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i64
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i64
%7 = alloca i32
store i32 0, i32* %1
%8 = load i32, i32* @O_RDONLY
%9 = call i32 @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %8)
store i32 %9, i32* %2
%10 = load i32, i32* %2
%11 = icmp ne i32 %10, -1
%12 = zext i1 %11 to i32
%13 = call i32 @assert(i32 %12)
br label %14
14: ; preds = %0, %14
store i64 256, i64* %3
%15 = load i64, i64* %3
%16 = call i8* @llvm.stacksave()
store i8* %16, i8** %4
%17 = alloca i8, i64 %15
store i64 %15, i64* %5
%18 = load i32, i32* %2
%19 = load i64, i64* %3
%20 = call i64 @read(i32 %18, i8* %17, i64 %19)
store i64 %20, i64* %6
%21 = load i64, i64* %6
%22 = inttoptr i64 %21 to i8*
%23 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* %22)
%24 = load i64, i64* %6
%25 = icmp sgt i64 %24, 0
%26 = zext i1 %25 to i32
%27 = call i32 @assert(i32 %26)
%28 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i8* %17)
%29 = load i32, i32* %2
%30 = load i32, i32* @SEEK_SET
%31 = call i32 @lseek(i32 %29, i32 %30, i32 0)
store i32 %31, i32* %7
%32 = load i32, i32* %7
%33 = icmp ne i32 %32, -1
%34 = zext i1 %33 to i32
%35 = call i32 @assert(i32 %34)
%36 = load i8*, i8** %4
br label %14
}

LLVM IR (-O2):
@.str = [13 x i8] c"/proc/uptime\00"
@O_RDONLY = global i32 0
@.str.1 = [19 x i8] c"count_read is %ld\0A\00"
@.str.2 = [13 x i8] c"we got [%s]\0A\00"
@SEEK_SET = global i32 0
define i32 @main() {
%1 = load i32, i32* @O_RDONLY
%2 = tail call i32 @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %1)
%3 = icmp ne i32 %2, -1
%4 = zext i1 %3 to i32
%5 = tail call i32 @assert(i32 %4)
br label %6
6: ; preds = %6, %0
%7 = call i8* @llvm.stacksave()
%8 = alloca [256 x i8]
%9 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%10 = call i64 @read(i32 %2, i8* %9, i64 256)
%11 = inttoptr i64 %10 to i8*
%12 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* %11)
%13 = icmp sgt i64 %10, 0
%14 = zext i1 %13 to i32
%15 = call i32 @assert(i32 %14)
%16 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i8* %9)
%17 = load i32, i32* @SEEK_SET
%18 = call i32 @lseek(i32 %2, i32 %17, i32 0)
%19 = icmp ne i32 %18, -1
%20 = zext i1 %19 to i32
%21 = call i32 @assert(i32 %20)
br label %6
}