#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 uint8_t;
typedef int uint32_t;

/* Variables and functions */
int read(int, int *, int);
int read_le32(int fd, uint32_t *out) {
  uint32_t tmp = 0;
  uint8_t byte;
  int i, err;
  for (i = 0; i < 4; i++) {
    err = read(fd, &byte, 1);
    if (err <= 0)
      return err;
    tmp |= (byte << (i * 8));
  }
  *out = tmp;
  do {
  } while (0);
  return 4;
}


x86 assembly (clang, -O0):
<read_le32>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x4,-0x1c(%rbp)
jge    117f <read_le32+0x6f>
mov    -0x8(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0x1,%edx
call   1030 <read@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jg     1160 <read_le32+0x50>
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1194 <read_le32+0x84>
mov    -0x18(%rbp),%eax
mov    -0x1c(%rbp),%ecx
shl    $0x3,%ecx
shl    %cl,%eax
or     -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    112d <read_le32+0x1d>
mov    -0x14(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
jmp    118d <read_le32+0x7d>
movl   $0x4,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_le32>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r15
mov    %edi,%ebp
lea    0xc(%rsp),%rsi
mov    $0x1,%edx
call   1030 <read@plt>
test   %eax,%eax
jle    119f <read_le32+0x8f>
mov    0xc(%rsp),%r14d
lea    0xc(%rsp),%rsi
mov    %ebp,%edi
mov    $0x1,%edx
call   1030 <read@plt>
test   %eax,%eax
jle    119f <read_le32+0x8f>
mov    0xc(%rsp),%ebx
lea    0xc(%rsp),%rsi
mov    %ebp,%edi
mov    $0x1,%edx
call   1030 <read@plt>
test   %eax,%eax
jle    119f <read_le32+0x8f>
mov    0xc(%rsp),%r12d
lea    0xc(%rsp),%rsi
mov    %ebp,%edi
mov    $0x1,%edx
call   1030 <read@plt>
test   %eax,%eax
jle    119f <read_le32+0x8f>
shl    $0x10,%r12d
shl    $0x8,%ebx
or     %r14d,%ebx
mov    0xc(%rsp),%eax
shl    $0x18,%eax
or     %r12d,%eax
or     %ebx,%eax
mov    %eax,(%r15)
mov    $0x4,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @read_le32(i32 %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 %0, i32* %4
store i32* %1, i32** %5
store i32 0, i32* %6
store i32 0, i32* %8
br label %10
10: ; preds = %27, %2
%11 = load i32, i32* %8
%12 = icmp slt i32 %11, 4
br i1 %12, label %13, label %30
13: ; preds = %10
%14 = load i32, i32* %4
%15 = call i32 @read(i32 %14, i32* %7, i32 1)
store i32 %15, i32* %9
%16 = load i32, i32* %9
%17 = icmp sle i32 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %13
%19 = load i32, i32* %9
store i32 %19, i32* %3
br label %35
20: ; preds = %13
%21 = load i32, i32* %7
%22 = load i32, i32* %8
%23 = mul nsw i32 %22, 8
%24 = shl i32 %21, %23
%25 = load i32, i32* %6
%26 = or i32 %25, %24
store i32 %26, i32* %6
br label %27
27: ; preds = %20
%28 = load i32, i32* %8
%29 = add nsw i32 %28, 1
store i32 %29, i32* %8
br label %10
30: ; preds = %10
%31 = load i32, i32* %6
%32 = load i32*, i32** %5
store i32 %31, i32* %32
br label %33
33: ; preds = %30
br label %34
34: ; preds = %33
store i32 4, i32* %3
br label %35
35: ; preds = %34, %18
%36 = load i32, i32* %3
ret i32 %36
}

LLVM IR (-O2):
define i32 @read_le32(i32 %0, i32* nocapture writeonly %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = call i32 @read(i32 %0, i32* %3, i32 1)
%6 = icmp slt i32 %5, 1
br i1 %6, label %27, label %7
7: ; preds = %2
%8 = load i32, i32* %3
%9 = call i32 @read(i32 %0, i32* %3, i32 1)
%10 = icmp slt i32 %9, 1
br i1 %10, label %27, label %11
11: ; preds = %7
%12 = load i32, i32* %3
%13 = call i32 @read(i32 %0, i32* %3, i32 1)
%14 = icmp slt i32 %13, 1
br i1 %14, label %27, label %15
15: ; preds = %11
%16 = load i32, i32* %3
%17 = call i32 @read(i32 %0, i32* %3, i32 1)
%18 = icmp slt i32 %17, 1
br i1 %18, label %27, label %19
19: ; preds = %15
%20 = shl i32 %16, 16
%21 = shl i32 %12, 8
%22 = or i32 %21, %8
%23 = or i32 %20, %22
%24 = load i32, i32* %3
%25 = shl i32 %24, 24
%26 = or i32 %25, %23
store i32 %26, i32* %1
br label %27
27: ; preds = %2, %7, %11, %15, %19
%28 = phi i32 [ 4, %19 ], [ %5, %2 ], [ %9, %7 ], [ %13, %11 ], [ %17, %15 ]
ret i32 %28
}