#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*/ SEEK_SET;
int /*<<< orphan*/ lseek(int, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int read(int, void *, int);
int file_read(int fd, void *buf, int count) {
  lseek(fd, 0, SEEK_SET);
  int ret = read(fd, buf, count);
  if (ret < 0) {
    perror("libsoc-file-debug");
    return -1;
  }
  return ret;
}


x86 assembly (clang, -O0):
<file_read>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2e94(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1030 <lseek@plt>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1040 <read@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    1189 <file_read+0x59>
lea    0xe88(%rip),%rdi
call   1050 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    118f <file_read+0x5f>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<file_read>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%r14d
mov    %rsi,%rbx
mov    %edi,%ebp
mov    0x2e9d(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1030 <lseek@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r14d,%edx
call   1040 <read@plt>
test   %eax,%eax
js     1162 <file_read+0x32>
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xe97(%rip),%rdi
call   1050 <perror@plt>
mov    $0xffffffff,%eax
jmp    115d <file_read+0x2d>

LLVM IR (-O0):
@SEEK_SET = global i32 0
@.str = [18 x i8] c"libsoc-file-debug\00"
define i32 @file_read(i32 %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %5
store i8* %1, i8** %6
store i32 %2, i32* %7
%9 = load i32, i32* %5
%10 = load i32, i32* @SEEK_SET
%11 = call i32 @lseek(i32 %9, i32 0, i32 %10)
%12 = load i32, i32* %5
%13 = load i8*, i8** %6
%14 = load i32, i32* %7
%15 = call i32 @read(i32 %12, i8* %13, i32 %14)
store i32 %15, i32* %8
%16 = load i32, i32* %8
%17 = icmp slt i32 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %3
%19 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %4
br label %22
20: ; preds = %3
%21 = load i32, i32* %8
store i32 %21, i32* %4
br label %22
22: ; preds = %20, %18
%23 = load i32, i32* %4
ret i32 %23
}

LLVM IR (-O2):
@SEEK_SET = global i32 0
@.str = [18 x i8] c"libsoc-file-debug\00"
define i32 @file_read(i32 %0, i8* nocapture %1, i32 %2) {
%4 = load i32, i32* @SEEK_SET
%5 = tail call i32 @lseek(i32 %0, i32 0, i32 %4)
%6 = tail call i32 @read(i32 %0, i8* %1, i32 %2)
%7 = icmp slt i32 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %3
%9 = tail call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
br label %10
10: ; preds = %3, %8
%11 = phi i32 [ -1, %8 ], [ %6, %3 ]
ret i32 %11
}