#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 */
struct file {
  int dummy;
};

/* Variables and functions */
scalar_t__ argfd(int /*<<< orphan*/, int /*<<< orphan*/, struct file **);
scalar_t__ argint(int, int *);
scalar_t__ argptr(int, char **, int);
int fileread(struct file *, char *, int);
int sys_read(void) {
  struct file *f;
  int n;
  char *p;
  if (argfd(0, 0, &f) < 0 || argint(2, &n) < 0 || argptr(1, &p, n) < 0) {
    return -1;
  }
  return fileread(f, p, n);
}


x86 assembly (clang, -O0):
<sys_read>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
xor    %esi,%esi
lea    -0x10(%rbp),%rdx
mov    %esi,%edi
call   1060 <argfd@plt>
cmp    $0x0,%rax
jl     1192 <sys_read+0x52>
mov    $0x2,%edi
lea    -0x14(%rbp),%rsi
call   1050 <argint@plt>
cmp    $0x0,%rax
jl     1192 <sys_read+0x52>
mov    -0x14(%rbp),%edx
mov    $0x1,%edi
lea    -0x20(%rbp),%rsi
call   1030 <argptr@plt>
cmp    $0x0,%rax
jge    119e <sys_read+0x5e>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b1 <sys_read+0x71>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1040 <fileread@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sys_read>:
push   %rbx
sub    $0x20,%rsp
lea    0x18(%rsp),%rdx
xor    %edi,%edi
xor    %esi,%esi
call   1060 <argfd@plt>
mov    $0xffffffff,%ebx
test   %rax,%rax
js     119e <sys_read+0x5e>
lea    0xc(%rsp),%rsi
mov    $0x2,%edi
call   1050 <argint@plt>
test   %rax,%rax
js     119e <sys_read+0x5e>
mov    0xc(%rsp),%edx
lea    0x10(%rsp),%rsi
mov    $0x1,%edi
call   1030 <argptr@plt>
test   %rax,%rax
js     119e <sys_read+0x5e>
mov    0x18(%rsp),%rdi
mov    0x10(%rsp),%rsi
mov    0xc(%rsp),%edx
call   1040 <fileread@plt>
mov    %eax,%ebx
mov    %ebx,%eax
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.file = type { i32 }
define i32 @sys_read() {
%1 = alloca i32
%2 = alloca %struct.file*
%3 = alloca i32
%4 = alloca i8*
%5 = call i64 @argfd(i32 0, i32 0, %struct.file** %2)
%6 = icmp slt i64 %5, 0
br i1 %6, label %14, label %7
7: ; preds = %0
%8 = call i64 @argint(i32 2, i32* %3)
%9 = icmp slt i64 %8, 0
br i1 %9, label %14, label %10
10: ; preds = %7
%11 = load i32, i32* %3
%12 = call i64 @argptr(i32 1, i8** %4, i32 %11)
%13 = icmp slt i64 %12, 0
br i1 %13, label %14, label %15
14: ; preds = %10, %7, %0
store i32 -1, i32* %1
br label %20
15: ; preds = %10
%16 = load %struct.file*, %struct.file** %2
%17 = load i8*, i8** %4
%18 = load i32, i32* %3
%19 = call i32 @fileread(%struct.file* %16, i8* %17, i32 %18)
store i32 %19, i32* %1
br label %20
20: ; preds = %15, %14
%21 = load i32, i32* %1
ret i32 %21
}

LLVM IR (-O2):
%struct.file = type { i32 }
define i32 @sys_read() {
%1 = alloca %struct.file*
%2 = alloca i32
%3 = alloca i8*
%4 = bitcast %struct.file** %1 to i8*
%5 = bitcast i32* %2 to i8*
%6 = bitcast i8** %3 to i8*
%7 = call i64 @argfd(i32 0, i32 0, %struct.file** %1)
%8 = icmp slt i64 %7, 0
br i1 %8, label %21, label %9
9: ; preds = %0
%10 = call i64 @argint(i32 2, i32* %2)
%11 = icmp slt i64 %10, 0
br i1 %11, label %21, label %12
12: ; preds = %9
%13 = load i32, i32* %2
%14 = call i64 @argptr(i32 1, i8** %3, i32 %13)
%15 = icmp slt i64 %14, 0
br i1 %15, label %21, label %16
16: ; preds = %12
%17 = load %struct.file*, %struct.file** %1
%18 = load i8*, i8** %3
%19 = load i32, i32* %2
%20 = call i32 @fileread(%struct.file* %17, i8* %18, i32 %19)
br label %21
21: ; preds = %0, %9, %12, %16
%22 = phi i32 [ %20, %16 ], [ -1, %12 ], [ -1, %9 ], [ -1, %0 ]
ret i32 %22
}