#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 layer_table_base(int);
int FS460_get_black_white(int layer, int *p_bw_enable) {
  int err;
  int addr;
  unsigned int reg;
  if (!p_bw_enable)
    return 0x1000;
  addr = layer_table_base(layer);
  if (!addr)
    return 0x1000;
  err = blender_read_reg(addr + 0x10, &reg);
  if (err)
    return err;
  if (reg & 0x40)
    *p_bw_enable = 1;
  else
    *p_bw_enable = 0;
  return 0;
}


x86 assembly (clang, -O0):
<FS460_get_black_white>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1146 <FS460_get_black_white+0x26>
movl   $0x1000,-0x4(%rbp)
jmp    11bd <FS460_get_black_white+0x9d>
mov    -0x8(%rbp),%edi
call   1030 <layer_table_base@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jne    1167 <FS460_get_black_white+0x47>
movl   $0x1000,-0x4(%rbp)
jmp    11bd <FS460_get_black_white+0x9d>
mov    -0x18(%rbp),%edi
add    $0x10,%edi
lea    -0x1c(%rbp),%rsi
call   1040 <blender_read_reg@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     118e <FS460_get_black_white+0x6e>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11bd <FS460_get_black_white+0x9d>
mov    -0x1c(%rbp),%eax
and    $0x40,%eax
cmp    $0x0,%eax
je     11ac <FS460_get_black_white+0x8c>
mov    -0x10(%rbp),%rax
movl   $0x1,(%rax)
jmp    11b6 <FS460_get_black_white+0x96>
mov    -0x10(%rbp),%rax
movl   $0x0,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<FS460_get_black_white>:
push   %rbp
push   %rbx
push   %rax
mov    $0x1000,%ebp
test   %rsi,%rsi
je     115c <FS460_get_black_white+0x3c>
mov    %rsi,%rbx
call   1030 <layer_table_base@plt>
test   %eax,%eax
je     115c <FS460_get_black_white+0x3c>
add    $0x10,%eax
lea    0x4(%rsp),%rsi
mov    %eax,%edi
call   1040 <blender_read_reg@plt>
mov    %eax,%ebp
test   %eax,%eax
jne    115c <FS460_get_black_white+0x3c>
mov    0x4(%rsp),%eax
shr    $0x6,%eax
and    $0x1,%eax
mov    %eax,(%rbx)
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @FS460_get_black_white(i32 %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %4
store i32* %1, i32** %5
%9 = load i32*, i32** %5
%10 = icmp ne i32* %9, null
br i1 %10, label %12, label %11
11: ; preds = %2
store i32 4096, i32* %3
br label %35
12: ; preds = %2
%13 = load i32, i32* %4
%14 = call i32 @layer_table_base(i32 %13)
store i32 %14, i32* %7
%15 = load i32, i32* %7
%16 = icmp ne i32 %15, 0
br i1 %16, label %18, label %17
17: ; preds = %12
store i32 4096, i32* %3
br label %35
18: ; preds = %12
%19 = load i32, i32* %7
%20 = add nsw i32 %19, 16
%21 = call i32 @blender_read_reg(i32 %20, i32* %8)
store i32 %21, i32* %6
%22 = load i32, i32* %6
%23 = icmp ne i32 %22, 0
br i1 %23, label %24, label %26
24: ; preds = %18
%25 = load i32, i32* %6
store i32 %25, i32* %3
br label %35
26: ; preds = %18
%27 = load i32, i32* %8
%28 = and i32 %27, 64
%29 = icmp ne i32 %28, 0
br i1 %29, label %30, label %32
30: ; preds = %26
%31 = load i32*, i32** %5
store i32 1, i32* %31
br label %34
32: ; preds = %26
%33 = load i32*, i32** %5
store i32 0, i32* %33
br label %34
34: ; preds = %32, %30
store i32 0, i32* %3
br label %35
35: ; preds = %34, %24, %17, %11
%36 = load i32, i32* %3
ret i32 %36
}

LLVM IR (-O2):
define i32 @FS460_get_black_white(i32 %0, i32* writeonly %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = icmp eq i32* %1, null
br i1 %5, label %17, label %6
6: ; preds = %2
%7 = tail call i32 @layer_table_base(i32 %0)
%8 = icmp eq i32 %7, 0
br i1 %8, label %17, label %9
9: ; preds = %6
%10 = add nsw i32 %7, 16
%11 = call i32 @blender_read_reg(i32 %10, i32* %3)
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %17
13: ; preds = %9
%14 = load i32, i32* %3
%15 = lshr i32 %14, 6
%16 = and i32 %15, 1
store i32 %16, i32* %1
br label %17
17: ; preds = %9, %6, %2, %13
%18 = phi i32 [ 0, %13 ], [ 4096, %2 ], [ 4096, %6 ], [ %11, %9 ]
ret i32 %18
}