#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 uint8_t;
typedef int uint16_t;

/* Variables and functions */
int /*<<< orphan*/ eeprom_lock();
int /*<<< orphan*/ eeprom_unlock_data();
uint8_t eeprom_set_afr0(void) {
  uint8_t sr;
  uint16_t timeout = 0xFFFF;
  if (!eeprom_unlock_data())
    return 0;
  *(unsigned char *)0x505B = (1 << 7);
  *(unsigned char *)0x505C = ~(1 << 7);
  *(unsigned char *)0x4803 = 1;
  *(unsigned char *)0x4804 = 0xFE;
  for (timeout = 0xFFFF; timeout > 0; timeout--) {
    sr = *(unsigned char *)0x505F;
    if (sr & (1 << 2))
      break;
  }
  if (sr & (1 << 0))
    timeout = 0;
  *(unsigned char *)0x505B &= (1 << 7);
  *(unsigned char *)0x505C |= (1 << 7);
  eeprom_lock();
  return (timeout > 0) && (*(unsigned char *)0x4803 & 1);
}


x86 assembly (clang, -O0):
<eeprom_set_afr0>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0xffff,-0xc(%rbp)
mov    $0x0,%al
call   1030 <eeprom_unlock_data@plt>
cmp    $0x0,%eax
jne    114b <eeprom_set_afr0+0x2b>
movl   $0x0,-0x4(%rbp)
jmp    1225 <eeprom_set_afr0+0x105>
mov    $0x505b,%eax
movb   $0x80,(%rax)
mov    $0x505c,%eax
movb   $0x7f,(%rax)
mov    $0x4803,%eax
movb   $0x1,(%rax)
mov    $0x4804,%eax
movb   $0xfe,(%rax)
movl   $0xffff,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jle    11ae <eeprom_set_afr0+0x8e>
mov    $0x505f,%eax
movzbl (%rax),%eax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
and    $0x4,%eax
cmp    $0x0,%eax
je     119b <eeprom_set_afr0+0x7b>
jmp    11ae <eeprom_set_afr0+0x8e>
jmp    11a0 <eeprom_set_afr0+0x80>
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
jmp    1172 <eeprom_set_afr0+0x52>
mov    -0x8(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     11c4 <eeprom_set_afr0+0xa4>
movl   $0x0,-0xc(%rbp)
mov    $0x505b,%eax
movzbl (%rax),%eax
and    $0x80,%eax
mov    %al,%cl
mov    $0x505b,%eax
mov    %cl,(%rax)
mov    $0x505c,%eax
movzbl (%rax),%eax
or     $0x80,%eax
mov    %al,%cl
mov    $0x505c,%eax
mov    %cl,(%rax)
mov    $0x0,%al
call   1040 <eeprom_lock@plt>
xor    %eax,%eax
cmpl   $0x0,-0xc(%rbp)
mov    %al,-0xd(%rbp)
jle    121a <eeprom_set_afr0+0xfa>
mov    $0x4803,%eax
movzbl (%rax),%eax
and    $0x1,%eax
cmp    $0x0,%eax
setne  %al
mov    %al,-0xd(%rbp)
mov    -0xd(%rbp),%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<eeprom_set_afr0>:
push   %rbp
push   %rbx
push   %rax
xor    %ebp,%ebp
xor    %eax,%eax
call   1030 <eeprom_unlock_data@plt>
test   %eax,%eax
je     1183 <eeprom_set_afr0+0x63>
movb   $0x80,0x505b
80
movb   $0x7f,0x505c
7f
movb   $0x1,0x4803
01
movb   $0xfe,0x4804
fe
mov    0x505f,%bl
andb   $0x80,0x505b
80
orb    $0x80,0x505c
80
xor    %ebp,%ebp
xor    %eax,%eax
call   1040 <eeprom_lock@plt>
and    $0x5,%bl
cmp    $0x4,%bl
jne    1183 <eeprom_set_afr0+0x63>
movzbl 0x4803,%ebp
and    $0x1,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @eeprom_set_afr0() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
store i32 65535, i32* %3
%4 = call i32 (...) @eeprom_unlock_data()
%5 = icmp ne i32 %4, 0
br i1 %5, label %7, label %6
6: ; preds = %0
store i32 0, i32* %1
br label %47
7: ; preds = %0
store i8 -128, i8* inttoptr (i64 20571 to i8*)
store i8 127, i8* inttoptr (i64 20572 to i8*)
store i8 1, i8* inttoptr (i64 18435 to i8*)
store i8 -2, i8* inttoptr (i64 18436 to i8*)
store i32 65535, i32* %3
br label %8
8: ; preds = %19, %7
%9 = load i32, i32* %3
%10 = icmp sgt i32 %9, 0
br i1 %10, label %11, label %22
11: ; preds = %8
%12 = load i8, i8* inttoptr (i64 20575 to i8*)
%13 = zext i8 %12 to i32
store i32 %13, i32* %2
%14 = load i32, i32* %2
%15 = and i32 %14, 4
%16 = icmp ne i32 %15, 0
br i1 %16, label %17, label %18
17: ; preds = %11
br label %22
18: ; preds = %11
br label %19
19: ; preds = %18
%20 = load i32, i32* %3
%21 = add nsw i32 %20, -1
store i32 %21, i32* %3
br label %8
22: ; preds = %17, %8
%23 = load i32, i32* %2
%24 = and i32 %23, 1
%25 = icmp ne i32 %24, 0
br i1 %25, label %26, label %27
26: ; preds = %22
store i32 0, i32* %3
br label %27
27: ; preds = %26, %22
%28 = load i8, i8* inttoptr (i64 20571 to i8*)
%29 = zext i8 %28 to i32
%30 = and i32 %29, 128
%31 = trunc i32 %30 to i8
store i8 %31, i8* inttoptr (i64 20571 to i8*)
%32 = load i8, i8* inttoptr (i64 20572 to i8*)
%33 = zext i8 %32 to i32
%34 = or i32 %33, 128
%35 = trunc i32 %34 to i8
store i8 %35, i8* inttoptr (i64 20572 to i8*)
%36 = call i32 (...) @eeprom_lock()
%37 = load i32, i32* %3
%38 = icmp sgt i32 %37, 0
br i1 %38, label %39, label %44
39: ; preds = %27
%40 = load i8, i8* inttoptr (i64 18435 to i8*)
%41 = zext i8 %40 to i32
%42 = and i32 %41, 1
%43 = icmp ne i32 %42, 0
br label %44
44: ; preds = %39, %27
%45 = phi i1 [ false, %27 ], [ %43, %39 ]
%46 = zext i1 %45 to i32
store i32 %46, i32* %1
br label %47
47: ; preds = %44, %6
%48 = load i32, i32* %1
ret i32 %48
}

LLVM IR (-O2):
define i32 @eeprom_set_afr0() {
%1 = tail call i32 (...) @eeprom_unlock_data()
%2 = icmp eq i32 %1, 0
br i1 %2, label %16, label %3
3: ; preds = %0
store i8 -128, i8* inttoptr (i64 20571 to i8*)
store i8 127, i8* inttoptr (i64 20572 to i8*)
store i8 1, i8* inttoptr (i64 18435 to i8*)
store i8 -2, i8* inttoptr (i64 18436 to i8*)
%4 = load i8, i8* inttoptr (i64 20575 to i8*)
%5 = load i8, i8* inttoptr (i64 20571 to i8*)
%6 = and i8 %5, -128
store i8 %6, i8* inttoptr (i64 20571 to i8*)
%7 = load i8, i8* inttoptr (i64 20572 to i8*)
%8 = or i8 %7, -128
store i8 %8, i8* inttoptr (i64 20572 to i8*)
%9 = tail call i32 (...) @eeprom_lock()
%10 = and i8 %4, 5
%11 = icmp eq i8 %10, 4
br i1 %11, label %12, label %16
12: ; preds = %3
%13 = load i8, i8* inttoptr (i64 18435 to i8*)
%14 = and i8 %13, 1
%15 = zext i8 %14 to i32
br label %16
16: ; preds = %3, %12, %0
%17 = phi i32 [ 0, %0 ], [ 0, %3 ], [ %15, %12 ]
ret i32 %17
}