#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 fread(void *, int, int, int /*<<< orphan*/);
int little_endian(char *, int);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ stdin;
int main(void) {
  char buf[4];
  while (1) {
    int res = fread((void *)buf, 1, 4, stdin);
    if (res == 0) {
      break;
    }
    int v = little_endian(buf, res);
    printf("%d", v);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x8(%rbp),%rdi
mov    0x2e9e(%rip),%rax
mov    (%rax),%ecx
mov    $0x1,%esi
mov    $0x4,%edx
call   1030 <fread@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jne    116d <main+0x3d>
jmp    1190 <main+0x60>
lea    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1040 <little_endian@plt>
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%esi
lea    0xe7a(%rip),%rdi
call   1050 <printf@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    0x2ea8(%rip),%r15
mov    (%r15),%ecx
lea    0xc(%rsp),%rdi
mov    $0x1,%esi
mov    $0x4,%edx
call   1030 <fread@plt>
test   %eax,%eax
je     119d <main+0x6d>
lea    0xc(%rsp),%rbx
lea    0xe99(%rip),%r14
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %eax,%esi
call   1040 <little_endian@plt>
mov    %r14,%rdi
mov    %eax,%esi
call   1050 <printf@plt>
mov    (%r15),%ecx
mov    %rbx,%rdi
mov    $0x1,%esi
mov    $0x4,%edx
call   1030 <fread@plt>
test   %eax,%eax
jne    1170 <main+0x40>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@stdin = global i32 0
@.str = [3 x i8] c"%d\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [4 x i8]
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
br label %5
5: ; preds = %0, %12
%6 = getelementptr inbounds [4 x i8], [4 x i8]* %2, i64 0, i64 0
%7 = load i32, i32* @stdin
%8 = call i32 @fread(i8* %6, i32 1, i32 4, i32 %7)
store i32 %8, i32* %3
%9 = load i32, i32* %3
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %12
11: ; preds = %5
br label %18
12: ; preds = %5
%13 = getelementptr inbounds [4 x i8], [4 x i8]* %2, i64 0, i64 0
%14 = load i32, i32* %3
%15 = call i32 @little_endian(i8* %13, i32 %14)
store i32 %15, i32* %4
%16 = load i32, i32* %4
%17 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %16)
br label %5
18: ; preds = %11
ret i32 0
}

LLVM IR (-O2):
@stdin = global i32 0
@.str = [3 x i8] c"%d\00"
define i32 @main() {
%1 = alloca [4 x i8]
%2 = getelementptr inbounds [4 x i8], [4 x i8]* %1, i64 0, i64 0
%3 = load i32, i32* @stdin
%4 = call i32 @fread(i8* %2, i32 1, i32 4, i32 %3)
%5 = icmp eq i32 %4, 0
br i1 %5, label %13, label %6
6: ; preds = %0, %6
%7 = phi i32 [ %11, %6 ], [ %4, %0 ]
%8 = call i32 @little_endian(i8* %2, i32 %7)
%9 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %8)
%10 = load i32, i32* @stdin
%11 = call i32 @fread(i8* %2, i32 1, i32 4, i32 %10)
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %6
13: ; preds = %6, %0
ret i32 0
}