#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 *, ...);
int read(int /*<<< orphan*/, int /*<<< orphan*/ *, int);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int write(int, int /*<<< orphan*/ *, int);
void w_loop(int fd, char **argv, int nbytes) {
  uint32_t reg;
  while (nbytes >= sizeof(reg)) {
    if (read(0, &reg, sizeof(reg)) != sizeof(reg)) {
      fprintf(stderr, "%s: <stdin>: short read\n", argv[0]);
      exit(1);
    }
    if (write(fd, &reg, sizeof(reg)) != sizeof(reg)) {
      fprintf(stderr, "%s: write(%s): %s\n", argv[0], argv[1], strerror(errno));
      exit(1);
    }
    nbytes -= sizeof(reg);
  }
  exit(0);
}


x86 assembly (clang, -O0):
<w_loop>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movslq -0x14(%rbp),%rax
cmp    $0x4,%rax
jb     1238 <w_loop+0xe8>
xor    %edi,%edi
lea    -0x18(%rbp),%rsi
mov    $0x4,%edx
call   1040 <read@plt>
cltq
cmp    $0x4,%rax
je     11b4 <w_loop+0x64>
mov    0x2e4d(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe5d(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    -0x4(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0x4,%edx
call   1030 <write@plt>
cltq
cmp    $0x4,%rax
je     1228 <w_loop+0xd8>
mov    0x2e08(%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    0x2ddd(%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    0xe02(%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 <w_loop+0x12>
xor    %edi,%edi
call   1060 <exit@plt>

x86 assembly (clang, -O2):
<w_loop>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
cmp    $0x4,%edx
jb     11a1 <w_loop+0x51>
mov    %edx,%ebp
mov    %rsi,%r14
mov    %edi,%r15d
lea    0x4(%rsp),%rbx
nopl   0x0(%rax)
xor    %edi,%edi
mov    %rbx,%rsi
mov    $0x4,%edx
call   1040 <read@plt>
cmp    $0x4,%eax
jne    11a8 <w_loop+0x58>
mov    %r15d,%edi
mov    %rbx,%rsi
mov    $0x4,%edx
call   1030 <write@plt>
cmp    $0x4,%eax
jne    11cc <w_loop+0x7c>
add    $0xfffffffc,%ebp
cmp    $0x4,%ebp
jae    1170 <w_loop+0x20>
xor    %edi,%edi
call   1060 <exit@plt>
mov    0x2e31(%rip),%rax
mov    (%rax),%edi
mov    (%r14),%rdx
lea    0xe45(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    0x2e0d(%rip),%rax
mov    (%rax),%ebx
mov    (%r14),%rbp
mov    0x8(%r14),%r14
mov    0x2df5(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
lea    0xe28(%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>

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

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