#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 /*<<< orphan*/ read(int, char *, int);
int read_word(int fd) {
  int i, forExport = 0;
  char temp;
  for (i = 0; i < 4; i++) {
    read(fd, &temp, sizeof(char));
    forExport += ((int)(temp) << (i * 8));
  }
  return forExport;
}


x86 assembly (clang, -O0):
<read_word>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x8(%rbp)
cmpl   $0x4,-0x8(%rbp)
jge    1164 <read_word+0x54>
mov    -0x4(%rbp),%edi
lea    -0xd(%rbp),%rsi
mov    $0x1,%edx
call   1030 <read@plt>
movsbl -0xd(%rbp),%eax
mov    -0x8(%rbp),%ecx
shl    $0x3,%ecx
shl    %cl,%eax
add    -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1129 <read_word+0x19>
mov    -0xc(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_word>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %edi,%r12d
lea    0xf(%rsp),%r14
mov    %r14,%rsi
mov    $0x1,%edx
call   1030 <read@plt>
movsbl 0xf(%rsp),%r15d
mov    %r12d,%edi
mov    %r14,%rsi
mov    $0x1,%edx
call   1030 <read@plt>
movsbl 0xf(%rsp),%ebp
shl    $0x8,%ebp
add    %r15d,%ebp
mov    %r12d,%edi
mov    %r14,%rsi
mov    $0x1,%edx
call   1030 <read@plt>
movsbl 0xf(%rsp),%ebx
shl    $0x10,%ebx
add    %ebp,%ebx
mov    %r12d,%edi
mov    %r14,%rsi
mov    $0x1,%edx
call   1030 <read@plt>
movzbl 0xf(%rsp),%eax
shl    $0x18,%eax
add    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @read_word(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8
store i32 %0, i32* %2
store i32 0, i32* %4
store i32 0, i32* %3
br label %6
6: ; preds = %19, %1
%7 = load i32, i32* %3
%8 = icmp slt i32 %7, 4
br i1 %8, label %9, label %22
9: ; preds = %6
%10 = load i32, i32* %2
%11 = call i32 @read(i32 %10, i8* %5, i32 1)
%12 = load i8, i8* %5
%13 = sext i8 %12 to i32
%14 = load i32, i32* %3
%15 = mul nsw i32 %14, 8
%16 = shl i32 %13, %15
%17 = load i32, i32* %4
%18 = add nsw i32 %17, %16
store i32 %18, i32* %4
br label %19
19: ; preds = %9
%20 = load i32, i32* %3
%21 = add nsw i32 %20, 1
store i32 %21, i32* %3
br label %6
22: ; preds = %6
%23 = load i32, i32* %4
ret i32 %23
}

LLVM IR (-O2):
define i32 @read_word(i32 %0) {
%2 = alloca i8
%3 = call i32 @read(i32 %0, i8* %2, i32 1)
%4 = load i8, i8* %2
%5 = sext i8 %4 to i32
%6 = call i32 @read(i32 %0, i8* %2, i32 1)
%7 = load i8, i8* %2
%8 = sext i8 %7 to i32
%9 = shl nsw i32 %8, 8
%10 = add nsw i32 %9, %5
%11 = call i32 @read(i32 %0, i8* %2, i32 1)
%12 = load i8, i8* %2
%13 = sext i8 %12 to i32
%14 = shl nsw i32 %13, 16
%15 = add nsw i32 %14, %10
%16 = call i32 @read(i32 %0, i8* %2, i32 1)
%17 = load i8, i8* %2
%18 = sext i8 %17 to i32
%19 = shl nsw i32 %18, 24
%20 = add nsw i32 %19, %15
ret i32 %20
}