#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*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ perror(char *);
int read(int, char *, int);
int /*<<< orphan*/ stderr;
int force_read(char *b, int fd, int s) {
  int r = 0;
  while (r < s) {
    int t = read(fd, b, s - r);
    if (t == -1) {
      perror("wut file error");
      exit(1);
    } else if (t == 0) {
      fprintf(stderr, "wut %d\n", r);
      exit(1);
    }
    r += t;
  }
  return r;
}


x86 assembly (clang, -O0):
<force_read>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    11d9 <force_read+0x99>
mov    -0xc(%rbp),%edi
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%edx
sub    -0x14(%rbp),%edx
call   1030 <read@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    119a <force_read+0x5a>
lea    0xe75(%rip),%rdi
call   1050 <perror@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
cmpl   $0x0,-0x18(%rbp)
jne    11c6 <force_read+0x86>
mov    0x2e35(%rip),%rax
mov    (%rax),%edi
mov    -0x14(%rbp),%edx
lea    0xe58(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
jmp    11cb <force_read+0x8b>
mov    -0x18(%rbp),%eax
add    -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
jmp    1159 <force_read+0x19>
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<force_read>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
test   %edx,%edx
jle    1180 <force_read+0x40>
mov    %edx,%ebp
mov    %esi,%r14d
mov    %rdi,%r15
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nop
mov    %ebp,%edx
sub    %ebx,%edx
mov    %r14d,%edi
mov    %r15,%rsi
call   1030 <read@plt>
test   %eax,%eax
je     118f <force_read+0x4f>
cmp    $0xffffffff,%eax
je     11b0 <force_read+0x70>
add    %eax,%ebx
cmp    %ebp,%ebx
jl     1160 <force_read+0x20>
jmp    1182 <force_read+0x42>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2e4a(%rip),%rax
mov    (%rax),%edi
lea    0xe70(%rip),%rsi
mov    %ebx,%edx
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
lea    0xe49(%rip),%rdi
call   1050 <perror@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [15 x i8] c"wut file error\00"
@stderr = global i32 0
@.str.1 = [8 x i8] c"wut %d\0A\00"
define i32 @force_read(i8* %0, i32 %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
store i32 0, i32* %7
br label %9
9: ; preds = %34, %3
%10 = load i32, i32* %7
%11 = load i32, i32* %6
%12 = icmp slt i32 %10, %11
br i1 %12, label %13, label %38
13: ; preds = %9
%14 = load i32, i32* %5
%15 = load i8*, i8** %4
%16 = load i32, i32* %6
%17 = load i32, i32* %7
%18 = sub nsw i32 %16, %17
%19 = call i32 @read(i32 %14, i8* %15, i32 %18)
store i32 %19, i32* %8
%20 = load i32, i32* %8
%21 = icmp eq i32 %20, -1
br i1 %21, label %22, label %25
22: ; preds = %13
%23 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%24 = call i32 @exit(i32 1)
unreachable
25: ; preds = %13
%26 = load i32, i32* %8
%27 = icmp eq i32 %26, 0
br i1 %27, label %28, label %33
28: ; preds = %25
%29 = load i32, i32* @stderr
%30 = load i32, i32* %7
%31 = call i32 @fprintf(i32 %29, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 %30)
%32 = call i32 @exit(i32 1)
unreachable
33: ; preds = %25
br label %34
34: ; preds = %33
%35 = load i32, i32* %8
%36 = load i32, i32* %7
%37 = add nsw i32 %36, %35
store i32 %37, i32* %7
br label %9
38: ; preds = %9
%39 = load i32, i32* %7
ret i32 %39
}

LLVM IR (-O2):
@.str = [15 x i8] c"wut file error\00"
@stderr = global i32 0
@.str.1 = [8 x i8] c"wut %d\0A\00"
define i32 @force_read(i8* nocapture %0, i32 %1, i32 %2) {
%4 = icmp sgt i32 %2, 0
br i1 %4, label %5, label %19
5: ; preds = %3, %16
%6 = phi i32 [ %17, %16 ], [ 0, %3 ]
%7 = sub nsw i32 %2, %6
%8 = tail call i32 @read(i32 %1, i8* %0, i32 %7)
switch i32 %8, label %16 [
i32 -1, label %9
i32 0, label %12
]
9: ; preds = %5
%10 = tail call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%11 = tail call i32 @exit(i32 1)
unreachable
12: ; preds = %5
%13 = load i32, i32* @stderr
%14 = tail call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 %6)
%15 = tail call i32 @exit(i32 1)
unreachable
16: ; preds = %5
%17 = add nsw i32 %8, %6
%18 = icmp slt i32 %17, %2
br i1 %18, label %5, label %19
19: ; preds = %16, %3
%20 = phi i32 [ 0, %3 ], [ %17, %16 ]
ret i32 %20
}