#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 /*<<< orphan*/ uint8_t;

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ err(int /*<<< orphan*/, char *, int, ...);
int lseek(int, int, int /*<<< orphan*/);
int write(int, int /*<<< orphan*/ *, int);
void write_ec_val(int fd, int byte_offset, uint8_t value) {
  int error;
  error = lseek(fd, byte_offset, SEEK_SET);
  if (error != byte_offset)
    err(EXIT_FAILURE, "Cannot set offset to 0x%.2x", byte_offset);
  error = write(fd, &value, 1);
  if (error != 1)
    err(EXIT_FAILURE, "Cannot write value 0x%.2x to offset 0x%.2x", value,
        byte_offset);
}


x86 assembly (clang, -O0):
<write_ec_val>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    0x2e92(%rip),%rax
mov    (%rax),%edx
call   1040 <lseek@plt>
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x8(%rbp),%eax
je     117e <write_ec_val+0x4e>
mov    0x2e6d(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%edx
lea    0xe89(%rip),%rsi
mov    $0x0,%al
call   1050 <err@plt>
mov    -0x4(%rbp),%edi
lea    -0xc(%rbp),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x1,-0x10(%rbp)
je     11b9 <write_ec_val+0x89>
mov    0x2e35(%rip),%rax
mov    (%rax),%edi
mov    -0xc(%rbp),%edx
mov    -0x8(%rbp),%ecx
lea    0xe6a(%rip),%rsi
mov    $0x0,%al
call   1050 <err@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_ec_val>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %edx,%r14d
mov    %esi,%ebx
mov    %edi,%ebp
mov    %edx,0xc(%rsp)
mov    0x2e96(%rip),%rax
mov    (%rax),%edx
call   1040 <lseek@plt>
cmp    %ebx,%eax
je     116e <write_ec_val+0x3e>
mov    0x2e7c(%rip),%rax
mov    (%rax),%edi
lea    0xe9b(%rip),%rsi
mov    %ebx,%edx
xor    %eax,%eax
call   1050 <err@plt>
lea    0xc(%rsp),%rsi
mov    %ebp,%edi
mov    $0x1,%edx
call   1030 <write@plt>
cmp    $0x1,%eax
jne    118d <write_ec_val+0x5d>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    0x2e44(%rip),%rax
mov    (%rax),%edi
lea    0xe7f(%rip),%rsi
mov    %r14d,%edx
mov    %ebx,%ecx
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
jmp    1050 <err@plt>

LLVM IR (-O0):
@SEEK_SET = global i32 0
@EXIT_FAILURE = global i32 0
@.str = [28 x i8] c"Cannot set offset to 0x%.2x\00"
@.str.1 = [43 x i8] c"Cannot write value 0x%.2x to offset 0x%.2x\00"
define void @write_ec_val(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%8 = load i32, i32* %4
%9 = load i32, i32* %5
%10 = load i32, i32* @SEEK_SET
%11 = call i32 @lseek(i32 %8, i32 %9, i32 %10)
store i32 %11, i32* %7
%12 = load i32, i32* %7
%13 = load i32, i32* %5
%14 = icmp ne i32 %12, %13
br i1 %14, label %15, label %19
15: ; preds = %3
%16 = load i32, i32* @EXIT_FAILURE
%17 = load i32, i32* %5
%18 = call i32 (i32, i8*, i32, ...) @err(i32 %16, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i32 %17)
br label %19
19: ; preds = %15, %3
%20 = load i32, i32* %4
%21 = call i32 @write(i32 %20, i32* %6, i32 1)
store i32 %21, i32* %7
%22 = load i32, i32* %7
%23 = icmp ne i32 %22, 1
br i1 %23, label %24, label %29
24: ; preds = %19
%25 = load i32, i32* @EXIT_FAILURE
%26 = load i32, i32* %6
%27 = load i32, i32* %5
%28 = call i32 (i32, i8*, i32, ...) @err(i32 %25, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.1, i64 0, i64 0), i32 %26, i32 %27)
br label %29
29: ; preds = %24, %19
ret void
}

LLVM IR (-O2):
@SEEK_SET = global i32 0
@EXIT_FAILURE = global i32 0
@.str = [28 x i8] c"Cannot set offset to 0x%.2x\00"
@.str.1 = [43 x i8] c"Cannot write value 0x%.2x to offset 0x%.2x\00"
define void @write_ec_val(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
store i32 %2, i32* %4
%5 = load i32, i32* @SEEK_SET
%6 = tail call i32 @lseek(i32 %0, i32 %1, i32 %5)
%7 = icmp eq i32 %6, %1
br i1 %7, label %11, label %8
8: ; preds = %3
%9 = load i32, i32* @EXIT_FAILURE
%10 = tail call i32 (i32, i8*, i32, ...) @err(i32 %9, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i32 %1)
br label %11
11: ; preds = %8, %3
%12 = call i32 @write(i32 %0, i32* %4, i32 1)
%13 = icmp eq i32 %12, 1
br i1 %13, label %17, label %14
14: ; preds = %11
%15 = load i32, i32* @EXIT_FAILURE
%16 = tail call i32 (i32, i8*, i32, ...) @err(i32 %15, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.1, i64 0, i64 0), i32 %2, i32 %1)
br label %17
17: ; preds = %14, %11
ret void
}