#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 errno;
int /*<<< orphan*/ fflush(int /*<<< orphan*/ *);
int full_read(int, char *, size_t);
int handle_gez(int);
int /*<<< orphan*/ printf(char *, ...);
int read_test(int fd, char *buf, size_t len) {
  int ret, save_errno;
  int passed;
  printf("read(): fd=%d, buf=0x%p, len=%zu\n", fd, buf, len);
  fflush(NULL);
  passed = handle_gez(ret = full_read(fd, buf, len));
  save_errno = errno;
  switch (passed) {
  case -1:
  case 0:
    printf("\t\tRead %d blocks\n", ret);
    printf("\t\tret = %d\n", ret);
    printf("\tSucceeded Phase 1\n");
    fflush(NULL);
    break;
  case -2:
    printf("\tFailed Phase 1: returned undefined value! "
           "ret = %d\n",
           ret);
    fflush(NULL);
    break;
  default:
    printf("Internal syscalltester error: passed = %d\n", passed);
    fflush(NULL);
    break;
  }
  errno = save_errno;
  return ret;
}


x86 assembly (clang, -O0):
<read_test>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x4(%rbp),%esi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
lea    0xe9b(%rip),%rdi
xor    %eax,%eax
mov    %eax,-0x2c(%rbp)
call   1040 <printf@plt>
mov    -0x2c(%rbp),%eax
mov    %eax,%edi
call   1050 <fflush@plt>
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1030 <full_read@plt>
mov    %eax,%edi
mov    %edi,-0x1c(%rbp)
call   1060 <handle_gez@plt>
mov    %eax,-0x24(%rbp)
mov    0x2e43(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x28(%rbp)
sub    $0xfffffffe,%eax
je     1208 <read_test+0xc8>
jmp    11b6 <read_test+0x76>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
sub    $0x1,%eax
ja     1227 <read_test+0xe7>
jmp    11ca <read_test+0x8a>
mov    -0x1c(%rbp),%esi
lea    0xe4e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x1c(%rbp),%esi
lea    0xe4f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe4d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1050 <fflush@plt>
jmp    1241 <read_test+0x101>
mov    -0x1c(%rbp),%esi
lea    0xe42(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1050 <fflush@plt>
jmp    1241 <read_test+0x101>
mov    -0x24(%rbp),%esi
lea    0xe58(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1050 <fflush@plt>
mov    -0x20(%rbp),%ecx
mov    0x2d95(%rip),%rax
mov    %ecx,(%rax)
mov    -0x1c(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_test>:
push   %rbp
push   %r14
push   %rbx
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %edi,%ebp
lea    0xe9d(%rip),%rdi
mov    %ebp,%esi
mov    %rbx,%rdx
mov    %r14,%rcx
xor    %eax,%eax
call   1050 <printf@plt>
xor    %edi,%edi
call   1060 <fflush@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r14,%rdx
call   1040 <full_read@plt>
mov    %eax,%ebx
mov    %eax,%edi
call   1070 <handle_gez@plt>
mov    0x2e4a(%rip),%r14
mov    (%r14),%ebp
lea    0x1(%rax),%ecx
cmp    $0x2,%ecx
jae    11cf <read_test+0x7f>
lea    0xe7a(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe7c(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xed8(%rip),%rdi
call   1030 <puts@plt>
jmp    11ef <read_test+0x9f>
cmp    $0xfffffffe,%eax
jne    11df <read_test+0x8f>
lea    0xe65(%rip),%rdi
mov    %ebx,%esi
jmp    11e8 <read_test+0x98>
lea    0xe8f(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %edi,%edi
call   1060 <fflush@plt>
mov    %ebp,(%r14)
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [34 x i8] c"read(): fd=%d, buf=0x%p, len=%zu\0A\00"
@errno = global i32 0
@.str.1 = [18 x i8] c"\09\09Read %d blocks\0A\00"
@.str.2 = [12 x i8] c"\09\09ret = %d\0A\00"
@.str.3 = [20 x i8] c"\09Succeeded Phase 1\0A\00"
@.str.4 = [53 x i8] c"\09Failed Phase 1: returned undefined value! ret = %d\0A\00"
@.str.5 = [43 x i8] c"Internal syscalltester error: passed = %d\0A\00"
define i32 @read_test(i32 %0, i8* %1, i64 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 %0, i32* %4
store i8* %1, i8** %5
store i64 %2, i64* %6
%10 = load i32, i32* %4
%11 = load i8*, i8** %5
%12 = load i64, i64* %6
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i32 %10, i8* %11, i64 %12)
%14 = call i32 @fflush(i32* null)
%15 = load i32, i32* %4
%16 = load i8*, i8** %5
%17 = load i64, i64* %6
%18 = call i32 @full_read(i32 %15, i8* %16, i64 %17)
store i32 %18, i32* %7
%19 = call i32 @handle_gez(i32 %18)
store i32 %19, i32* %9
%20 = load i32, i32* @errno
store i32 %20, i32* %8
%21 = load i32, i32* %9
switch i32 %21, label %33 [
i32 -1, label %22
i32 0, label %22
i32 -2, label %29
]
22: ; preds = %3, %3
%23 = load i32, i32* %7
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i32 %23)
%25 = load i32, i32* %7
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32 %25)
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
%28 = call i32 @fflush(i32* null)
br label %37
29: ; preds = %3
%30 = load i32, i32* %7
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.4, i64 0, i64 0), i32 %30)
%32 = call i32 @fflush(i32* null)
br label %37
33: ; preds = %3
%34 = load i32, i32* %9
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.5, i64 0, i64 0), i32 %34)
%36 = call i32 @fflush(i32* null)
br label %37
37: ; preds = %33, %29, %22
%38 = load i32, i32* %8
store i32 %38, i32* @errno
%39 = load i32, i32* %7
ret i32 %39
}

LLVM IR (-O2):
@.str = [34 x i8] c"read(): fd=%d, buf=0x%p, len=%zu\0A\00"
@errno = global i32 0
@.str.1 = [18 x i8] c"\09\09Read %d blocks\0A\00"
@.str.2 = [12 x i8] c"\09\09ret = %d\0A\00"
@.str.4 = [53 x i8] c"\09Failed Phase 1: returned undefined value! ret = %d\0A\00"
@.str.5 = [43 x i8] c"Internal syscalltester error: passed = %d\0A\00"
@str = [19 x i8] c"\09Succeeded Phase 1\00"
define i32 @read_test(i32 %0, i8* %1, i64 %2) {
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i32 %0, i8* %1, i64 %2)
%5 = tail call i32 @fflush(i32* null)
%6 = tail call i32 @full_read(i32 %0, i8* %1, i64 %2)
%7 = tail call i32 @handle_gez(i32 %6)
%8 = load i32, i32* @errno
switch i32 %7, label %15 [
i32 -1, label %9
i32 0, label %9
i32 -2, label %13
]
9: ; preds = %3, %3
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i32 %6)
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32 %6)
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str, i64 0, i64 0))
br label %17
13: ; preds = %3
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([53 x i8], [53 x i8]* @.str.4, i64 0, i64 0), i32 %6)
br label %17
15: ; preds = %3
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @.str.5, i64 0, i64 0), i32 %7)
br label %17
17: ; preds = %15, %13, %9
%18 = tail call i32 @fflush(i32* null)
store i32 %8, i32* @errno
ret i32 %6
}