#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 /*<<< orphan*/ uint32_t;
typedef int /*<<< orphan*/ reg;

/* Variables and functions */
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, char *, ...);
int read(int, int /*<<< orphan*/ *, int);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int write(int, int /*<<< orphan*/ *, int);
void r_loop(int fd, char **argv, int nbytes) {
  uint32_t reg;
  while (nbytes >= sizeof(reg)) {
    if (read(fd, &reg, sizeof(reg)) != sizeof(reg)) {
      fprintf(stderr, "%s: read(%s): %s\n", argv[0], argv[1], strerror(errno));
      exit(1);
    }
    if (write(1, &reg, sizeof(reg)) != sizeof(reg)) {
      fprintf(stderr, "%s: <stdout>: %s\n", argv[0], strerror(errno));
      exit(1);
    }
    nbytes -= sizeof(reg);
  }
  exit(0);
}


x86 assembly (clang, -O0):
<r_loop>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movslq -0x14(%rbp),%rax
cmp    $0x4,%rax
jb     125a <r_loop+0x10a>
mov    -0x4(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0x4,%edx
call   1040 <read@plt>
cltq
cmp    $0x4,%rax
je     11e4 <r_loop+0x94>
mov    0x2e4c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    0x2e21(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    -0x2c(%rbp),%edi
mov    -0x28(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    %rax,%r8
lea    0xe2d(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    $0x1,%edi
lea    -0x18(%rbp),%rsi
mov    $0x4,%edx
call   1030 <write@plt>
cltq
cmp    $0x4,%rax
je     124a <r_loop+0xfa>
mov    0x2dd6(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x38(%rbp)
mov    0x2db7(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    -0x3c(%rbp),%edi
mov    -0x38(%rbp),%rdx
mov    %rax,%rcx
lea    0xdd9(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
movslq -0x14(%rbp),%rax
sub    $0x4,%rax
mov    %eax,-0x14(%rbp)
jmp    1162 <r_loop+0x12>
xor    %edi,%edi
call   1060 <exit@plt>

x86 assembly (clang, -O2):
<r_loop>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
cmp    $0x4,%edx
jb     11a4 <r_loop+0x54>
mov    %edx,%ebp
mov    %rsi,%r14
mov    %edi,%r15d
lea    0x4(%rsp),%rbx
nopl   0x0(%rax)
mov    %r15d,%edi
mov    %rbx,%rsi
mov    $0x4,%edx
call   1040 <read@plt>
cmp    $0x4,%eax
jne    11ab <r_loop+0x5b>
mov    $0x1,%edi
mov    %rbx,%rsi
mov    $0x4,%edx
call   1030 <write@plt>
cmp    $0x4,%eax
jne    11ec <r_loop+0x9c>
add    $0xfffffffc,%ebp
cmp    $0x4,%ebp
jae    1170 <r_loop+0x20>
xor    %edi,%edi
call   1060 <exit@plt>
mov    0x2e2e(%rip),%rax
mov    (%rax),%ebx
mov    (%r14),%rbp
mov    0x8(%r14),%r14
mov    0x2e16(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
lea    0xe30(%rip),%rsi
mov    %ebx,%edi
mov    %rbp,%rdx
mov    %r14,%rcx
mov    %rax,%r8
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    0x2ded(%rip),%rax
mov    (%rax),%ebx
mov    (%r14),%rbp
mov    0x2dd9(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
lea    0xe05(%rip),%rsi
mov    %ebx,%edi
mov    %rbp,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [18 x i8] c"%s: read(%s): %s\0A\00"
@errno = global i32 0
@.str.1 = [18 x i8] c"%s: <stdout>: %s\0A\00"
define void @r_loop(i32 %0, i8** %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 %2, i32* %6
br label %8
8: ; preds = %42, %3
%9 = load i32, i32* %6
%10 = sext i32 %9 to i64
%11 = icmp uge i64 %10, 4
br i1 %11, label %12, label %47
12: ; preds = %8
%13 = load i32, i32* %4
%14 = call i32 @read(i32 %13, i32* %7, i32 4)
%15 = sext i32 %14 to i64
%16 = icmp ne i64 %15, 4
br i1 %16, label %17, label %29
17: ; preds = %12
%18 = load i32, i32* @stderr
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 0
%21 = load i8*, i8** %20
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 1
%24 = load i8*, i8** %23
%25 = load i32, i32* @errno
%26 = call i8* @strerror(i32 %25)
%27 = call i32 (i32, i8*, i8*, i8*, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %21, i8* %24, i8* %26)
%28 = call i32 @exit(i32 1)
unreachable
29: ; preds = %12
%30 = call i32 @write(i32 1, i32* %7, i32 4)
%31 = sext i32 %30 to i64
%32 = icmp ne i64 %31, 4
br i1 %32, label %33, label %42
33: ; preds = %29
%34 = load i32, i32* @stderr
%35 = load i8**, i8*** %5
%36 = getelementptr inbounds i8*, i8** %35, i64 0
%37 = load i8*, i8** %36
%38 = load i32, i32* @errno
%39 = call i8* @strerror(i32 %38)
%40 = call i32 (i32, i8*, i8*, i8*, ...) @fprintf(i32 %34, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %37, i8* %39)
%41 = call i32 @exit(i32 1)
unreachable
42: ; preds = %29
%43 = load i32, i32* %6
%44 = sext i32 %43 to i64
%45 = sub i64 %44, 4
%46 = trunc i64 %45 to i32
store i32 %46, i32* %6
br label %8
47: ; preds = %8
%48 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [18 x i8] c"%s: read(%s): %s\0A\00"
@errno = global i32 0
@.str.1 = [18 x i8] c"%s: <stdout>: %s\0A\00"
define void @r_loop(i32 %0, i8** nocapture %1, i32 %2) {
%4 = alloca i32
%5 = bitcast i32* %4 to i8*
%6 = icmp ugt i32 %2, 3
br i1 %6, label %9, label %33
7: ; preds = %22
%8 = icmp ugt i32 %25, 3
br i1 %8, label %9, label %33
9: ; preds = %3, %7
%10 = phi i32 [ %25, %7 ], [ %2, %3 ]
%11 = call i32 @read(i32 %0, i32* %4, i32 4)
%12 = icmp eq i32 %11, 4
br i1 %12, label %22, label %13
13: ; preds = %9
%14 = load i32, i32* @stderr
%15 = load i8*, i8** %1
%16 = getelementptr inbounds i8*, i8** %1, i64 1
%17 = load i8*, i8** %16
%18 = load i32, i32* @errno
%19 = tail call i8* @strerror(i32 %18)
%20 = tail call i32 (i32, i8*, i8*, i8*, ...) @fprintf(i32 %14, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %15, i8* %17, i8* %19)
%21 = tail call i32 @exit(i32 1)
unreachable
22: ; preds = %9
%23 = call i32 @write(i32 1, i32* %4, i32 4)
%24 = icmp eq i32 %23, 4
%25 = add i32 %10, -4
br i1 %24, label %7, label %26
26: ; preds = %22
%27 = load i32, i32* @stderr
%28 = load i8*, i8** %1
%29 = load i32, i32* @errno
%30 = tail call i8* @strerror(i32 %29)
%31 = tail call i32 (i32, i8*, i8*, i8*, ...) @fprintf(i32 %27, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %28, i8* %30)
%32 = tail call i32 @exit(i32 1)
unreachable
33: ; preds = %7, %3
%34 = tail call i32 @exit(i32 0)
unreachable
}