#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(int);
int FS460_set_swap_uv(int layer, int swap_uv) {
  int err;
  int addr;
  unsigned int reg;
  addr = layer_table_base(layer);
  if (!addr)
    return 0x1000;
  err = blender_read_reg(addr + 0x10, &reg);
  if (err)
    return err;
  if (swap_uv)
    reg |= 0x80;
  else
    reg &= ~0x80;
  err = blender_write_reg(addr + 0x10, reg);
  if (err)
    return err;
  return 0;
}


x86 assembly (clang, -O0):
<FS460_set_swap_uv>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%edi
call   1030 <layer_table_base@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    115f <FS460_set_swap_uv+0x2f>
movl   $0x1000,-0x4(%rbp)
jmp    11d8 <FS460_set_swap_uv+0xa8>
mov    -0x14(%rbp),%edi
add    $0x10,%edi
lea    -0x18(%rbp),%rsi
call   1040 <blender_read_reg@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
je     1186 <FS460_set_swap_uv+0x56>
mov    -0x10(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11d8 <FS460_set_swap_uv+0xa8>
cmpl   $0x0,-0xc(%rbp)
je     11a0 <FS460_set_swap_uv+0x70>
mov    -0x18(%rbp),%eax
or     $0x80,%eax
mov    %eax,-0x18(%rbp)
jmp    11ab <FS460_set_swap_uv+0x7b>
mov    -0x18(%rbp),%eax
and    $0xffffff7f,%eax
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%edi
add    $0x10,%edi
mov    -0x18(%rbp),%esi
call   1050 <blender_write_reg@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
je     11d1 <FS460_set_swap_uv+0xa1>
mov    -0x10(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11d8 <FS460_set_swap_uv+0xa8>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<FS460_set_swap_uv>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
call   1030 <layer_table_base@plt>
test   %eax,%eax
je     1176 <FS460_set_swap_uv+0x46>
mov    %eax,%ebx
add    $0x10,%ebx
lea    0x4(%rsp),%rsi
mov    %ebx,%edi
call   1040 <blender_read_reg@plt>
test   %eax,%eax
jne    117b <FS460_set_swap_uv+0x4b>
xor    %esi,%esi
test   %ebp,%ebp
setne  %sil
mov    $0xffffff7f,%eax
and    0x4(%rsp),%eax
shl    $0x7,%esi
or     %eax,%esi
mov    %esi,0x4(%rsp)
mov    %ebx,%edi
call   1050 <blender_write_reg@plt>
jmp    117b <FS460_set_swap_uv+0x4b>
mov    $0x1000,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @FS460_set_swap_uv(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(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 %41
14: ; preds = %2
%15 = load i32, i32* %7
%16 = add nsw i32 %15, 16
%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 %41
22: ; preds = %14
%23 = load i32, i32* %5
%24 = icmp ne i32 %23, 0
br i1 %24, label %25, label %28
25: ; preds = %22
%26 = load i32, i32* %8
%27 = or i32 %26, 128
store i32 %27, i32* %8
br label %31
28: ; preds = %22
%29 = load i32, i32* %8
%30 = and i32 %29, -129
store i32 %30, i32* %8
br label %31
31: ; preds = %28, %25
%32 = load i32, i32* %7
%33 = add nsw i32 %32, 16
%34 = load i32, i32* %8
%35 = call i32 @blender_write_reg(i32 %33, i32 %34)
store i32 %35, i32* %6
%36 = load i32, i32* %6
%37 = icmp ne i32 %36, 0
br i1 %37, label %38, label %40
38: ; preds = %31
%39 = load i32, i32* %6
store i32 %39, i32* %3
br label %41
40: ; preds = %31
store i32 0, i32* %3
br label %41
41: ; preds = %40, %38, %20, %13
%42 = load i32, i32* %3
ret i32 %42
}

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