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

/* Variables and functions */
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, unsigned char,
                         int /*<<< orphan*/);
int /*<<< orphan*/ fwrite(unsigned char *, int, int, int /*<<< orphan*/ *);
unsigned char read8(int /*<<< orphan*/ *, unsigned char);
void write1(FILE *f, unsigned char offset, unsigned char bit,
            const unsigned char value) {
  unsigned char c = read8(f, offset);
  fseek(f, offset, SEEK_SET);
  if (value > 0) {
    c |= (1 << bit);
  } else {
    c &= ~(1 << bit);
  }
  fwrite(&c, sizeof(unsigned char), 1, f);
}


x86 assembly (clang, -O0):
<write1>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %cl,%al
mov    %dl,%cl
mov    %sil,%dl
mov    %rdi,-0x8(%rbp)
mov    %dl,-0x9(%rbp)
mov    %cl,-0xa(%rbp)
mov    %al,-0xb(%rbp)
mov    -0x8(%rbp),%rdi
movzbl -0x9(%rbp),%esi
call   1030 <read8@plt>
mov    %al,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x9(%rbp),%al
mov    0x2e76(%rip),%rcx
mov    (%rcx),%edx
movzbl %al,%esi
call   1040 <fseek@plt>
movzbl -0xb(%rbp),%eax
cmp    $0x0,%eax
jle    119c <write1+0x6c>
movzbl -0xa(%rbp),%ecx
mov    $0x1,%eax
shl    %cl,%eax
mov    %eax,%ecx
movzbl -0xc(%rbp),%eax
or     %ecx,%eax
mov    %al,-0xc(%rbp)
jmp    11b5 <write1+0x85>
movzbl -0xa(%rbp),%ecx
mov    $0x1,%eax
shl    %cl,%eax
mov    %eax,%ecx
xor    $0xffffffff,%ecx
movzbl -0xc(%rbp),%eax
and    %ecx,%eax
mov    %al,-0xc(%rbp)
mov    -0x8(%rbp),%rcx
lea    -0xc(%rbp),%rdi
mov    $0x1,%edx
mov    %edx,%esi
call   1050 <fwrite@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write1>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %ecx,%r14d
mov    %edx,%r15d
mov    %esi,%ebp
mov    %rdi,%r12
call   1030 <read8@plt>
mov    %eax,%ebx
mov    0x2e8f(%rip),%rax
mov    (%rax),%edx
mov    %r12,%rdi
mov    %ebp,%esi
call   1050 <fseek@plt>
mov    $0x1,%eax
mov    %r15d,%ecx
shl    %cl,%eax
mov    %eax,%ecx
not    %cl
and    %bl,%cl
or     %al,%bl
test   %r14d,%r14d
movzbl %bl,%eax
movzbl %cl,%ecx
cmovne %eax,%ecx
movsbl %cl,%edi
mov    %r12,%rsi
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <fputc@plt>

LLVM IR (-O0):
@SEEK_SET = global i32 0
define void @write1(i32* %0, i8 zeroext %1, i8 zeroext %2, i8 zeroext %3) {
%5 = alloca i32*
%6 = alloca i8
%7 = alloca i8
%8 = alloca i8
%9 = alloca i8
store i32* %0, i32** %5
store i8 %1, i8* %6
store i8 %2, i8* %7
store i8 %3, i8* %8
%10 = load i32*, i32** %5
%11 = load i8, i8* %6
%12 = call zeroext i8 @read8(i32* %10, i8 zeroext %11)
store i8 %12, i8* %9
%13 = load i32*, i32** %5
%14 = load i8, i8* %6
%15 = load i32, i32* @SEEK_SET
%16 = call i32 @fseek(i32* %13, i8 zeroext %14, i32 %15)
%17 = load i8, i8* %8
%18 = zext i8 %17 to i32
%19 = icmp sgt i32 %18, 0
br i1 %19, label %20, label %28
20: ; preds = %4
%21 = load i8, i8* %7
%22 = zext i8 %21 to i32
%23 = shl i32 1, %22
%24 = load i8, i8* %9
%25 = zext i8 %24 to i32
%26 = or i32 %25, %23
%27 = trunc i32 %26 to i8
store i8 %27, i8* %9
br label %37
28: ; preds = %4
%29 = load i8, i8* %7
%30 = zext i8 %29 to i32
%31 = shl i32 1, %30
%32 = xor i32 %31, -1
%33 = load i8, i8* %9
%34 = zext i8 %33 to i32
%35 = and i32 %34, %32
%36 = trunc i32 %35 to i8
store i8 %36, i8* %9
br label %37
37: ; preds = %28, %20
%38 = load i32*, i32** %5
%39 = call i32 @fwrite(i8* %9, i32 1, i32 1, i32* %38)
ret void
}

LLVM IR (-O2):
@SEEK_SET = global i32 0
define void @write1(i32* %0, i8 zeroext %1, i8 zeroext %2, i8 zeroext %3) {
%5 = tail call zeroext i8 @read8(i32* %0, i8 zeroext %1)
%6 = load i32, i32* @SEEK_SET
%7 = tail call i32 @fseek(i32* %0, i8 zeroext %1, i32 %6)
%8 = icmp eq i8 %3, 0
%9 = zext i8 %2 to i32
%10 = shl nuw i32 1, %9
%11 = trunc i32 %10 to i8
%12 = xor i8 %11, -1
%13 = and i8 %5, %12
%14 = or i8 %5, %11
%15 = select i1 %8, i8 %13, i8 %14
%16 = sext i8 %15 to i32
%17 = tail call i32 @fputc(i32 %16, i32* %0)
ret void
}