#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 scalar_t__ const pid_t;

/* Variables and functions */
int find_pid_in_list(const pid_t *list, pid_t val) {
  int ret = 0;
  while (list && *(list)) {
    if (*list == val)
      return ret;
    ret++;
    list++;
  }
  return -1;
}


x86 assembly (clang, -O0):
<find_pid_in_list>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x10(%rbp)
mov    %al,-0x1d(%rbp)
je     1131 <find_pid_in_list+0x31>
mov    -0x10(%rbp),%rax
cmpq   $0x0,(%rax)
setne  %al
mov    %al,-0x1d(%rbp)
mov    -0x1d(%rbp),%al
test   $0x1,%al
jne    1141 <find_pid_in_list+0x41>
jmp    1177 <find_pid_in_list+0x77>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
cmp    -0x18(%rbp),%rax
jne    115d <find_pid_in_list+0x5d>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    117e <find_pid_in_list+0x7e>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x10(%rbp)
jmp    1113 <find_pid_in_list+0x13>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<find_pid_in_list>:
mov    $0xffffffff,%eax
test   %rdi,%rdi
je     1133 <find_pid_in_list+0x33>
mov    (%rdi),%rdx
test   %rdx,%rdx
je     1133 <find_pid_in_list+0x33>
xor    %ecx,%ecx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
cmp    %rsi,%rdx
je     1134 <find_pid_in_list+0x34>
mov    0x8(%rdi,%rcx,8),%rdx
add    $0x1,%rcx
test   %rdx,%rdx
jne    1120 <find_pid_in_list+0x20>
ret
mov    %ecx,%eax
ret

LLVM IR (-O0):
define i32 @find_pid_in_list(i64* %0, i64 %1) {
%3 = alloca i32
%4 = alloca i64*
%5 = alloca i64
%6 = alloca i32
store i64* %0, i64** %4
store i64 %1, i64* %5
store i32 0, i32* %6
br label %7
7: ; preds = %23, %2
%8 = load i64*, i64** %4
%9 = icmp ne i64* %8, null
br i1 %9, label %10, label %14
10: ; preds = %7
%11 = load i64*, i64** %4
%12 = load i64, i64* %11
%13 = icmp ne i64 %12, 0
br label %14
14: ; preds = %10, %7
%15 = phi i1 [ false, %7 ], [ %13, %10 ]
br i1 %15, label %16, label %28
16: ; preds = %14
%17 = load i64*, i64** %4
%18 = load i64, i64* %17
%19 = load i64, i64* %5
%20 = icmp eq i64 %18, %19
br i1 %20, label %21, label %23
21: ; preds = %16
%22 = load i32, i32* %6
store i32 %22, i32* %3
br label %29
23: ; preds = %16
%24 = load i32, i32* %6
%25 = add nsw i32 %24, 1
store i32 %25, i32* %6
%26 = load i64*, i64** %4
%27 = getelementptr inbounds i64, i64* %26, i32 1
store i64* %27, i64** %4
br label %7
28: ; preds = %14
store i32 -1, i32* %3
br label %29
29: ; preds = %28, %21
%30 = load i32, i32* %3
ret i32 %30
}

LLVM IR (-O2):
define i32 @find_pid_in_list(i64* %0, i64 %1) {
%3 = icmp eq i64* %0, null
br i1 %3, label %17, label %4
4: ; preds = %2
%5 = load i64, i64* %0
%6 = icmp eq i64 %5, 0
br i1 %6, label %17, label %7
7: ; preds = %4, %12
%8 = phi i64 [ %15, %12 ], [ %5, %4 ]
%9 = phi i64* [ %14, %12 ], [ %0, %4 ]
%10 = phi i32 [ %13, %12 ], [ 0, %4 ]
%11 = icmp eq i64 %8, %1
br i1 %11, label %17, label %12
12: ; preds = %7
%13 = add nuw nsw i32 %10, 1
%14 = getelementptr inbounds i64, i64* %9, i64 1
%15 = load i64, i64* %14
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %7
17: ; preds = %12, %7, %4, %2
%18 = phi i32 [ -1, %2 ], [ -1, %4 ], [ %10, %7 ], [ -1, %12 ]
ret i32 %18
}