#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*/ uint8_t;

/* Variables and functions */
int /*<<< orphan*/ blit_packed422_scanline(int /*<<< orphan*/ *,
                                           int /*<<< orphan*/ *, int);
void pulldown_merge_fields(uint8_t *output, uint8_t *topfield,
                           uint8_t *botfield, int width, int frame_height,
                           int fieldstride, int outstride) {
  int i;
  for (i = 0; i < frame_height; i++) {
    uint8_t *curoutput = output + (i * outstride);
    if (i & 1) {
      blit_packed422_scanline(curoutput, botfield + ((i / 2) * fieldstride),
                              width);
    } else {
      blit_packed422_scanline(curoutput, topfield + ((i / 2) * fieldstride),
                              width);
    }
  }
}


x86 assembly (clang, -O0):
<pulldown_merge_fields>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    0x10(%rbp),%eax
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8d,-0x20(%rbp)
mov    %r9d,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x20(%rbp),%eax
jge    11d5 <pulldown_merge_fields+0xc5>
mov    -0x8(%rbp),%rax
mov    -0x28(%rbp),%ecx
imul   0x10(%rbp),%ecx
movslq %ecx,%rcx
shl    $0x2,%rcx
add    %rcx,%rax
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     119a <pulldown_merge_fields+0x8a>
mov    -0x30(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x28(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
imul   -0x24(%rbp),%eax
cltq
shl    $0x2,%rax
add    %rax,%rsi
mov    -0x1c(%rbp),%edx
call   1030 <blit_packed422_scanline@plt>
jmp    11c2 <pulldown_merge_fields+0xb2>
mov    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x28(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
imul   -0x24(%rbp),%eax
cltq
shl    $0x2,%rax
add    %rax,%rsi
mov    -0x1c(%rbp),%edx
call   1030 <blit_packed422_scanline@plt>
jmp    11c7 <pulldown_merge_fields+0xb7>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1139 <pulldown_merge_fields+0x29>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pulldown_merge_fields>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
test   %r8d,%r8d
jle    1184 <pulldown_merge_fields+0x74>
mov    %r9d,%r12d
mov    %ecx,%ebp
mov    %rdx,%r14
mov    %rsi,%r13
mov    %rdi,%rbx
movslq 0x50(%rsp),%rax
mov    %r8d,%ecx
mov    %rcx,0x8(%rsp)
shl    $0x2,%rax
mov    %rax,0x10(%rsp)
xor    %r15d,%r15d
nopw   0x0(%rax,%rax,1)
mov    %r15d,%eax
shr    %eax
imul   %r12d,%eax
test   $0x1,%r15b
cltq
mov    %r14,%rcx
cmove  %r13,%rcx
lea    (%rcx,%rax,4),%rsi
mov    %rbx,%rdi
mov    %ebp,%edx
call   1030 <blit_packed422_scanline@plt>
add    $0x1,%r15
add    0x10(%rsp),%rbx
cmp    %r15,0x8(%rsp)
jne    1150 <pulldown_merge_fields+0x40>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @pulldown_merge_fields(i32* %0, i32* %1, i32* %2, i32 %3, i32 %4, i32 %5, i32 %6) {
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca i32*
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32*
store i32* %0, i32** %8
store i32* %1, i32** %9
store i32* %2, i32** %10
store i32 %3, i32* %11
store i32 %4, i32* %12
store i32 %5, i32* %13
store i32 %6, i32* %14
store i32 0, i32* %15
br label %17
17: ; preds = %54, %7
%18 = load i32, i32* %15
%19 = load i32, i32* %12
%20 = icmp slt i32 %18, %19
br i1 %20, label %21, label %57
21: ; preds = %17
%22 = load i32*, i32** %8
%23 = load i32, i32* %15
%24 = load i32, i32* %14
%25 = mul nsw i32 %23, %24
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i32, i32* %22, i64 %26
store i32* %27, i32** %16
%28 = load i32, i32* %15
%29 = and i32 %28, 1
%30 = icmp ne i32 %29, 0
br i1 %30, label %31, label %42
31: ; preds = %21
%32 = load i32*, i32** %16
%33 = load i32*, i32** %10
%34 = load i32, i32* %15
%35 = sdiv i32 %34, 2
%36 = load i32, i32* %13
%37 = mul nsw i32 %35, %36
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i32, i32* %33, i64 %38
%40 = load i32, i32* %11
%41 = call i32 @blit_packed422_scanline(i32* %32, i32* %39, i32 %40)
br label %53
42: ; preds = %21
%43 = load i32*, i32** %16
%44 = load i32*, i32** %9
%45 = load i32, i32* %15
%46 = sdiv i32 %45, 2
%47 = load i32, i32* %13
%48 = mul nsw i32 %46, %47
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds i32, i32* %44, i64 %49
%51 = load i32, i32* %11
%52 = call i32 @blit_packed422_scanline(i32* %43, i32* %50, i32 %51)
br label %53
53: ; preds = %42, %31
br label %54
54: ; preds = %53
%55 = load i32, i32* %15
%56 = add nsw i32 %55, 1
store i32 %56, i32* %15
br label %17
57: ; preds = %17
ret void
}

LLVM IR (-O2):
define void @pulldown_merge_fields(i32* %0, i32* %1, i32* %2, i32 %3, i32 %4, i32 %5, i32 %6) {
%8 = icmp sgt i32 %4, 0
br i1 %8, label %9, label %27
9: ; preds = %7
%10 = sext i32 %6 to i64
%11 = zext i32 %4 to i64
br label %12
12: ; preds = %9, %12
%13 = phi i64 [ 0, %9 ], [ %25, %12 ]
%14 = mul nsw i64 %13, %10
%15 = getelementptr inbounds i32, i32* %0, i64 %14
%16 = trunc i64 %13 to i32
%17 = and i32 %16, 1
%18 = icmp eq i32 %17, 0
%19 = lshr i32 %16, 1
%20 = mul nsw i32 %19, %5
%21 = sext i32 %20 to i64
%22 = select i1 %18, i32* %1, i32* %2
%23 = getelementptr inbounds i32, i32* %22, i64 %21
%24 = tail call i32 @blit_packed422_scanline(i32* %15, i32* %23, i32 %3)
%25 = add nuw nsw i64 %13, 1
%26 = icmp eq i64 %25, %11
br i1 %26, label %27, label %12
27: ; preds = %12, %7
ret void
}