#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 */
double red_diff_uyvy(unsigned char const *);
extern int find_red_flash_uyvy(const unsigned char *video_buf, int line_size) {
  double total_diff = 0;
  int num_diffs = 0;
  int i;
  for (i = 20; i < 80; i += 4) {
    double red_diff = red_diff_uyvy(video_buf + 30 * line_size + i);
    total_diff += red_diff;
    num_diffs++;
  }
  double avg_diff = total_diff / num_diffs;
  if (avg_diff > 30.0)
    return 1;
  return 0;
}


x86 assembly (clang, -O0):
<find_red_flash_uyvy>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x14,-0x28(%rbp)
cmpl   $0x50,-0x28(%rbp)
jge    1183 <find_red_flash_uyvy+0x73>
mov    -0x10(%rbp),%rdi
imul   $0x1e,-0x14(%rbp),%eax
cltq
add    %rax,%rdi
movslq -0x28(%rbp),%rax
add    %rax,%rdi
call   1030 <red_diff_uyvy@plt>
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
addsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    -0x28(%rbp),%eax
add    $0x4,%eax
mov    %eax,-0x28(%rbp)
jmp    1135 <find_red_flash_uyvy+0x25>
movsd  -0x20(%rbp),%xmm0
cvtsi2sdl -0x24(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm0
movsd  0xe5d(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    11b9 <find_red_flash_uyvy+0xa9>
movl   $0x1,-0x4(%rbp)
jmp    11c0 <find_red_flash_uyvy+0xb0>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<find_red_flash_uyvy>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
mov    %esi,%eax
shl    $0x5,%eax
sub    %esi,%eax
sub    %esi,%eax
movslq %eax,%rbx
add    %rbx,%rdi
add    $0x14,%rdi
call   1030 <red_diff_uyvy@plt>
xorpd  %xmm1,%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,(%rsp)
lea    (%r14,%rbx,1),%rdi
add    $0x18,%rdi
call   1030 <red_diff_uyvy@plt>
addsd  (%rsp),%xmm0
movsd  %xmm0,(%rsp)
lea    (%r14,%rbx,1),%rdi
add    $0x1c,%rdi
call   1030 <red_diff_uyvy@plt>
addsd  (%rsp),%xmm0
movsd  %xmm0,(%rsp)
lea    (%r14,%rbx,1),%rdi
add    $0x20,%rdi
call   1030 <red_diff_uyvy@plt>
addsd  (%rsp),%xmm0
movsd  %xmm0,(%rsp)
lea    (%r14,%rbx,1),%rdi
add    $0x24,%rdi
call   1030 <red_diff_uyvy@plt>
addsd  (%rsp),%xmm0
movsd  %xmm0,(%rsp)
lea    (%r14,%rbx,1),%rdi
add    $0x28,%rdi
call   1030 <red_diff_uyvy@plt>
addsd  (%rsp),%xmm0
movsd  %xmm0,(%rsp)
lea    (%r14,%rbx,1),%rdi
add    $0x2c,%rdi
call   1030 <red_diff_uyvy@plt>
addsd  (%rsp),%xmm0
movsd  %xmm0,(%rsp)
lea    (%r14,%rbx,1),%rdi
add    $0x30,%rdi
call   1030 <red_diff_uyvy@plt>
addsd  (%rsp),%xmm0
movsd  %xmm0,(%rsp)
lea    (%r14,%rbx,1),%rdi
add    $0x34,%rdi
call   1030 <red_diff_uyvy@plt>
addsd  (%rsp),%xmm0
movsd  %xmm0,(%rsp)
lea    (%r14,%rbx,1),%rdi
add    $0x38,%rdi
call   1030 <red_diff_uyvy@plt>
addsd  (%rsp),%xmm0
movsd  %xmm0,(%rsp)
lea    (%r14,%rbx,1),%rdi
add    $0x3c,%rdi
call   1030 <red_diff_uyvy@plt>
addsd  (%rsp),%xmm0
movsd  %xmm0,(%rsp)
lea    (%r14,%rbx,1),%rdi
add    $0x40,%rdi
call   1030 <red_diff_uyvy@plt>
addsd  (%rsp),%xmm0
movsd  %xmm0,(%rsp)
lea    (%r14,%rbx,1),%rdi
add    $0x44,%rdi
call   1030 <red_diff_uyvy@plt>
addsd  (%rsp),%xmm0
movsd  %xmm0,(%rsp)
lea    (%r14,%rbx,1),%rdi
add    $0x48,%rdi
call   1030 <red_diff_uyvy@plt>
addsd  (%rsp),%xmm0
movsd  %xmm0,(%rsp)
lea    (%r14,%rbx,1),%rdi
add    $0x4c,%rdi
call   1030 <red_diff_uyvy@plt>
addsd  (%rsp),%xmm0
divsd  0xd7f(%rip),%xmm0
xor    %eax,%eax
ucomisd 0xd7d(%rip),%xmm0
seta   %al
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i32 @find_red_flash_uyvy(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca double
%7 = alloca i32
%8 = alloca i32
%9 = alloca double
%10 = alloca double
store i8* %0, i8** %4
store i32 %1, i32* %5
store double 0.000000e+00, double* %6
store i32 0, i32* %7
store i32 20, i32* %8
br label %11
11: ; preds = %29, %2
%12 = load i32, i32* %8
%13 = icmp slt i32 %12, 80
br i1 %13, label %14, label %32
14: ; preds = %11
%15 = load i8*, i8** %4
%16 = load i32, i32* %5
%17 = mul nsw i32 30, %16
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %15, i64 %18
%20 = load i32, i32* %8
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i8, i8* %19, i64 %21
%23 = call double @red_diff_uyvy(i8* %22)
store double %23, double* %9
%24 = load double, double* %9
%25 = load double, double* %6
%26 = fadd double %25, %24
store double %26, double* %6
%27 = load i32, i32* %7
%28 = add nsw i32 %27, 1
store i32 %28, i32* %7
br label %29
29: ; preds = %14
%30 = load i32, i32* %8
%31 = add nsw i32 %30, 4
store i32 %31, i32* %8
br label %11
32: ; preds = %11
%33 = load double, double* %6
%34 = load i32, i32* %7
%35 = sitofp i32 %34 to double
%36 = fdiv double %33, %35
store double %36, double* %10
%37 = load double, double* %10
%38 = fcmp ogt double %37, 3.000000e+01
br i1 %38, label %39, label %40
39: ; preds = %32
store i32 1, i32* %3
br label %41
40: ; preds = %32
store i32 0, i32* %3
br label %41
41: ; preds = %40, %39
%42 = load i32, i32* %3
ret i32 %42
}

LLVM IR (-O2):
define i32 @find_red_flash_uyvy(i8* %0, i32 %1) {
%3 = mul nsw i32 %1, 30
%4 = sext i32 %3 to i64
%5 = getelementptr inbounds i8, i8* %0, i64 %4
%6 = getelementptr inbounds i8, i8* %5, i64 20
%7 = tail call double @red_diff_uyvy(i8* %6)
%8 = fadd double %7, 0.000000e+00
%9 = getelementptr inbounds i8, i8* %5, i64 24
%10 = tail call double @red_diff_uyvy(i8* %9)
%11 = fadd double %8, %10
%12 = getelementptr inbounds i8, i8* %5, i64 28
%13 = tail call double @red_diff_uyvy(i8* %12)
%14 = fadd double %11, %13
%15 = getelementptr inbounds i8, i8* %5, i64 32
%16 = tail call double @red_diff_uyvy(i8* %15)
%17 = fadd double %14, %16
%18 = getelementptr inbounds i8, i8* %5, i64 36
%19 = tail call double @red_diff_uyvy(i8* %18)
%20 = fadd double %17, %19
%21 = getelementptr inbounds i8, i8* %5, i64 40
%22 = tail call double @red_diff_uyvy(i8* %21)
%23 = fadd double %20, %22
%24 = getelementptr inbounds i8, i8* %5, i64 44
%25 = tail call double @red_diff_uyvy(i8* %24)
%26 = fadd double %23, %25
%27 = getelementptr inbounds i8, i8* %5, i64 48
%28 = tail call double @red_diff_uyvy(i8* %27)
%29 = fadd double %26, %28
%30 = getelementptr inbounds i8, i8* %5, i64 52
%31 = tail call double @red_diff_uyvy(i8* %30)
%32 = fadd double %29, %31
%33 = getelementptr inbounds i8, i8* %5, i64 56
%34 = tail call double @red_diff_uyvy(i8* %33)
%35 = fadd double %32, %34
%36 = getelementptr inbounds i8, i8* %5, i64 60
%37 = tail call double @red_diff_uyvy(i8* %36)
%38 = fadd double %35, %37
%39 = getelementptr inbounds i8, i8* %5, i64 64
%40 = tail call double @red_diff_uyvy(i8* %39)
%41 = fadd double %38, %40
%42 = getelementptr inbounds i8, i8* %5, i64 68
%43 = tail call double @red_diff_uyvy(i8* %42)
%44 = fadd double %41, %43
%45 = getelementptr inbounds i8, i8* %5, i64 72
%46 = tail call double @red_diff_uyvy(i8* %45)
%47 = fadd double %44, %46
%48 = getelementptr inbounds i8, i8* %5, i64 76
%49 = tail call double @red_diff_uyvy(i8* %48)
%50 = fadd double %47, %49
%51 = fdiv double %50, 1.500000e+01
%52 = fcmp ogt double %51, 3.000000e+01
%53 = zext i1 %52 to i32
ret i32 %53
}