#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_3(int);
int FS460_get_channel_mux(int layer, int *p_channel) {
  int err;
  int addr;
  unsigned int reg;
  if (!p_channel)
    return 0x1000;
  addr = layer_table_base_3(layer);
  if (!addr)
    return 0x1000;
  err = blender_read_reg(addr + 0x02, &reg);
  if (err)
    return err;
  *p_channel = reg & 0x000F;
  return 0;
}


x86 assembly (clang, -O0):
<FS460_get_channel_mux>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1146 <FS460_get_channel_mux+0x26>
movl   $0x1000,-0x4(%rbp)
jmp    11a1 <FS460_get_channel_mux+0x81>
mov    -0x8(%rbp),%edi
call   1040 <layer_table_base_3@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jne    1167 <FS460_get_channel_mux+0x47>
movl   $0x1000,-0x4(%rbp)
jmp    11a1 <FS460_get_channel_mux+0x81>
mov    -0x18(%rbp),%edi
add    $0x2,%edi
lea    -0x1c(%rbp),%rsi
call   1030 <blender_read_reg@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     118e <FS460_get_channel_mux+0x6e>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11a1 <FS460_get_channel_mux+0x81>
mov    -0x1c(%rbp),%ecx
and    $0xf,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<FS460_get_channel_mux>:
push   %rbp
push   %rbx
push   %rax
mov    $0x1000,%ebp
test   %rsi,%rsi
je     1159 <FS460_get_channel_mux+0x39>
mov    %rsi,%rbx
call   1040 <layer_table_base_3@plt>
test   %eax,%eax
je     1159 <FS460_get_channel_mux+0x39>
add    $0x2,%eax
lea    0x4(%rsp),%rsi
mov    %eax,%edi
call   1030 <blender_read_reg@plt>
mov    %eax,%ebp
test   %eax,%eax
jne    1159 <FS460_get_channel_mux+0x39>
mov    0x4(%rsp),%eax
and    $0xf,%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_channel_mux(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 %30
12: ; preds = %2
%13 = load i32, i32* %4
%14 = call i32 @layer_table_base_3(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 %30
18: ; preds = %12
%19 = load i32, i32* %7
%20 = add nsw i32 %19, 2
%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 %30
26: ; preds = %18
%27 = load i32, i32* %8
%28 = and i32 %27, 15
%29 = load i32*, i32** %5
store i32 %28, i32* %29
store i32 0, i32* %3
br label %30
30: ; preds = %26, %24, %17, %11
%31 = load i32, i32* %3
ret i32 %31
}

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