#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*/ opcode;
typedef int /*<<< orphan*/ __uint32_t;

/* Variables and functions */
int /*<<< orphan*/ STDIN_FILENO;
int /*<<< orphan*/ STDOUT_FILENO;
int /*<<< orphan*/ ntohl(int /*<<< orphan*/);
int read(int /*<<< orphan*/, int /*<<< orphan*/ *, int);
int /*<<< orphan*/ write(int /*<<< orphan*/, int /*<<< orphan*/ *, int);
int main(void) {
  __uint32_t opcode;
  int ret;
  while ((ret = read(STDIN_FILENO, &opcode, sizeof(opcode))) ==
         sizeof(opcode)) {
    opcode = ntohl(opcode);
    write(STDOUT_FILENO, &opcode, sizeof(opcode));
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e92(%rip),%rax
mov    (%rax),%edi
lea    -0x8(%rbp),%rsi
mov    $0x4,%edx
call   1040 <read@plt>
mov    %eax,-0xc(%rbp)
cltq
cmp    $0x4,%rax
jne    118c <main+0x5c>
mov    -0x8(%rbp),%edi
call   1050 <ntohl@plt>
mov    %eax,-0x8(%rbp)
mov    0x2e79(%rip),%rax
mov    (%rax),%edi
lea    -0x8(%rbp),%rsi
mov    $0x4,%edx
call   1030 <write@plt>
jmp    113f <main+0xf>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    0x2e98(%rip),%r14
mov    (%r14),%edi
lea    0xc(%rsp),%rsi
mov    $0x4,%edx
call   1040 <read@plt>
cmp    $0x4,%eax
jne    11a2 <main+0x72>
mov    0x2e92(%rip),%r15
lea    0xc(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    0xc(%rsp),%edi
call   1050 <ntohl@plt>
mov    %eax,0xc(%rsp)
mov    (%r15),%edi
mov    %rbx,%rsi
mov    $0x4,%edx
call   1030 <write@plt>
mov    (%r14),%edi
mov    %rbx,%rsi
mov    $0x4,%edx
call   1040 <read@plt>
cmp    $0x4,%eax
je     1170 <main+0x40>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@STDIN_FILENO = global i32 0
@STDOUT_FILENO = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
store i32 0, i32* %1
br label %4
4: ; preds = %9, %0
%5 = load i32, i32* @STDIN_FILENO
%6 = call i32 @read(i32 %5, i32* %2, i32 4)
store i32 %6, i32* %3
%7 = sext i32 %6 to i64
%8 = icmp eq i64 %7, 4
br i1 %8, label %9, label %14
9: ; preds = %4
%10 = load i32, i32* %2
%11 = call i32 @ntohl(i32 %10)
store i32 %11, i32* %2
%12 = load i32, i32* @STDOUT_FILENO
%13 = call i32 @write(i32 %12, i32* %2, i32 4)
br label %4
14: ; preds = %4
ret i32 0
}

LLVM IR (-O2):
@STDIN_FILENO = global i32 0
@STDOUT_FILENO = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = load i32, i32* @STDIN_FILENO
%4 = call i32 @read(i32 %3, i32* %1, i32 4)
%5 = icmp eq i32 %4, 4
br i1 %5, label %6, label %14
6: ; preds = %0, %6
%7 = load i32, i32* %1
%8 = tail call i32 @ntohl(i32 %7)
store i32 %8, i32* %1
%9 = load i32, i32* @STDOUT_FILENO
%10 = call i32 @write(i32 %9, i32* %1, i32 4)
%11 = load i32, i32* @STDIN_FILENO
%12 = call i32 @read(i32 %11, i32* %1, i32 4)
%13 = icmp eq i32 %12, 4
br i1 %13, label %6, label %14
14: ; preds = %6, %0
ret i32 0
}