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

/* Variables and functions */
int /*<<< orphan*/ SEEK_SET;
int lseek(int, int /*<<< orphan*/, int /*<<< orphan*/);
int write(int, unsigned char *, int);
int pe_set16(int fd, off_t offset, uint16_t value) {
  unsigned char b[2];
  b[0] = (unsigned char)(value & 0x00ff);
  b[1] = (unsigned char)((value >> 8) & 0x00ff);
  if (lseek(fd, offset, SEEK_SET) == -1)
    return 1;
  if (write(fd, b, 2) != 2)
    return 1;
  return 0;
}


x86 assembly (clang, -O0):
<pe_set16>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0x10(%rbp),%eax
and    $0xff,%eax
mov    %al,-0x12(%rbp)
mov    -0x10(%rbp),%eax
sar    $0x8,%eax
and    $0xff,%eax
mov    %al,-0x11(%rbp)
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
mov    0x2e89(%rip),%rax
mov    (%rax),%edx
call   1040 <lseek@plt>
cmp    $0xffffffff,%eax
jne    1173 <pe_set16+0x53>
movl   $0x1,-0x4(%rbp)
jmp    11a0 <pe_set16+0x80>
mov    -0x8(%rbp),%edi
lea    -0x12(%rbp),%rsi
mov    $0x2,%edx
call   1030 <write@plt>
cmp    $0x2,%eax
je     1199 <pe_set16+0x79>
movl   $0x1,-0x4(%rbp)
jmp    11a0 <pe_set16+0x80>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pe_set16>:
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebx
mov    %dx,0xe(%rsp)
mov    0x2ead(%rip),%rax
mov    (%rax),%edx
call   1040 <lseek@plt>
cmp    $0xffffffff,%eax
je     115c <pe_set16+0x3c>
lea    0xe(%rsp),%rsi
mov    %ebx,%edi
mov    $0x2,%edx
call   1030 <write@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x2,%ecx
setne  %al
jmp    1161 <pe_set16+0x41>
mov    $0x1,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@SEEK_SET = global i32 0
define i32 @pe_set16(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca [2 x i8]
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32 %2, i32* %7
%9 = load i32, i32* %7
%10 = and i32 %9, 255
%11 = trunc i32 %10 to i8
%12 = getelementptr inbounds [2 x i8], [2 x i8]* %8, i64 0, i64 0
store i8 %11, i8* %12
%13 = load i32, i32* %7
%14 = ashr i32 %13, 8
%15 = and i32 %14, 255
%16 = trunc i32 %15 to i8
%17 = getelementptr inbounds [2 x i8], [2 x i8]* %8, i64 0, i64 1
store i8 %16, i8* %17
%18 = load i32, i32* %5
%19 = load i32, i32* %6
%20 = load i32, i32* @SEEK_SET
%21 = call i32 @lseek(i32 %18, i32 %19, i32 %20)
%22 = icmp eq i32 %21, -1
br i1 %22, label %23, label %24
23: ; preds = %3
store i32 1, i32* %4
br label %31
24: ; preds = %3
%25 = load i32, i32* %5
%26 = getelementptr inbounds [2 x i8], [2 x i8]* %8, i64 0, i64 0
%27 = call i32 @write(i32 %25, i8* %26, i32 2)
%28 = icmp ne i32 %27, 2
br i1 %28, label %29, label %30
29: ; preds = %24
store i32 1, i32* %4
br label %31
30: ; preds = %24
store i32 0, i32* %4
br label %31
31: ; preds = %30, %29, %23
%32 = load i32, i32* %4
ret i32 %32
}

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