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


x86 assembly (clang, -O0):
<FS460_set_channel_mux>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%edi
call   1040 <layer_table_base_3@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    115f <FS460_set_channel_mux+0x2f>
movl   $0x1000,-0x4(%rbp)
jmp    11c8 <FS460_set_channel_mux+0x98>
mov    -0x14(%rbp),%edi
add    $0x2,%edi
lea    -0x18(%rbp),%rsi
call   1030 <blender_read_reg@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
je     1186 <FS460_set_channel_mux+0x56>
mov    -0x10(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11c8 <FS460_set_channel_mux+0x98>
mov    -0x18(%rbp),%eax
and    $0xfffffff0,%eax
mov    %eax,-0x18(%rbp)
mov    -0xc(%rbp),%eax
and    $0xf,%eax
or     -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%edi
add    $0x2,%edi
mov    -0x18(%rbp),%esi
call   1050 <blender_write_reg@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
je     11c1 <FS460_set_channel_mux+0x91>
mov    -0x10(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11c8 <FS460_set_channel_mux+0x98>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<FS460_set_channel_mux>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebx
call   1040 <layer_table_base_3@plt>
test   %eax,%eax
je     116e <FS460_set_channel_mux+0x3e>
mov    %eax,%ebp
add    $0x2,%ebp
lea    0x4(%rsp),%rsi
mov    %ebp,%edi
call   1030 <blender_read_reg@plt>
test   %eax,%eax
jne    1173 <FS460_set_channel_mux+0x43>
mov    0x4(%rsp),%eax
and    $0xfffffff0,%eax
and    $0xf,%ebx
or     %eax,%ebx
mov    %ebx,0x4(%rsp)
mov    %ebp,%edi
mov    %ebx,%esi
call   1050 <blender_write_reg@plt>
jmp    1173 <FS460_set_channel_mux+0x43>
mov    $0x1000,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @FS460_set_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* %4
%10 = call i32 @layer_table_base_3(i32 %9)
store i32 %10, i32* %7
%11 = load i32, i32* %7
%12 = icmp ne i32 %11, 0
br i1 %12, label %14, label %13
13: ; preds = %2
store i32 4096, i32* %3
br label %38
14: ; preds = %2
%15 = load i32, i32* %7
%16 = add nsw i32 %15, 2
%17 = call i32 @blender_read_reg(i32 %16, i32* %8)
store i32 %17, i32* %6
%18 = load i32, i32* %6
%19 = icmp ne i32 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %14
%21 = load i32, i32* %6
store i32 %21, i32* %3
br label %38
22: ; preds = %14
%23 = load i32, i32* %8
%24 = and i32 %23, -16
store i32 %24, i32* %8
%25 = load i32, i32* %5
%26 = and i32 %25, 15
%27 = load i32, i32* %8
%28 = or i32 %27, %26
store i32 %28, i32* %8
%29 = load i32, i32* %7
%30 = add nsw i32 %29, 2
%31 = load i32, i32* %8
%32 = call i32 @blender_write_reg(i32 %30, i32 %31)
store i32 %32, i32* %6
%33 = load i32, i32* %6
%34 = icmp ne i32 %33, 0
br i1 %34, label %35, label %37
35: ; preds = %22
%36 = load i32, i32* %6
store i32 %36, i32* %3
br label %38
37: ; preds = %22
store i32 0, i32* %3
br label %38
38: ; preds = %37, %35, %20, %13
%39 = load i32, i32* %3
ret i32 %39
}

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