#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 */
unsigned int *skip_fields(unsigned int const *, int);
const unsigned int *sphinx_get_field_factors(const unsigned int *in,
                                             int field) {
  if (!in || field < 0 || field >= (int)in[5])
    return NULL;
  in = skip_fields(in, field);
  if (!in[0])
    return NULL;
  if ((int)in[1] != field)
    return NULL;
  return in;
}


x86 assembly (clang, -O0):
<sphinx_get_field_factors>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1144 <sphinx_get_field_factors+0x34>
cmpl   $0x0,-0x14(%rbp)
jl     1144 <sphinx_get_field_factors+0x34>
mov    -0x14(%rbp),%eax
mov    -0x10(%rbp),%rcx
cmp    0x14(%rcx),%eax
jl     1151 <sphinx_get_field_factors+0x41>
movq   $0x0,-0x8(%rbp)
jmp    11a0 <sphinx_get_field_factors+0x90>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1030 <skip_fields@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
cmpl   $0x0,(%rax)
jne    117b <sphinx_get_field_factors+0x6b>
movq   $0x0,-0x8(%rbp)
jmp    11a0 <sphinx_get_field_factors+0x90>
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%eax
cmp    -0x14(%rbp),%eax
je     1198 <sphinx_get_field_factors+0x88>
movq   $0x0,-0x8(%rbp)
jmp    11a0 <sphinx_get_field_factors+0x90>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sphinx_get_field_factors>:
push   %rbx
xor    %eax,%eax
test   %rdi,%rdi
je     113b <sphinx_get_field_factors+0x2b>
mov    %esi,%ebx
test   %esi,%esi
js     113b <sphinx_get_field_factors+0x2b>
cmp    %ebx,0x14(%rdi)
jle    113d <sphinx_get_field_factors+0x2d>
mov    %ebx,%esi
call   1030 <skip_fields@plt>
cmpl   $0x0,(%rax)
je     113d <sphinx_get_field_factors+0x2d>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %ebx,0x4(%rcx)
cmove  %rcx,%rax
pop    %rbx
ret
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
define i32* @sphinx_get_field_factors(i32* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca i32
store i32* %0, i32** %4
store i32 %1, i32* %5
%6 = load i32*, i32** %4
%7 = icmp ne i32* %6, null
br i1 %7, label %8, label %17
8: ; preds = %2
%9 = load i32, i32* %5
%10 = icmp slt i32 %9, 0
br i1 %10, label %17, label %11
11: ; preds = %8
%12 = load i32, i32* %5
%13 = load i32*, i32** %4
%14 = getelementptr inbounds i32, i32* %13, i64 5
%15 = load i32, i32* %14
%16 = icmp sge i32 %12, %15
br i1 %16, label %17, label %18
17: ; preds = %11, %8, %2
store i32* null, i32** %3
br label %36
18: ; preds = %11
%19 = load i32*, i32** %4
%20 = load i32, i32* %5
%21 = call i32* @skip_fields(i32* %19, i32 %20)
store i32* %21, i32** %4
%22 = load i32*, i32** %4
%23 = getelementptr inbounds i32, i32* %22, i64 0
%24 = load i32, i32* %23
%25 = icmp ne i32 %24, 0
br i1 %25, label %27, label %26
26: ; preds = %18
store i32* null, i32** %3
br label %36
27: ; preds = %18
%28 = load i32*, i32** %4
%29 = getelementptr inbounds i32, i32* %28, i64 1
%30 = load i32, i32* %29
%31 = load i32, i32* %5
%32 = icmp ne i32 %30, %31
br i1 %32, label %33, label %34
33: ; preds = %27
store i32* null, i32** %3
br label %36
34: ; preds = %27
%35 = load i32*, i32** %4
store i32* %35, i32** %3
br label %36
36: ; preds = %34, %33, %26, %17
%37 = load i32*, i32** %3
ret i32* %37
}

LLVM IR (-O2):
define i32* @sphinx_get_field_factors(i32* %0, i32 %1) {
%3 = icmp eq i32* %0, null
%4 = icmp slt i32 %1, 0
%5 = or i1 %3, %4
br i1 %5, label %19, label %6
6: ; preds = %2
%7 = getelementptr inbounds i32, i32* %0, i64 5
%8 = load i32, i32* %7
%9 = icmp sgt i32 %8, %1
br i1 %9, label %10, label %19
10: ; preds = %6
%11 = tail call i32* @skip_fields(i32* %0, i32 %1)
%12 = load i32, i32* %11
%13 = icmp eq i32 %12, 0
br i1 %13, label %19, label %14
14: ; preds = %10
%15 = getelementptr inbounds i32, i32* %11, i64 1
%16 = load i32, i32* %15
%17 = icmp eq i32 %16, %1
%18 = select i1 %17, i32* %11, i32* null
br label %19
19: ; preds = %14, %10, %2, %6
%20 = phi i32* [ null, %6 ], [ null, %2 ], [ null, %10 ], [ %18, %14 ]
ret i32* %20
}