#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 FS460_image_get_begin_field(int odd_field) {
  int err;
  unsigned int FRAM_read;
  err = blender_read_reg(0x50E, &FRAM_read);
  if (err)
    return err;
  FRAM_read &= ~0x000E;
  if (odd_field)
    FRAM_read |= 0x04;
  err = blender_write_reg(0x50E, FRAM_read);
  if (err)
    return err;
  FRAM_read |= 0x08;
  err = blender_write_reg(0x50E, FRAM_read);
  if (err)
    return err;
  FRAM_read &= ~0x08;
  err = blender_write_reg(0x50E, FRAM_read);
  if (err)
    return err;
  return 0;
}


x86 assembly (clang, -O0):
<FS460_image_get_begin_field>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    $0x50e,%edi
lea    -0x10(%rbp),%rsi
call   1030 <blender_read_reg@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     1151 <FS460_image_get_begin_field+0x31>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11f5 <FS460_image_get_begin_field+0xd5>
mov    -0x10(%rbp),%eax
and    $0xfffffff1,%eax
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     116d <FS460_image_get_begin_field+0x4d>
mov    -0x10(%rbp),%eax
or     $0x4,%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%esi
mov    $0x50e,%edi
call   1040 <blender_write_reg@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     1192 <FS460_image_get_begin_field+0x72>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11f5 <FS460_image_get_begin_field+0xd5>
mov    -0x10(%rbp),%eax
or     $0x8,%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%esi
mov    $0x50e,%edi
call   1040 <blender_write_reg@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     11c0 <FS460_image_get_begin_field+0xa0>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11f5 <FS460_image_get_begin_field+0xd5>
mov    -0x10(%rbp),%eax
and    $0xfffffff7,%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%esi
mov    $0x50e,%edi
call   1040 <blender_write_reg@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     11ee <FS460_image_get_begin_field+0xce>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11f5 <FS460_image_get_begin_field+0xd5>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<FS460_image_get_begin_field>:
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebx
lea    0xc(%rsp),%rsi
mov    $0x50e,%edi
call   1030 <blender_read_reg@plt>
test   %eax,%eax
jne    1189 <FS460_image_get_begin_field+0x69>
mov    0xc(%rsp),%eax
and    $0xfffffff1,%eax
lea    0x4(%rax),%esi
test   %ebx,%ebx
cmove  %eax,%esi
mov    %esi,0xc(%rsp)
mov    $0x50e,%edi
call   1040 <blender_write_reg@plt>
test   %eax,%eax
jne    1189 <FS460_image_get_begin_field+0x69>
mov    0xc(%rsp),%esi
or     $0x8,%esi
mov    %esi,0xc(%rsp)
mov    $0x50e,%edi
call   1040 <blender_write_reg@plt>
test   %eax,%eax
jne    1189 <FS460_image_get_begin_field+0x69>
mov    0xc(%rsp),%esi
and    $0xfffffff7,%esi
mov    %esi,0xc(%rsp)
mov    $0x50e,%edi
call   1040 <blender_write_reg@plt>
add    $0x10,%rsp
pop    %rbx
ret

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

LLVM IR (-O2):
define i32 @FS460_image_get_begin_field(i32 %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
%4 = call i32 @blender_read_reg(i32 1294, i32* %2)
%5 = icmp eq i32 %4, 0
br i1 %5, label %6, label %23
6: ; preds = %1
%7 = load i32, i32* %2
%8 = and i32 %7, -15
%9 = icmp eq i32 %0, 0
%10 = or i32 %8, 4
%11 = select i1 %9, i32 %8, i32 %10
store i32 %11, i32* %2
%12 = call i32 @blender_write_reg(i32 1294, i32 %11)
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %23
14: ; preds = %6
%15 = load i32, i32* %2
%16 = or i32 %15, 8
store i32 %16, i32* %2
%17 = call i32 @blender_write_reg(i32 1294, i32 %16)
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %23
19: ; preds = %14
%20 = load i32, i32* %2
%21 = and i32 %20, -9
store i32 %21, i32* %2
%22 = call i32 @blender_write_reg(i32 1294, i32 %21)
br label %23
23: ; preds = %19, %14, %6, %1
%24 = phi i32 [ %4, %1 ], [ %12, %6 ], [ %17, %14 ], [ %22, %19 ]
ret i32 %24
}