#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 */
typedef int /*<<< orphan*/ line_bgr;

/* Variables and functions */
int FS460_image_is_transfer_completed(int *);
int FS460_image_set_start_write(unsigned char *, int);
int OS_file_read(unsigned long, unsigned char *, int);
int OS_file_seek(unsigned long, int /*<<< orphan*/, int, int);
int /*<<< orphan*/ OS_memset(unsigned char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ convert_bgr_to_yuv(unsigned char *, unsigned char *, int);
int read_line(unsigned long file_handle, int width, int file_y, int header_size,
              int scaler_width) {
  int err;
  int completed;
  unsigned char line_yuv[720 * 2];
  unsigned char line_bgr[(((720 * 3) + 3) & ~3)];
  int h_offset;
  {}
  h_offset = (scaler_width - width) / 2;
  err = OS_file_seek(file_handle, 0,
                     header_size + ((((width * 3) + 3) & ~3) * file_y), 0);
  if (!err) {
    if (h_offset < 0) {
      err = OS_file_seek(file_handle, 0, 3 * (-h_offset), 1);
      if (!err) {
        err = OS_file_read(file_handle, line_bgr, scaler_width * 3);
      }
    } else {
      OS_memset(line_bgr, 0, sizeof(line_bgr));
      err = OS_file_read(file_handle, line_bgr + (3 * h_offset), width * 3);
    }
    if (!err) {
      convert_bgr_to_yuv(line_yuv, line_bgr, scaler_width);
      err = FS460_image_set_start_write(line_yuv, scaler_width * 2);
      if (!err) {
        completed = 0;
        while (!completed && !err)
          err = FS460_image_is_transfer_completed(&completed);
      }
    }
  }
  return err;
}


x86 assembly (clang, -O0):
<read_line>:
push   %rbp
mov    %rsp,%rbp
sub    $0xe40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    %r8d,-0x18(%rbp)
mov    -0x18(%rbp),%eax
sub    -0xc(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0xe34(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%edx
imul   $0x3,-0xc(%rbp),%eax
add    $0x3,%eax
and    $0xfffffffc,%eax
imul   -0x10(%rbp),%eax
add    %eax,%edx
xor    %ecx,%ecx
mov    %ecx,%esi
call   1060 <OS_file_seek@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jne    12de <read_line+0x17e>
cmpl   $0x0,-0xe34(%rbp)
jge    120e <read_line+0xae>
mov    -0x8(%rbp),%rdi
xor    %eax,%eax
sub    -0xe34(%rbp),%eax
imul   $0x3,%eax,%edx
xor    %esi,%esi
mov    $0x1,%ecx
call   1060 <OS_file_seek@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jne    1209 <read_line+0xa9>
mov    -0x8(%rbp),%rdi
lea    -0xe30(%rbp),%rsi
imul   $0x3,-0x18(%rbp),%edx
call   1050 <OS_file_read@plt>
mov    %eax,-0x1c(%rbp)
jmp    1244 <read_line+0xe4>
lea    -0xe30(%rbp),%rdi
xor    %esi,%esi
mov    $0x870,%edx
call   1080 <OS_memset@plt>
mov    -0x8(%rbp),%rdi
lea    -0xe30(%rbp),%rsi
imul   $0x3,-0xe34(%rbp),%eax
cltq
add    %rax,%rsi
imul   $0x3,-0xc(%rbp),%edx
call   1050 <OS_file_read@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jne    12d9 <read_line+0x179>
lea    -0x5c0(%rbp),%rdi
lea    -0xe30(%rbp),%rsi
mov    -0x18(%rbp),%edx
call   1070 <convert_bgr_to_yuv@plt>
lea    -0x5c0(%rbp),%rdi
mov    -0x18(%rbp),%esi
shl    $0x1,%esi
call   1030 <FS460_image_set_start_write@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jne    12d4 <read_line+0x174>
movl   $0x0,-0x20(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x20(%rbp)
mov    %al,-0xe35(%rbp)
jne    12ab <read_line+0x14b>
cmpl   $0x0,-0x1c(%rbp)
setne  %al
xor    $0xff,%al
mov    %al,-0xe35(%rbp)
mov    -0xe35(%rbp),%al
test   $0x1,%al
jne    12be <read_line+0x15e>
jmp    12cf <read_line+0x16f>
lea    -0x20(%rbp),%rdi
call   1040 <FS460_image_is_transfer_completed@plt>
mov    %eax,-0x1c(%rbp)
jmp    128a <read_line+0x12a>
jmp    12d4 <read_line+0x174>
jmp    12d9 <read_line+0x179>
jmp    12de <read_line+0x17e>
mov    -0x1c(%rbp),%eax
add    $0xe40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_line>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0xe20,%rsp
mov    %r8d,%r14d
mov    %esi,%r12d
mov    %rdi,%r15
lea    (%r12,%r12,2),%eax
add    $0x3,%eax
and    $0xfffffffc,%eax
imul   %eax,%edx
add    %ecx,%edx
xor    %esi,%esi
xor    %ecx,%ecx
call   1060 <OS_file_seek@plt>
test   %eax,%eax
jne    1250 <read_line+0xf0>
mov    %r14d,%eax
sub    %r12d,%eax
mov    %eax,%ebx
shr    $0x1f,%ebx
add    %eax,%ebx
sar    %ebx
cmp    $0xfffffffe,%eax
jg     11d6 <read_line+0x76>
lea    (%rbx,%rbx,2),%edx
neg    %edx
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x1,%ecx
call   1060 <OS_file_seek@plt>
test   %eax,%eax
jne    1250 <read_line+0xf0>
lea    (%r14,%r14,2),%edx
lea    0x10(%rsp),%rsi
mov    %r15,%rdi
jmp    11fd <read_line+0x9d>
lea    (%r12,%r12,2),%ebp
lea    0x10(%rsp),%rdi
xor    %esi,%esi
mov    $0x870,%edx
call   1080 <OS_memset@plt>
lea    (%rbx,%rbx,2),%eax
cltq
lea    (%rsp,%rax,1),%rsi
add    $0x10,%rsi
mov    %r15,%rdi
mov    %ebp,%edx
call   1050 <OS_file_read@plt>
test   %eax,%eax
jne    1250 <read_line+0xf0>
lea    0x880(%rsp),%rbx
lea    0x10(%rsp),%rsi
mov    %rbx,%rdi
mov    %r14d,%edx
call   1070 <convert_bgr_to_yuv@plt>
add    %r14d,%r14d
mov    %rbx,%rdi
mov    %r14d,%esi
call   1030 <FS460_image_set_start_write@plt>
test   %eax,%eax
jne    1250 <read_line+0xf0>
movl   $0x0,0xc(%rsp)
lea    0xc(%rsp),%rbx
nopl   (%rax)
mov    %rbx,%rdi
call   1040 <FS460_image_is_transfer_completed@plt>
mov    0xc(%rsp),%ecx
or     %eax,%ecx
je     1240 <read_line+0xe0>
add    $0xe20,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @read_line(i64 %0, i32 %1, i32 %2, i32 %3, i32 %4) {
%6 = alloca i64
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca [1440 x i8]
%14 = alloca [2160 x i8]
%15 = alloca i32
store i64 %0, i64* %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store i32 %3, i32* %9
store i32 %4, i32* %10
%16 = load i32, i32* %10
%17 = load i32, i32* %7
%18 = sub nsw i32 %16, %17
%19 = sdiv i32 %18, 2
store i32 %19, i32* %15
%20 = load i64, i64* %6
%21 = load i32, i32* %9
%22 = load i32, i32* %7
%23 = mul nsw i32 %22, 3
%24 = add nsw i32 %23, 3
%25 = and i32 %24, -4
%26 = load i32, i32* %8
%27 = mul nsw i32 %25, %26
%28 = add nsw i32 %21, %27
%29 = call i32 @OS_file_seek(i64 %20, i32 0, i32 %28, i32 0)
store i32 %29, i32* %11
%30 = load i32, i32* %11
%31 = icmp ne i32 %30, 0
br i1 %31, label %91, label %32
32: ; preds = %5
%33 = load i32, i32* %15
%34 = icmp slt i32 %33, 0
br i1 %34, label %35, label %50
35: ; preds = %32
%36 = load i64, i64* %6
%37 = load i32, i32* %15
%38 = sub nsw i32 0, %37
%39 = mul nsw i32 3, %38
%40 = call i32 @OS_file_seek(i64 %36, i32 0, i32 %39, i32 1)
store i32 %40, i32* %11
%41 = load i32, i32* %11
%42 = icmp ne i32 %41, 0
br i1 %42, label %49, label %43
43: ; preds = %35
%44 = load i64, i64* %6
%45 = getelementptr inbounds [2160 x i8], [2160 x i8]* %14, i64 0, i64 0
%46 = load i32, i32* %10
%47 = mul nsw i32 %46, 3
%48 = call i32 @OS_file_read(i64 %44, i8* %45, i32 %47)
store i32 %48, i32* %11
br label %49
49: ; preds = %43, %35
br label %62
50: ; preds = %32
%51 = getelementptr inbounds [2160 x i8], [2160 x i8]* %14, i64 0, i64 0
%52 = call i32 @OS_memset(i8* %51, i32 0, i32 2160)
%53 = load i64, i64* %6
%54 = getelementptr inbounds [2160 x i8], [2160 x i8]* %14, i64 0, i64 0
%55 = load i32, i32* %15
%56 = mul nsw i32 3, %55
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds i8, i8* %54, i64 %57
%59 = load i32, i32* %7
%60 = mul nsw i32 %59, 3
%61 = call i32 @OS_file_read(i64 %53, i8* %58, i32 %60)
store i32 %61, i32* %11
br label %62
62: ; preds = %50, %49
%63 = load i32, i32* %11
%64 = icmp ne i32 %63, 0
br i1 %64, label %90, label %65
65: ; preds = %62
%66 = getelementptr inbounds [1440 x i8], [1440 x i8]* %13, i64 0, i64 0
%67 = getelementptr inbounds [2160 x i8], [2160 x i8]* %14, i64 0, i64 0
%68 = load i32, i32* %10
%69 = call i32 @convert_bgr_to_yuv(i8* %66, i8* %67, i32 %68)
%70 = getelementptr inbounds [1440 x i8], [1440 x i8]* %13, i64 0, i64 0
%71 = load i32, i32* %10
%72 = mul nsw i32 %71, 2
%73 = call i32 @FS460_image_set_start_write(i8* %70, i32 %72)
store i32 %73, i32* %11
%74 = load i32, i32* %11
%75 = icmp ne i32 %74, 0
br i1 %75, label %89, label %76
76: ; preds = %65
store i32 0, i32* %12
br label %77
77: ; preds = %86, %76
%78 = load i32, i32* %12
%79 = icmp ne i32 %78, 0
br i1 %79, label %84, label %80
80: ; preds = %77
%81 = load i32, i32* %11
%82 = icmp ne i32 %81, 0
%83 = xor i1 %82, true
br label %84
84: ; preds = %80, %77
%85 = phi i1 [ false, %77 ], [ %83, %80 ]
br i1 %85, label %86, label %88
86: ; preds = %84
%87 = call i32 @FS460_image_is_transfer_completed(i32* %12)
store i32 %87, i32* %11
br label %77
88: ; preds = %84
br label %89
89: ; preds = %88, %65
br label %90
90: ; preds = %89, %62
br label %91
91: ; preds = %90, %5
%92 = load i32, i32* %11
ret i32 %92
}

LLVM IR (-O2):
define i32 @read_line(i64 %0, i32 %1, i32 %2, i32 %3, i32 %4) {
%6 = alloca i32
%7 = alloca [1440 x i8]
%8 = alloca [2160 x i8]
%9 = bitcast i32* %6 to i8*
%10 = getelementptr inbounds [1440 x i8], [1440 x i8]* %7, i64 0, i64 0
%11 = getelementptr inbounds [2160 x i8], [2160 x i8]* %8, i64 0, i64 0
%12 = sub nsw i32 %4, %1
%13 = sdiv i32 %12, 2
%14 = mul nsw i32 %1, 3
%15 = add nsw i32 %14, 3
%16 = and i32 %15, -4
%17 = mul nsw i32 %16, %2
%18 = add nsw i32 %17, %3
%19 = tail call i32 @OS_file_seek(i64 %0, i32 0, i32 %18, i32 0)
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %51
21: ; preds = %5
%22 = icmp slt i32 %12, -1
br i1 %22, label %23, label %30
23: ; preds = %21
%24 = mul i32 %13, -3
%25 = tail call i32 @OS_file_seek(i64 %0, i32 0, i32 %24, i32 1)
%26 = icmp eq i32 %25, 0
br i1 %26, label %27, label %51
27: ; preds = %23
%28 = mul nsw i32 %4, 3
%29 = call i32 @OS_file_read(i64 %0, i8* %11, i32 %28)
br label %36
30: ; preds = %21
%31 = call i32 @OS_memset(i8* %11, i32 0, i32 2160)
%32 = mul nsw i32 %13, 3
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds [2160 x i8], [2160 x i8]* %8, i64 0, i64 %33
%35 = call i32 @OS_file_read(i64 %0, i8* %34, i32 %14)
br label %36
36: ; preds = %27, %30
%37 = phi i32 [ %29, %27 ], [ %35, %30 ]
%38 = icmp eq i32 %37, 0
br i1 %38, label %39, label %51
39: ; preds = %36
%40 = call i32 @convert_bgr_to_yuv(i8* %10, i8* %11, i32 %4)
%41 = shl nsw i32 %4, 1
%42 = call i32 @FS460_image_set_start_write(i8* %10, i32 %41)
%43 = icmp eq i32 %42, 0
br i1 %43, label %44, label %51
44: ; preds = %39
store i32 0, i32* %6
br label %45
45: ; preds = %44, %45
%46 = call i32 @FS460_image_is_transfer_completed(i32* %6)
%47 = load i32, i32* %6
%48 = icmp eq i32 %47, 0
%49 = icmp eq i32 %46, 0
%50 = select i1 %48, i1 %49, i1 false
br i1 %50, label %45, label %51
51: ; preds = %45, %23, %36, %39, %5
%52 = phi i32 [ %19, %5 ], [ %37, %36 ], [ %42, %39 ], [ %25, %23 ], [ %46, %45 ]
ret i32 %52
}