#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 blender_read_reg(int, unsigned int *);
int blender_write_reg(int, int);
int freeze_write(int freeze) {
  int err;
  unsigned int FRAM_write;
  err = blender_read_reg(0x50C, &FRAM_write);
  if (err)
    return err;
  if (freeze) {
    err = blender_write_reg(0x50C, 0x0009 | FRAM_write);
    if (err)
      return err;
    err = blender_write_reg(0x50C, 0x0001 | FRAM_write);
    if (err)
      return err;
  } else {
    if (0x0001 & FRAM_write) {
      err = blender_write_reg(0x50C, 0x0009 | FRAM_write);
      if (err)
        return err;
    }
    err = blender_write_reg(0x50C, ~0x0009 & FRAM_write);
    if (err)
      return err;
  }
  return 0;
}


x86 assembly (clang, -O0):
<freeze_write>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    $0x50c,%edi
lea    -0x10(%rbp),%rsi
call   1030 <blender_read_reg@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     1151 <freeze_write+0x31>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1223 <freeze_write+0x103>
cmpl   $0x0,-0x8(%rbp)
je     11b0 <freeze_write+0x90>
mov    -0x10(%rbp),%esi
or     $0x9,%esi
mov    $0x50c,%edi
call   1040 <blender_write_reg@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     1183 <freeze_write+0x63>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1223 <freeze_write+0x103>
mov    -0x10(%rbp),%esi
or     $0x1,%esi
mov    $0x50c,%edi
call   1040 <blender_write_reg@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     11ab <freeze_write+0x8b>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1223 <freeze_write+0x103>
jmp    121c <freeze_write+0xfc>
mov    -0x10(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     11ec <freeze_write+0xcc>
mov    -0x10(%rbp),%esi
or     $0x9,%esi
mov    $0x50c,%edi
call   1040 <blender_write_reg@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     11e7 <freeze_write+0xc7>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1223 <freeze_write+0x103>
jmp    11ec <freeze_write+0xcc>
mov    -0x10(%rbp),%esi
and    $0xfffffff6,%esi
mov    $0x50c,%edi
call   1040 <blender_write_reg@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     1217 <freeze_write+0xf7>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1223 <freeze_write+0x103>
jmp    121c <freeze_write+0xfc>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<freeze_write>:
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebx
lea    0xc(%rsp),%rsi
mov    $0x50c,%edi
call   1030 <blender_read_reg@plt>
test   %eax,%eax
je     1140 <freeze_write+0x20>
add    $0x10,%rsp
pop    %rbx
ret
mov    0xc(%rsp),%esi
test   %ebx,%ebx
je     1162 <freeze_write+0x42>
or     $0x9,%esi
mov    $0x50c,%edi
call   1040 <blender_write_reg@plt>
test   %eax,%eax
jne    113a <freeze_write+0x1a>
mov    0xc(%rsp),%esi
or     $0x1,%esi
jmp    1180 <freeze_write+0x60>
test   $0x1,%sil
je     117d <freeze_write+0x5d>
or     $0x9,%esi
mov    $0x50c,%edi
call   1040 <blender_write_reg@plt>
test   %eax,%eax
jne    113a <freeze_write+0x1a>
mov    0xc(%rsp),%esi
and    $0xfffffff6,%esi
mov    $0x50c,%edi
call   1040 <blender_write_reg@plt>
test   %eax,%eax
jne    113a <freeze_write+0x1a>
xor    %eax,%eax
jmp    113a <freeze_write+0x1a>

LLVM IR (-O0):
define i32 @freeze_write(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %3
%6 = call i32 @blender_read_reg(i32 1292, i32* %5)
store i32 %6, i32* %4
%7 = load i32, i32* %4
%8 = icmp ne i32 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %1
%10 = load i32, i32* %4
store i32 %10, i32* %2
br label %54
11: ; preds = %1
%12 = load i32, i32* %3
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %31
14: ; preds = %11
%15 = load i32, i32* %5
%16 = or i32 9, %15
%17 = call i32 @blender_write_reg(i32 1292, i32 %16)
store i32 %17, i32* %4
%18 = load i32, i32* %4
%19 = icmp ne i32 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %14
%21 = load i32, i32* %4
store i32 %21, i32* %2
br label %54
22: ; preds = %14
%23 = load i32, i32* %5
%24 = or i32 1, %23
%25 = call i32 @blender_write_reg(i32 1292, i32 %24)
store i32 %25, i32* %4
%26 = load i32, i32* %4
%27 = icmp ne i32 %26, 0
br i1 %27, label %28, label %30
28: ; preds = %22
%29 = load i32, i32* %4
store i32 %29, i32* %2
br label %54
30: ; preds = %22
br label %53
31: ; preds = %11
%32 = load i32, i32* %5
%33 = and i32 1, %32
%34 = icmp ne i32 %33, 0
br i1 %34, label %35, label %44
35: ; preds = %31
%36 = load i32, i32* %5
%37 = or i32 9, %36
%38 = call i32 @blender_write_reg(i32 1292, i32 %37)
store i32 %38, i32* %4
%39 = load i32, i32* %4
%40 = icmp ne i32 %39, 0
br i1 %40, label %41, label %43
41: ; preds = %35
%42 = load i32, i32* %4
store i32 %42, i32* %2
br label %54
43: ; preds = %35
br label %44
44: ; preds = %43, %31
%45 = load i32, i32* %5
%46 = and i32 -10, %45
%47 = call i32 @blender_write_reg(i32 1292, i32 %46)
store i32 %47, i32* %4
%48 = load i32, i32* %4
%49 = icmp ne i32 %48, 0
br i1 %49, label %50, label %52
50: ; preds = %44
%51 = load i32, i32* %4
store i32 %51, i32* %2
br label %54
52: ; preds = %44
br label %53
53: ; preds = %52, %30
store i32 0, i32* %2
br label %54
54: ; preds = %53, %50, %41, %28, %20, %9
%55 = load i32, i32* %2
ret i32 %55
}

LLVM IR (-O2):
define i32 @freeze_write(i32 %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
%4 = call i32 @blender_read_reg(i32 1292, i32* %2)
%5 = icmp eq i32 %4, 0
br i1 %5, label %6, label %33
6: ; preds = %1
%7 = icmp eq i32 %0, 0
%8 = load i32, i32* %2
br i1 %7, label %18, label %9
9: ; preds = %6
%10 = or i32 %8, 9
%11 = call i32 @blender_write_reg(i32 1292, i32 %10)
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %33
13: ; preds = %9
%14 = load i32, i32* %2
%15 = or i32 %14, 1
%16 = call i32 @blender_write_reg(i32 1292, i32 %15)
%17 = icmp eq i32 %16, 0
br i1 %17, label %32, label %33
18: ; preds = %6
%19 = and i32 %8, 1
%20 = icmp eq i32 %19, 0
br i1 %20, label %27, label %21
21: ; preds = %18
%22 = or i32 %8, 9
%23 = call i32 @blender_write_reg(i32 1292, i32 %22)
%24 = icmp eq i32 %23, 0
br i1 %24, label %25, label %33
25: ; preds = %21
%26 = load i32, i32* %2
br label %27
27: ; preds = %25, %18
%28 = phi i32 [ %26, %25 ], [ %8, %18 ]
%29 = and i32 %28, -10
%30 = call i32 @blender_write_reg(i32 1292, i32 %29)
%31 = icmp eq i32 %30, 0
br i1 %31, label %32, label %33
32: ; preds = %27, %13
br label %33
33: ; preds = %27, %21, %13, %9, %1, %32
%34 = phi i32 [ 0, %32 ], [ %4, %1 ], [ %11, %9 ], [ %16, %13 ], [ %23, %21 ], [ %30, %27 ]
ret i32 %34
}