#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 uint32_t;
struct PatternGen_Tick {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ CopyTick(struct PatternGen_Tick *, struct PatternGen_Tick *);
void ApplyDither(int tick, uint32_t ditherpattern, struct PatternGen_Tick *A,
                 struct PatternGen_Tick *B, struct PatternGen_Tick *Out) {
  if ((ditherpattern >> (tick & 0b11)) & 1 == 1) {
    CopyTick(A, Out);
  } else {
    CopyTick(B, Out);
  }
}


x86 assembly (clang, -O0):
<ApplyDither>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
mov    %r8,-0x20(%rbp)
mov    -0x8(%rbp),%eax
mov    -0x4(%rbp),%ecx
and    $0x3,%ecx
sar    %cl,%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     1153 <ApplyDither+0x43>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1030 <CopyTick@plt>
jmp    1160 <ApplyDither+0x50>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1030 <CopyTick@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ApplyDither>:
and    $0x3,%dil
movzbl %dil,%eax
bt     %eax,%esi
cmovae %rcx,%rdx
mov    %rdx,%rdi
mov    %r8,%rsi
jmp    1030 <CopyTick@plt>

LLVM IR (-O0):
%struct.PatternGen_Tick = type { i32 }
define void @ApplyDither(i32 %0, i32 %1, %struct.PatternGen_Tick* %2, %struct.PatternGen_Tick* %3, %struct.PatternGen_Tick* %4) {
%6 = alloca i32
%7 = alloca i32
%8 = alloca %struct.PatternGen_Tick*
%9 = alloca %struct.PatternGen_Tick*
%10 = alloca %struct.PatternGen_Tick*
store i32 %0, i32* %6
store i32 %1, i32* %7
store %struct.PatternGen_Tick* %2, %struct.PatternGen_Tick** %8
store %struct.PatternGen_Tick* %3, %struct.PatternGen_Tick** %9
store %struct.PatternGen_Tick* %4, %struct.PatternGen_Tick** %10
%11 = load i32, i32* %7
%12 = load i32, i32* %6
%13 = and i32 %12, 3
%14 = ashr i32 %11, %13
%15 = and i32 %14, 1
%16 = icmp ne i32 %15, 0
br i1 %16, label %17, label %21
17: ; preds = %5
%18 = load %struct.PatternGen_Tick*, %struct.PatternGen_Tick** %8
%19 = load %struct.PatternGen_Tick*, %struct.PatternGen_Tick** %10
%20 = call i32 @CopyTick(%struct.PatternGen_Tick* %18, %struct.PatternGen_Tick* %19)
br label %25
21: ; preds = %5
%22 = load %struct.PatternGen_Tick*, %struct.PatternGen_Tick** %9
%23 = load %struct.PatternGen_Tick*, %struct.PatternGen_Tick** %10
%24 = call i32 @CopyTick(%struct.PatternGen_Tick* %22, %struct.PatternGen_Tick* %23)
br label %25
25: ; preds = %21, %17
ret void
}

LLVM IR (-O2):
%struct.PatternGen_Tick = type { i32 }
define void @ApplyDither(i32 %0, i32 %1, %struct.PatternGen_Tick* %2, %struct.PatternGen_Tick* %3, %struct.PatternGen_Tick* %4) {
%6 = and i32 %0, 3
%7 = shl nuw nsw i32 1, %6
%8 = and i32 %7, %1
%9 = icmp eq i32 %8, 0
%10 = select i1 %9, %struct.PatternGen_Tick* %3, %struct.PatternGen_Tick* %2
%11 = tail call i32 @CopyTick(%struct.PatternGen_Tick* %10, %struct.PatternGen_Tick* %4)
ret void
}