#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 */
struct ipr_dev {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ free_empty_slot(struct ipr_dev *);
int remove_dup_dev(struct ipr_dev *dev, struct ipr_dev **devs, int num_devs) {
  int i, j;
  for (i = 0; i < num_devs; i++) {
    if (dev == devs[i]) {
      free_empty_slot(dev);
      devs[i] = NULL;
      for (j = (i + 1); j < num_devs; j++) {
        devs[j - 1] = devs[j];
        devs[j] = NULL;
      }
      return (num_devs - 1);
    }
  }
  return num_devs;
}


x86 assembly (clang, -O0):
<remove_dup_dev>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    11d6 <remove_dup_dev+0xc6>
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
movslq -0x20(%rbp),%rdx
cmp    (%rcx,%rdx,8),%rax
jne    11c3 <remove_dup_dev+0xb3>
mov    -0x10(%rbp),%rdi
call   1030 <free_empty_slot@plt>
mov    -0x18(%rbp),%rax
movslq -0x20(%rbp),%rcx
movq   $0x0,(%rax,%rcx,8)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    11b5 <remove_dup_dev+0xa5>
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
mov    -0x18(%rbp),%rax
mov    -0x24(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
movq   $0x0,(%rax,%rcx,8)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    116e <remove_dup_dev+0x5e>
mov    -0x1c(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    11dc <remove_dup_dev+0xcc>
jmp    11c8 <remove_dup_dev+0xb8>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    112a <remove_dup_dev+0x1a>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<remove_dup_dev>:
push   %r15
push   %r14
push   %rbx
mov    %edx,%eax
test   %edx,%edx
jle    11cc <remove_dup_dev+0xbc>
mov    %edx,%r14d
mov    %rsi,%r15
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
cmp    %rdi,(%r15,%rbx,8)
je     1144 <remove_dup_dev+0x34>
add    $0x1,%rbx
cmp    %rbx,%rax
jne    1130 <remove_dup_dev+0x20>
jmp    11cc <remove_dup_dev+0xbc>
call   1030 <free_empty_slot@plt>
movq   $0x0,(%r15,%rbx,8)
lea    0x1(%rbx),%ecx
lea    -0x1(%r14),%eax
cmp    %r14d,%ecx
jge    11cc <remove_dup_dev+0xbc>
mov    %eax,%ecx
mov    %eax,%esi
sub    %ebx,%esi
mov    %rbx,%rdx
test   $0x1,%sil
je     1182 <remove_dup_dev+0x72>
lea    0x1(%rbx),%rdx
mov    0x8(%r15,%rbx,8),%rsi
mov    %rsi,(%r15,%rbx,8)
movq   $0x0,0x8(%r15,%rbx,8)
lea    -0x1(%rcx),%rsi
cmp    %rbx,%rsi
je     11cc <remove_dup_dev+0xbc>
sub    %rdx,%rcx
lea    (%r15,%rdx,8),%rsi
add    $0x8,%rsi
lea    (%r15,%rdx,8),%rdx
add    $0x10,%rdx
xor    %edi,%edi
mov    -0x8(%rdx,%rdi,8),%rbx
mov    %rbx,-0x8(%rsi,%rdi,8)
movq   $0x0,-0x8(%rdx,%rdi,8)
mov    (%rdx,%rdi,8),%rbx
mov    %rbx,(%rsi,%rdi,8)
movq   $0x0,(%rdx,%rdi,8)
add    $0x2,%rdi
cmp    %rdi,%rcx
jne    11a0 <remove_dup_dev+0x90>
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
%struct.ipr_dev = type { i32 }
define i32 @remove_dup_dev(%struct.ipr_dev* %0, %struct.ipr_dev** nocapture %1, i32 %2) {
%4 = icmp sgt i32 %2, 0
br i1 %4, label %5, label %54
5: ; preds = %3
%6 = zext i32 %2 to i64
br label %7
7: ; preds = %5, %51
%8 = phi i64 [ 0, %5 ], [ %52, %51 ]
%9 = getelementptr inbounds %struct.ipr_dev*, %struct.ipr_dev** %1, i64 %8
%10 = load %struct.ipr_dev*, %struct.ipr_dev** %9
%11 = icmp eq %struct.ipr_dev* %10, %0
br i1 %11, label %12, label %51
12: ; preds = %7
%13 = trunc i64 %8 to i32
%14 = and i64 %8, 4294967295
%15 = getelementptr inbounds %struct.ipr_dev*, %struct.ipr_dev** %1, i64 %14
%16 = tail call i32 @free_empty_slot(%struct.ipr_dev* %0)
store %struct.ipr_dev* null, %struct.ipr_dev** %15
%17 = add nuw nsw i32 %13, 1
%18 = icmp slt i32 %17, %2
%19 = add nsw i32 %2, -1
br i1 %18, label %20, label %54
20: ; preds = %12
%21 = zext i32 %19 to i64
%22 = sub nsw i64 %21, %8
%23 = xor i64 %8, -1
%24 = and i64 %22, 1
%25 = icmp eq i64 %24, 0
br i1 %25, label %32, label %26
26: ; preds = %20
%27 = add nuw nsw i64 %8, 1
%28 = add nuw nsw i64 %8, 1
%29 = getelementptr inbounds %struct.ipr_dev*, %struct.ipr_dev** %1, i64 %27
%30 = load %struct.ipr_dev*, %struct.ipr_dev** %29
%31 = getelementptr inbounds %struct.ipr_dev*, %struct.ipr_dev** %1, i64 %8
store %struct.ipr_dev* %30, %struct.ipr_dev** %31
store %struct.ipr_dev* null, %struct.ipr_dev** %29
br label %32
32: ; preds = %26, %20
%33 = phi i64 [ %8, %20 ], [ %28, %26 ]
%34 = phi i64 [ %8, %20 ], [ %27, %26 ]
%35 = sub nsw i64 0, %21
%36 = icmp eq i64 %23, %35
br i1 %36, label %54, label %37
37: ; preds = %32, %37
%38 = phi i64 [ %46, %37 ], [ %33, %32 ]
%39 = phi i64 [ %45, %37 ], [ %34, %32 ]
%40 = add nuw nsw i64 %39, 1
%41 = add nuw nsw i64 %38, 1
%42 = getelementptr inbounds %struct.ipr_dev*, %struct.ipr_dev** %1, i64 %40
%43 = load %struct.ipr_dev*, %struct.ipr_dev** %42
%44 = getelementptr inbounds %struct.ipr_dev*, %struct.ipr_dev** %1, i64 %38
store %struct.ipr_dev* %43, %struct.ipr_dev** %44
store %struct.ipr_dev* null, %struct.ipr_dev** %42
%45 = add nuw nsw i64 %39, 2
%46 = add nuw nsw i64 %38, 2
%47 = getelementptr inbounds %struct.ipr_dev*, %struct.ipr_dev** %1, i64 %45
%48 = load %struct.ipr_dev*, %struct.ipr_dev** %47
%49 = getelementptr inbounds %struct.ipr_dev*, %struct.ipr_dev** %1, i64 %41
store %struct.ipr_dev* %48, %struct.ipr_dev** %49
store %struct.ipr_dev* null, %struct.ipr_dev** %47
%50 = icmp eq i64 %46, %21
br i1 %50, label %54, label %37
51: ; preds = %7
%52 = add nuw nsw i64 %8, 1
%53 = icmp eq i64 %52, %6
br i1 %53, label %54, label %7
54: ; preds = %51, %32, %37, %12, %3
%55 = phi i32 [ %2, %3 ], [ %19, %12 ], [ %19, %37 ], [ %19, %32 ], [ %2, %51 ]
ret i32 %55
}