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

/* Variables and functions */
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ free(void *);
int lseek(int, int /*<<< orphan*/, int /*<<< orphan*/);
void *malloc(int);
int /*<<< orphan*/ perror(char *);
int read(int, void *, int);
int fs_test(int fd, off_t pos, int size) {
  void *buff;
  int status;
  if (lseek(fd, pos, SEEK_SET) == -1) {
    perror("status");
    return 0;
  }
  buff = malloc(size);
  status = read(fd, buff, size);
  perror("status");
  free(buff);
  return (status >= 0) ? status : 0;
}


x86 assembly (clang, -O0):
<fs_test>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
mov    0x2e72(%rip),%rax
mov    (%rax),%edx
call   1040 <lseek@plt>
cmp    $0xffffffff,%eax
jne    1196 <fs_test+0x46>
lea    0xe7b(%rip),%rdi
call   1070 <perror@plt>
movl   $0x0,-0x4(%rbp)
jmp    11ee <fs_test+0x9e>
mov    -0x10(%rbp),%edi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    -0x10(%rbp),%edx
call   1050 <read@plt>
mov    %eax,-0x1c(%rbp)
lea    0xe45(%rip),%rdi
call   1070 <perror@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
cmpl   $0x0,-0x1c(%rbp)
jl     11de <fs_test+0x8e>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x20(%rbp)
jmp    11e8 <fs_test+0x98>
xor    %eax,%eax
mov    %eax,-0x20(%rbp)
jmp    11e8 <fs_test+0x98>
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fs_test>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%ebx
mov    %edi,%ebp
mov    0x2e81(%rip),%rax
mov    (%rax),%edx
call   1040 <lseek@plt>
cmp    $0xffffffff,%eax
jne    117b <fs_test+0x2b>
lea    0xe8e(%rip),%rdi
call   1070 <perror@plt>
xor    %eax,%eax
jmp    11ae <fs_test+0x5e>
mov    %ebx,%edi
call   1060 <malloc@plt>
mov    %rax,%r14
mov    %ebp,%edi
mov    %rax,%rsi
mov    %ebx,%edx
call   1050 <read@plt>
mov    %eax,%ebx
lea    0xe66(%rip),%rdi
call   1070 <perror@plt>
mov    %r14,%rdi
call   1030 <free@plt>
xor    %eax,%eax
test   %ebx,%ebx
cmovns %ebx,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@SEEK_SET = global i32 0
@.str = [7 x i8] c"status\00"
define i32 @fs_test(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32 %2, i32* %7
%10 = load i32, i32* %5
%11 = load i32, i32* %6
%12 = load i32, i32* @SEEK_SET
%13 = call i32 @lseek(i32 %10, i32 %11, i32 %12)
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %17
15: ; preds = %3
%16 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %4
br label %34
17: ; preds = %3
%18 = load i32, i32* %7
%19 = call i8* @malloc(i32 %18)
store i8* %19, i8** %8
%20 = load i32, i32* %5
%21 = load i8*, i8** %8
%22 = load i32, i32* %7
%23 = call i32 @read(i32 %20, i8* %21, i32 %22)
store i32 %23, i32* %9
%24 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%25 = load i8*, i8** %8
%26 = call i32 @free(i8* %25)
%27 = load i32, i32* %9
%28 = icmp sge i32 %27, 0
br i1 %28, label %29, label %31
29: ; preds = %17
%30 = load i32, i32* %9
br label %32
31: ; preds = %17
br label %32
32: ; preds = %31, %29
%33 = phi i32 [ %30, %29 ], [ 0, %31 ]
store i32 %33, i32* %4
br label %34
34: ; preds = %32, %15
%35 = load i32, i32* %4
ret i32 %35
}

LLVM IR (-O2):
@SEEK_SET = global i32 0
@.str = [7 x i8] c"status\00"
define i32 @fs_test(i32 %0, i32 %1, i32 %2) {
%4 = load i32, i32* @SEEK_SET
%5 = tail call i32 @lseek(i32 %0, i32 %1, i32 %4)
%6 = icmp eq i32 %5, -1
br i1 %6, label %7, label %9
7: ; preds = %3
%8 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %16
9: ; preds = %3
%10 = tail call i8* @malloc(i32 %2)
%11 = tail call i32 @read(i32 %0, i8* %10, i32 %2)
%12 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%13 = tail call i32 @free(i8* %10)
%14 = icmp sgt i32 %11, 0
%15 = select i1 %14, i32 %11, i32 0
br label %16
16: ; preds = %9, %7
%17 = phi i32 [ 0, %7 ], [ %15, %9 ]
ret i32 %17
}