#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*/ SEEK_SET;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
scalar_t__ lseek(int, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int write(int, char *, int);
void _write_value(int fd, int val) {
  char c = val ? '1' : '0';
  if (lseek(fd, 0, SEEK_SET) < 0) {
    perror("lseek");
    exit(0);
  }
  if (write(fd, &c, 1) != 1) {
    perror("write");
    exit(0);
  }
}


x86 assembly (clang, -O0):
<_write_value>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x8(%rbp),%edx
mov    $0x30,%eax
mov    $0x31,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
mov    %al,-0x9(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e72(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1040 <lseek@plt>
cmp    $0x0,%rax
jge    1194 <_write_value+0x54>
lea    0xe78(%rip),%rdi
call   1050 <perror@plt>
xor    %edi,%edi
call   1060 <exit@plt>
mov    -0x4(%rbp),%edi
lea    -0x9(%rbp),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
cmp    $0x1,%eax
je     11c1 <_write_value+0x81>
lea    0xe51(%rip),%rdi
call   1050 <perror@plt>
xor    %edi,%edi
call   1060 <exit@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_write_value>:
push   %rbx
sub    $0x10,%rsp
cmp    $0x1,%esi
mov    $0x31,%al
sbb    $0x0,%al
mov    %edi,%ebx
mov    %al,0xf(%rsp)
mov    0x2e87(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1040 <lseek@plt>
test   %rax,%rax
js     1183 <_write_value+0x43>
lea    0xf(%rsp),%rsi
mov    %ebx,%edi
mov    $0x1,%edx
call   1030 <write@plt>
cmp    $0x1,%eax
jne    118c <_write_value+0x4c>
add    $0x10,%rsp
pop    %rbx
ret
lea    0xe76(%rip),%rdi
jmp    1193 <_write_value+0x53>
lea    0xe73(%rip),%rdi
call   1050 <perror@plt>
xor    %edi,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@SEEK_SET = global i32 0
@.str = [6 x i8] c"lseek\00"
@.str.1 = [6 x i8] c"write\00"
define void @_write_value(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8
store i32 %0, i32* %3
store i32 %1, i32* %4
%6 = load i32, i32* %4
%7 = icmp ne i32 %6, 0
%8 = zext i1 %7 to i64
%9 = select i1 %7, i32 49, i32 48
%10 = trunc i32 %9 to i8
store i8 %10, i8* %5
%11 = load i32, i32* %3
%12 = load i32, i32* @SEEK_SET
%13 = call i64 @lseek(i32 %11, i32 0, i32 %12)
%14 = icmp slt i64 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %2
%16 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%17 = call i32 @exit(i32 0)
unreachable
18: ; preds = %2
%19 = load i32, i32* %3
%20 = call i32 @write(i32 %19, i8* %5, i32 1)
%21 = icmp ne i32 %20, 1
br i1 %21, label %22, label %25
22: ; preds = %18
%23 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%24 = call i32 @exit(i32 0)
unreachable
25: ; preds = %18
ret void
}

LLVM IR (-O2):
@SEEK_SET = global i32 0
@.str = [6 x i8] c"lseek\00"
@.str.1 = [6 x i8] c"write\00"
define void @_write_value(i32 %0, i32 %1) {
%3 = alloca i8
%4 = icmp eq i32 %1, 0
%5 = select i1 %4, i8 48, i8 49
store i8 %5, i8* %3
%6 = load i32, i32* @SEEK_SET
%7 = tail call i64 @lseek(i32 %0, i32 0, i32 %6)
%8 = icmp slt i64 %7, 0
br i1 %8, label %9, label %12
9: ; preds = %2
%10 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%11 = tail call i32 @exit(i32 0)
unreachable
12: ; preds = %2
%13 = call i32 @write(i32 %0, i8* %3, i32 1)
%14 = icmp eq i32 %13, 1
br i1 %14, label %18, label %15
15: ; preds = %12
%16 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%17 = tail call i32 @exit(i32 0)
unreachable
18: ; preds = %12
ret void
}