#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 FS460_image_get_finish_read(unsigned char *, int);
int FS460_image_get_start_read(int);
int FS460_image_is_transfer_completed(int *);
int OS_file_seek(unsigned long, int /*<<< orphan*/, int, int /*<<< orphan*/);
int OS_file_write(unsigned long, unsigned char *, int);
int /*<<< orphan*/ convert_yuv_to_bgr(unsigned char *, unsigned char *, int);
int write_line(unsigned long file_handle, int width, int file_y) {
  int err;
  int completed;
  unsigned char line_yuv[720 * 2];
  unsigned char line_bgr[(((720 * 3) + 3) & ~3)];
  {}
  err = FS460_image_get_start_read(width * 2);
  if (!err) {
    completed = 0;
    while (!completed && !err)
      err = FS460_image_is_transfer_completed(&completed);
    if (!err) {
      err = FS460_image_get_finish_read(line_yuv, width * 2);
      if (!err) {
        convert_yuv_to_bgr(line_bgr, line_yuv, width);
        err = OS_file_seek(file_handle, 0,
                           (14 + 40) + ((((width * 3) + 3) & ~3) * file_y), 0);
        if (!err) {
          err = OS_file_write(file_handle, line_bgr, (((width * 3) + 3) & ~3));
        }
      }
    }
  }
  if (err) {
  }
  return err;
}


x86 assembly (clang, -O0):
<write_line>:
push   %rbp
mov    %rsp,%rbp
sub    $0xe40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0xc(%rbp),%edi
shl    $0x1,%edi
call   1050 <FS460_image_get_start_read@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    126f <write_line+0x10f>
movl   $0x0,-0x18(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x18(%rbp)
mov    %al,-0xe31(%rbp)
jne    11b5 <write_line+0x55>
cmpl   $0x0,-0x14(%rbp)
setne  %al
xor    $0xff,%al
mov    %al,-0xe31(%rbp)
mov    -0xe31(%rbp),%al
test   $0x1,%al
jne    11c8 <write_line+0x68>
jmp    11d9 <write_line+0x79>
lea    -0x18(%rbp),%rdi
call   1060 <FS460_image_is_transfer_completed@plt>
mov    %eax,-0x14(%rbp)
jmp    1194 <write_line+0x34>
cmpl   $0x0,-0x14(%rbp)
jne    126a <write_line+0x10a>
lea    -0x5c0(%rbp),%rdi
mov    -0xc(%rbp),%esi
shl    $0x1,%esi
call   1030 <FS460_image_get_finish_read@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    1265 <write_line+0x105>
lea    -0xe30(%rbp),%rdi
lea    -0x5c0(%rbp),%rsi
mov    -0xc(%rbp),%edx
call   1040 <convert_yuv_to_bgr@plt>
mov    -0x8(%rbp),%rdi
imul   $0x3,-0xc(%rbp),%edx
add    $0x3,%edx
and    $0xfffffffc,%edx
imul   -0x10(%rbp),%edx
add    $0x36,%edx
xor    %ecx,%ecx
mov    %ecx,%esi
call   1070 <OS_file_seek@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    1260 <write_line+0x100>
mov    -0x8(%rbp),%rdi
lea    -0xe30(%rbp),%rsi
imul   $0x3,-0xc(%rbp),%edx
add    $0x3,%edx
and    $0xfffffffc,%edx
call   1080 <OS_file_write@plt>
mov    %eax,-0x14(%rbp)
jmp    1265 <write_line+0x105>
jmp    126a <write_line+0x10a>
jmp    126f <write_line+0x10f>
cmpl   $0x0,-0x14(%rbp)
je     127e <write_line+0x11e>
jmp    127e <write_line+0x11e>
mov    -0x14(%rbp),%eax
add    $0xe40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_line>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0xe20,%rsp
mov    %edx,%r15d
mov    %esi,%r12d
mov    %rdi,%r14
lea    (%r12,%r12,1),%ebp
mov    %ebp,%edi
call   1050 <FS460_image_get_start_read@plt>
test   %eax,%eax
jne    1210 <write_line+0xb0>
movl   $0x0,0xc(%rsp)
lea    0xc(%rsp),%rbx
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1060 <FS460_image_is_transfer_completed@plt>
mov    0xc(%rsp),%ecx
or     %eax,%ecx
je     11a0 <write_line+0x40>
test   %eax,%eax
jne    1210 <write_line+0xb0>
lea    0x10(%rsp),%rdi
mov    %ebp,%esi
call   1030 <FS460_image_get_finish_read@plt>
test   %eax,%eax
jne    1210 <write_line+0xb0>
lea    0x5b0(%rsp),%rdi
lea    0x10(%rsp),%rsi
mov    %r12d,%edx
call   1040 <convert_yuv_to_bgr@plt>
lea    (%r12,%r12,2),%ebx
add    $0x3,%ebx
and    $0xfffffffc,%ebx
imul   %ebx,%r15d
add    $0x36,%r15d
mov    %r14,%rdi
xor    %esi,%esi
mov    %r15d,%edx
xor    %ecx,%ecx
call   1070 <OS_file_seek@plt>
test   %eax,%eax
jne    1210 <write_line+0xb0>
lea    0x5b0(%rsp),%rsi
mov    %r14,%rdi
mov    %ebx,%edx
call   1080 <OS_file_write@plt>
add    $0xe20,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @write_line(i64 %0, i32 %1, i32 %2) {
%4 = alloca i64
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca [1440 x i8]
%10 = alloca [2160 x i8]
store i64 %0, i64* %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%11 = load i32, i32* %5
%12 = mul nsw i32 %11, 2
%13 = call i32 @FS460_image_get_start_read(i32 %12)
store i32 %13, i32* %7
%14 = load i32, i32* %7
%15 = icmp ne i32 %14, 0
br i1 %15, label %65, label %16
16: ; preds = %3
store i32 0, i32* %8
br label %17
17: ; preds = %26, %16
%18 = load i32, i32* %8
%19 = icmp ne i32 %18, 0
br i1 %19, label %24, label %20
20: ; preds = %17
%21 = load i32, i32* %7
%22 = icmp ne i32 %21, 0
%23 = xor i1 %22, true
br label %24
24: ; preds = %20, %17
%25 = phi i1 [ false, %17 ], [ %23, %20 ]
br i1 %25, label %26, label %28
26: ; preds = %24
%27 = call i32 @FS460_image_is_transfer_completed(i32* %8)
store i32 %27, i32* %7
br label %17
28: ; preds = %24
%29 = load i32, i32* %7
%30 = icmp ne i32 %29, 0
br i1 %30, label %64, label %31
31: ; preds = %28
%32 = getelementptr inbounds [1440 x i8], [1440 x i8]* %9, i64 0, i64 0
%33 = load i32, i32* %5
%34 = mul nsw i32 %33, 2
%35 = call i32 @FS460_image_get_finish_read(i8* %32, i32 %34)
store i32 %35, i32* %7
%36 = load i32, i32* %7
%37 = icmp ne i32 %36, 0
br i1 %37, label %63, label %38
38: ; preds = %31
%39 = getelementptr inbounds [2160 x i8], [2160 x i8]* %10, i64 0, i64 0
%40 = getelementptr inbounds [1440 x i8], [1440 x i8]* %9, i64 0, i64 0
%41 = load i32, i32* %5
%42 = call i32 @convert_yuv_to_bgr(i8* %39, i8* %40, i32 %41)
%43 = load i64, i64* %4
%44 = load i32, i32* %5
%45 = mul nsw i32 %44, 3
%46 = add nsw i32 %45, 3
%47 = and i32 %46, -4
%48 = load i32, i32* %6
%49 = mul nsw i32 %47, %48
%50 = add nsw i32 54, %49
%51 = call i32 @OS_file_seek(i64 %43, i32 0, i32 %50, i32 0)
store i32 %51, i32* %7
%52 = load i32, i32* %7
%53 = icmp ne i32 %52, 0
br i1 %53, label %62, label %54
54: ; preds = %38
%55 = load i64, i64* %4
%56 = getelementptr inbounds [2160 x i8], [2160 x i8]* %10, i64 0, i64 0
%57 = load i32, i32* %5
%58 = mul nsw i32 %57, 3
%59 = add nsw i32 %58, 3
%60 = and i32 %59, -4
%61 = call i32 @OS_file_write(i64 %55, i8* %56, i32 %60)
store i32 %61, i32* %7
br label %62
62: ; preds = %54, %38
br label %63
63: ; preds = %62, %31
br label %64
64: ; preds = %63, %28
br label %65
65: ; preds = %64, %3
%66 = load i32, i32* %7
%67 = icmp ne i32 %66, 0
br i1 %67, label %68, label %69
68: ; preds = %65
br label %69
69: ; preds = %68, %65
%70 = load i32, i32* %7
ret i32 %70
}

LLVM IR (-O2):
define i32 @write_line(i64 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca [1440 x i8]
%6 = alloca [2160 x i8]
%7 = bitcast i32* %4 to i8*
%8 = getelementptr inbounds [1440 x i8], [1440 x i8]* %5, i64 0, i64 0
%9 = getelementptr inbounds [2160 x i8], [2160 x i8]* %6, i64 0, i64 0
%10 = shl nsw i32 %1, 1
%11 = tail call i32 @FS460_image_get_start_read(i32 %10)
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %35
13: ; preds = %3
store i32 0, i32* %4
br label %14
14: ; preds = %13, %14
%15 = call i32 @FS460_image_is_transfer_completed(i32* %4)
%16 = load i32, i32* %4
%17 = icmp eq i32 %16, 0
%18 = icmp eq i32 %15, 0
%19 = select i1 %17, i1 %18, i1 false
br i1 %19, label %14, label %20
20: ; preds = %14
br i1 %18, label %21, label %35
21: ; preds = %20
%22 = call i32 @FS460_image_get_finish_read(i8* %8, i32 %10)
%23 = icmp eq i32 %22, 0
br i1 %23, label %24, label %35
24: ; preds = %21
%25 = call i32 @convert_yuv_to_bgr(i8* %9, i8* %8, i32 %1)
%26 = mul nsw i32 %1, 3
%27 = add nsw i32 %26, 3
%28 = and i32 %27, -4
%29 = mul nsw i32 %28, %2
%30 = add nsw i32 %29, 54
%31 = call i32 @OS_file_seek(i64 %0, i32 0, i32 %30, i32 0)
%32 = icmp eq i32 %31, 0
br i1 %32, label %33, label %35
33: ; preds = %24
%34 = call i32 @OS_file_write(i64 %0, i8* %9, i32 %28)
br label %35
35: ; preds = %20, %24, %33, %21, %3
%36 = phi i32 [ %11, %3 ], [ %15, %20 ], [ %22, %21 ], [ %31, %24 ], [ %34, %33 ]
ret i32 %36
}