#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 unsigned char uint32_t;
typedef int /*<<< orphan*/ off_t;

/* Variables and functions */
int /*<<< orphan*/ SEEK_SET;
int lseek(int, int /*<<< orphan*/, int /*<<< orphan*/);
int read(int, unsigned char *, int);
int pe_get32(int fd, off_t offset, uint32_t *value) {
  unsigned char b[4];
  if (lseek(fd, offset, SEEK_SET) == -1)
    return 1;
  if (read(fd, b, 4) != 4)
    return 1;
  *value = b[0] + (b[1] << 8) + (b[2] << 16) + (b[3] << 24);
  return 0;
}


x86 assembly (clang, -O0):
<pe_get32>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
mov    0x2ea1(%rip),%rax
mov    (%rax),%edx
call   1030 <lseek@plt>
cmp    $0xffffffff,%eax
jne    115b <pe_get32+0x3b>
movl   $0x1,-0x4(%rbp)
jmp    11af <pe_get32+0x8f>
mov    -0x8(%rbp),%edi
lea    -0x1c(%rbp),%rsi
mov    $0x4,%edx
call   1040 <read@plt>
cmp    $0x4,%eax
je     1181 <pe_get32+0x61>
movl   $0x1,-0x4(%rbp)
jmp    11af <pe_get32+0x8f>
movzbl -0x1c(%rbp),%eax
movzbl -0x1b(%rbp),%ecx
shl    $0x8,%ecx
add    %ecx,%eax
movzbl -0x1a(%rbp),%ecx
shl    $0x10,%ecx
add    %ecx,%eax
movzbl -0x19(%rbp),%ecx
shl    $0x18,%ecx
add    %ecx,%eax
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %cl,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pe_get32>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdx,%r14
mov    %edi,%ebx
mov    0x2eac(%rip),%rax
mov    (%rax),%edx
call   1030 <lseek@plt>
mov    $0x1,%ebp
cmp    $0xffffffff,%eax
je     1164 <pe_get32+0x44>
lea    0xc(%rsp),%rsi
mov    %ebx,%edi
mov    $0x4,%edx
call   1040 <read@plt>
cmp    $0x4,%eax
jne    1164 <pe_get32+0x44>
mov    0xc(%rsp),%al
mov    %al,(%r14)
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@SEEK_SET = global i32 0
define i32 @pe_get32(i32 %0, i32 %1, i8* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca [4 x i8]
store i32 %0, i32* %5
store i32 %1, i32* %6
store i8* %2, i8** %7
%9 = load i32, i32* %5
%10 = load i32, i32* %6
%11 = load i32, i32* @SEEK_SET
%12 = call i32 @lseek(i32 %9, i32 %10, i32 %11)
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %15
14: ; preds = %3
store i32 1, i32* %4
br label %42
15: ; preds = %3
%16 = load i32, i32* %5
%17 = getelementptr inbounds [4 x i8], [4 x i8]* %8, i64 0, i64 0
%18 = call i32 @read(i32 %16, i8* %17, i32 4)
%19 = icmp ne i32 %18, 4
br i1 %19, label %20, label %21
20: ; preds = %15
store i32 1, i32* %4
br label %42
21: ; preds = %15
%22 = getelementptr inbounds [4 x i8], [4 x i8]* %8, i64 0, i64 0
%23 = load i8, i8* %22
%24 = zext i8 %23 to i32
%25 = getelementptr inbounds [4 x i8], [4 x i8]* %8, i64 0, i64 1
%26 = load i8, i8* %25
%27 = zext i8 %26 to i32
%28 = shl i32 %27, 8
%29 = add nsw i32 %24, %28
%30 = getelementptr inbounds [4 x i8], [4 x i8]* %8, i64 0, i64 2
%31 = load i8, i8* %30
%32 = zext i8 %31 to i32
%33 = shl i32 %32, 16
%34 = add nsw i32 %29, %33
%35 = getelementptr inbounds [4 x i8], [4 x i8]* %8, i64 0, i64 3
%36 = load i8, i8* %35
%37 = zext i8 %36 to i32
%38 = shl i32 %37, 24
%39 = add nsw i32 %34, %38
%40 = trunc i32 %39 to i8
%41 = load i8*, i8** %7
store i8 %40, i8* %41
store i32 0, i32* %4
br label %42
42: ; preds = %21, %20, %14
%43 = load i32, i32* %4
ret i32 %43
}

LLVM IR (-O2):
@SEEK_SET = global i32 0
define i32 @pe_get32(i32 %0, i32 %1, i8* nocapture writeonly %2) {
%4 = alloca [4 x i8]
%5 = getelementptr inbounds [4 x i8], [4 x i8]* %4, i64 0, i64 0
%6 = load i32, i32* @SEEK_SET
%7 = tail call i32 @lseek(i32 %0, i32 %1, i32 %6)
%8 = icmp eq i32 %7, -1
br i1 %8, label %14, label %9
9: ; preds = %3
%10 = call i32 @read(i32 %0, i8* %5, i32 4)
%11 = icmp eq i32 %10, 4
br i1 %11, label %12, label %14
12: ; preds = %9
%13 = load i8, i8* %5
store i8 %13, i8* %2
br label %14
14: ; preds = %9, %3, %12
%15 = phi i32 [ 0, %12 ], [ 1, %3 ], [ 1, %9 ]
ret i32 %15
}