#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;

/* Variables and functions */
int read(int, int **, int);
int read_int(int fd) {
  uint8_t bytes[4];
  int c = 0;
  int r;
  do {
    r = read(fd, &bytes, 4 - c);
    c += r;
  } while (c < 4);
  return (bytes[0] << 24 | bytes[1] << 16 | bytes[2] << 8 | bytes[3]);
}


x86 assembly (clang, -O0):
<read_int>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0x4,%edx
sub    -0x24(%rbp),%edx
call   1030 <read@plt>
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%eax
add    -0x24(%rbp),%eax
mov    %eax,-0x24(%rbp)
cmpl   $0x4,-0x24(%rbp)
jl     1122 <read_int+0x12>
mov    -0x20(%rbp),%eax
shl    $0x18,%eax
mov    -0x1c(%rbp),%ecx
shl    $0x10,%ecx
or     %ecx,%eax
mov    -0x18(%rbp),%ecx
shl    $0x8,%ecx
or     %ecx,%eax
or     -0x14(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_int>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebx
xor    %ebp,%ebp
mov    %rsp,%r14
nop
mov    $0x4,%edx
sub    %ebp,%edx
mov    %ebx,%edi
mov    %r14,%rsi
call   1030 <read@plt>
add    %eax,%ebp
cmp    $0x4,%ebp
jl     1120 <read_int+0x10>
mov    (%rsp),%eax
mov    0x4(%rsp),%ecx
shl    $0x18,%eax
shl    $0x10,%ecx
or     %eax,%ecx
mov    0x8(%rsp),%eax
shl    $0x8,%eax
or     %ecx,%eax
or     0xc(%rsp),%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @read_int(i32 %0) {
%2 = alloca i32
%3 = alloca [4 x i32]
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %2
store i32 0, i32* %4
br label %6
6: ; preds = %15, %1
%7 = load i32, i32* %2
%8 = bitcast [4 x i32]* %3 to i32**
%9 = load i32, i32* %4
%10 = sub nsw i32 4, %9
%11 = call i32 @read(i32 %7, i32** %8, i32 %10)
store i32 %11, i32* %5
%12 = load i32, i32* %5
%13 = load i32, i32* %4
%14 = add nsw i32 %13, %12
store i32 %14, i32* %4
br label %15
15: ; preds = %6
%16 = load i32, i32* %4
%17 = icmp slt i32 %16, 4
br i1 %17, label %6, label %18
18: ; preds = %15
%19 = getelementptr inbounds [4 x i32], [4 x i32]* %3, i64 0, i64 0
%20 = load i32, i32* %19
%21 = shl i32 %20, 24
%22 = getelementptr inbounds [4 x i32], [4 x i32]* %3, i64 0, i64 1
%23 = load i32, i32* %22
%24 = shl i32 %23, 16
%25 = or i32 %21, %24
%26 = getelementptr inbounds [4 x i32], [4 x i32]* %3, i64 0, i64 2
%27 = load i32, i32* %26
%28 = shl i32 %27, 8
%29 = or i32 %25, %28
%30 = getelementptr inbounds [4 x i32], [4 x i32]* %3, i64 0, i64 3
%31 = load i32, i32* %30
%32 = or i32 %29, %31
ret i32 %32
}

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