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

/* Variables and functions */
size_t __get_array_size(void *);
int __infer_nondet_int();
ssize_t read(int fildes, void *buf, size_t nbyte) {
  if (nbyte == 0)
    return 0;
  if (__get_array_size(buf) < nbyte)
    while (1)
      ;
  int ret = __infer_nondet_int();
  if (ret < -1 || ret > nbyte)
    while (1)
      ;
  return ret;
}


x86 assembly (clang, -O0):
<read>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    114a <read+0x2a>
movl   $0x0,-0x4(%rbp)
jmp    1199 <read+0x79>
mov    -0x10(%rbp),%rdi
call   1040 <__get_array_size@plt>
cmp    -0x18(%rbp),%rax
jae    1167 <read+0x47>
jmp    1162 <read+0x42>
jmp    1162 <read+0x42>
mov    $0x0,%al
call   1030 <__infer_nondet_int@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jl     1189 <read+0x69>
movslq -0x1c(%rbp),%rax
cmp    -0x18(%rbp),%rax
jbe    1193 <read+0x73>
jmp    118e <read+0x6e>
jmp    118e <read+0x6e>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read>:
push   %rbx
test   %rdx,%rdx
je     1142 <read+0x22>
mov    %rdx,%rbx
mov    %rsi,%rdi
call   1040 <__get_array_size@plt>
cmp    %rbx,%rax
jae    1146 <read+0x26>
cs nopw 0x0(%rax,%rax,1)
jmp    1140 <read+0x20>
xor    %eax,%eax
jmp    115a <read+0x3a>
xor    %eax,%eax
call   1030 <__infer_nondet_int@plt>
cmp    $0xffffffff,%eax
jl     1160 <read+0x40>
movslq %eax,%rcx
cmp    %rbx,%rcx
ja     1160 <read+0x40>
pop    %rbx
ret
nopl   0x0(%rax)
jmp    1160 <read+0x40>

LLVM IR (-O0):
define i32 @read(i32 %0, i8* %1, i64 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i32
store i32 %0, i32* %5
store i8* %1, i8** %6
store i64 %2, i64* %7
%9 = load i64, i64* %7
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %12
11: ; preds = %3
store i32 0, i32* %4
br label %32
12: ; preds = %3
%13 = load i8*, i8** %6
%14 = call i64 @__get_array_size(i8* %13)
%15 = load i64, i64* %7
%16 = icmp ult i64 %14, %15
br i1 %16, label %17, label %19
17: ; preds = %12
br label %18
18: ; preds = %17, %18
br label %18
19: ; preds = %12
%20 = call i32 (...) @__infer_nondet_int()
store i32 %20, i32* %8
%21 = load i32, i32* %8
%22 = icmp slt i32 %21, -1
br i1 %22, label %28, label %23
23: ; preds = %19
%24 = load i32, i32* %8
%25 = sext i32 %24 to i64
%26 = load i64, i64* %7
%27 = icmp ugt i64 %25, %26
br i1 %27, label %28, label %30
28: ; preds = %23, %19
br label %29
29: ; preds = %28, %29
br label %29
30: ; preds = %23
%31 = load i32, i32* %8
store i32 %31, i32* %4
br label %32
32: ; preds = %30, %11
%33 = load i32, i32* %4
ret i32 %33
}

LLVM IR (-O2):
define i32 @read(i32 %0, i8* %1, i64 %2) {
%4 = icmp eq i64 %2, 0
br i1 %4, label %16, label %5
5: ; preds = %3
%6 = tail call i64 @__get_array_size(i8* %1)
%7 = icmp ult i64 %6, %2
br i1 %7, label %8, label %9
8: ; preds = %5, %8
br label %8
9: ; preds = %5
%10 = tail call i32 (...) @__infer_nondet_int()
%11 = icmp slt i32 %10, -1
%12 = sext i32 %10 to i64
%13 = icmp ugt i64 %12, %2
%14 = or i1 %11, %13
br i1 %14, label %15, label %16
15: ; preds = %9, %15
br label %15
16: ; preds = %9, %3
%17 = phi i32 [ 0, %3 ], [ %10, %9 ]
ret i32 %17
}