#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 /*<<< orphan*/ assert(int);
int indexof_detector_coeff(int num_detector, int detector, int pos, int base) {
  assert(detector >= 0);
  assert(pos >= 0);
  assert(base >= 0 && base < 4);
  return detector + num_detector * (base + 4 * pos);
}


x86 assembly (clang, -O0):
<indexof_detector_coeff>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    %ecx,-0x10(%rbp)
cmpl   $0x0,-0x8(%rbp)
setge  %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
cmpl   $0x0,-0xc(%rbp)
setge  %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
xor    %eax,%eax
cmpl   $0x0,-0x10(%rbp)
mov    %al,-0x11(%rbp)
jl     115f <indexof_detector_coeff+0x4f>
cmpl   $0x4,-0x10(%rbp)
setl   %al
mov    %al,-0x11(%rbp)
mov    -0x11(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
mov    -0x8(%rbp),%eax
mov    -0x4(%rbp),%ecx
mov    -0x10(%rbp),%edx
mov    -0xc(%rbp),%esi
shl    $0x2,%esi
add    %esi,%edx
imul   %edx,%ecx
add    %ecx,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<indexof_detector_coeff>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %ecx,%ebx
mov    %edx,%ebp
mov    %esi,%r14d
mov    %edi,%r15d
mov    %esi,%edi
not    %edi
shr    $0x1f,%edi
call   1030 <assert@plt>
mov    %ebp,%edi
not    %edi
shr    $0x1f,%edi
call   1030 <assert@plt>
xor    %edi,%edi
cmp    $0x4,%ebx
setb   %dil
call   1030 <assert@plt>
lea    (%rbx,%rbp,4),%eax
imul   %r15d,%eax
add    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @indexof_detector_coeff(i32 %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%9 = load i32, i32* %6
%10 = icmp sge i32 %9, 0
%11 = zext i1 %10 to i32
%12 = call i32 @assert(i32 %11)
%13 = load i32, i32* %7
%14 = icmp sge i32 %13, 0
%15 = zext i1 %14 to i32
%16 = call i32 @assert(i32 %15)
%17 = load i32, i32* %8
%18 = icmp sge i32 %17, 0
br i1 %18, label %19, label %22
19: ; preds = %4
%20 = load i32, i32* %8
%21 = icmp slt i32 %20, 4
br label %22
22: ; preds = %19, %4
%23 = phi i1 [ false, %4 ], [ %21, %19 ]
%24 = zext i1 %23 to i32
%25 = call i32 @assert(i32 %24)
%26 = load i32, i32* %6
%27 = load i32, i32* %5
%28 = load i32, i32* %8
%29 = load i32, i32* %7
%30 = mul nsw i32 4, %29
%31 = add nsw i32 %28, %30
%32 = mul nsw i32 %27, %31
%33 = add nsw i32 %26, %32
ret i32 %33
}

LLVM IR (-O2):
define i32 @indexof_detector_coeff(i32 %0, i32 %1, i32 %2, i32 %3) {
%5 = xor i32 %1, -1
%6 = lshr i32 %5, 31
%7 = tail call i32 @assert(i32 %6)
%8 = xor i32 %2, -1
%9 = lshr i32 %8, 31
%10 = tail call i32 @assert(i32 %9)
%11 = icmp ult i32 %3, 4
%12 = zext i1 %11 to i32
%13 = tail call i32 @assert(i32 %12)
%14 = shl nsw i32 %2, 2
%15 = add nsw i32 %14, %3
%16 = mul nsw i32 %15, %0
%17 = add nsw i32 %16, %1
ret i32 %17
}