#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 uint16_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_get16(int fd, off_t offset, uint16_t *value) {
  unsigned char b[2];
  if (lseek(fd, offset, SEEK_SET) == -1)
    return 1;
  if (read(fd, b, 2) != 2)
    return 1;
  *value = b[0] + (b[1] << 8);
  return 0;
}


x86 assembly (clang, -O0):
<pe_get16>:
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_get16+0x3b>
movl   $0x1,-0x4(%rbp)
jmp    119d <pe_get16+0x7d>
mov    -0x8(%rbp),%edi
lea    -0x1a(%rbp),%rsi
mov    $0x2,%edx
call   1040 <read@plt>
cmp    $0x2,%eax
je     1181 <pe_get16+0x61>
movl   $0x1,-0x4(%rbp)
jmp    119d <pe_get16+0x7d>
movzbl -0x1a(%rbp),%eax
movzbl -0x19(%rbp),%ecx
shl    $0x8,%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_get16>:
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_get16+0x44>
lea    0xe(%rsp),%rsi
mov    %ebx,%edi
mov    $0x2,%edx
call   1040 <read@plt>
cmp    $0x2,%eax
jne    1164 <pe_get16+0x44>
mov    0xe(%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_get16(i32 %0, i32 %1, i8* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca [2 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 %32
15: ; preds = %3
%16 = load i32, i32* %5
%17 = getelementptr inbounds [2 x i8], [2 x i8]* %8, i64 0, i64 0
%18 = call i32 @read(i32 %16, i8* %17, i32 2)
%19 = icmp ne i32 %18, 2
br i1 %19, label %20, label %21
20: ; preds = %15
store i32 1, i32* %4
br label %32
21: ; preds = %15
%22 = getelementptr inbounds [2 x i8], [2 x i8]* %8, i64 0, i64 0
%23 = load i8, i8* %22
%24 = zext i8 %23 to i32
%25 = getelementptr inbounds [2 x i8], [2 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 = trunc i32 %29 to i8
%31 = load i8*, i8** %7
store i8 %30, i8* %31
store i32 0, i32* %4
br label %32
32: ; preds = %21, %20, %14
%33 = load i32, i32* %4
ret i32 %33
}

LLVM IR (-O2):
@SEEK_SET = global i32 0
define i32 @pe_get16(i32 %0, i32 %1, i8* nocapture writeonly %2) {
%4 = alloca [2 x i8]
%5 = getelementptr inbounds [2 x i8], [2 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 2)
%11 = icmp eq i32 %10, 2
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
}