#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 */
struct ipr_dev *find_dup(struct ipr_dev *, struct ipr_dev **, int);
int remove_dup_dev(struct ipr_dev *, struct ipr_dev **, int);
int remove_conc_dups(struct ipr_dev **devs, int num_devs) {
  int i;
  struct ipr_dev *dev;
  for (i = 0; i < num_devs; i++) {
    dev = find_dup(devs[i], &devs[i + 1], (num_devs - i - 1));
    if (!dev)
      continue;
    num_devs = remove_dup_dev(dev, devs, num_devs);
  }
  return num_devs;
}


x86 assembly (clang, -O0):
<remove_conc_dups>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11a4 <remove_conc_dups+0x84>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x3,%rax
add    %rax,%rsi
mov    -0xc(%rbp),%edx
sub    -0x10(%rbp),%edx
sub    $0x1,%edx
call   1030 <find_dup@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1183 <remove_conc_dups+0x63>
jmp    1196 <remove_conc_dups+0x76>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0xc(%rbp),%edx
call   1040 <remove_dup_dev@plt>
mov    %eax,-0xc(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1136 <remove_conc_dups+0x16>
mov    -0xc(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<remove_conc_dups>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %esi,%r15d
test   %esi,%esi
jle    118c <remove_conc_dups+0x6c>
mov    %rdi,%r14
lea    0x8(%rdi),%rbx
mov    $0xffffffff,%r12d
xor    %r13d,%r13d
jmp    1160 <remove_conc_dups+0x40>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movslq %r15d,%rax
add    $0x8,%rbx
add    $0xffffffff,%r12d
cmp    %rax,%r13
jge    118c <remove_conc_dups+0x6c>
mov    -0x8(%rbx),%rdi
add    $0x1,%r13
lea    (%r15,%r12,1),%edx
mov    %rbx,%rsi
call   1030 <find_dup@plt>
test   %rax,%rax
je     1150 <remove_conc_dups+0x30>
mov    %rax,%rdi
mov    %r14,%rsi
mov    %r15d,%edx
call   1040 <remove_dup_dev@plt>
mov    %eax,%r15d
jmp    1150 <remove_conc_dups+0x30>
mov    %r15d,%eax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
%struct.ipr_dev = type { i32 }
define i32 @remove_conc_dups(%struct.ipr_dev** %0, i32 %1) {
%3 = icmp sgt i32 %1, 0
br i1 %3, label %4, label %22
4: ; preds = %2, %18
%5 = phi i64 [ %9, %18 ], [ 0, %2 ]
%6 = phi i32 [ %19, %18 ], [ %1, %2 ]
%7 = getelementptr inbounds %struct.ipr_dev*, %struct.ipr_dev** %0, i64 %5
%8 = load %struct.ipr_dev*, %struct.ipr_dev** %7
%9 = add nuw nsw i64 %5, 1
%10 = getelementptr inbounds %struct.ipr_dev*, %struct.ipr_dev** %0, i64 %9
%11 = trunc i64 %5 to i32
%12 = xor i32 %11, -1
%13 = add i32 %6, %12
%14 = tail call %struct.ipr_dev* @find_dup(%struct.ipr_dev* %8, %struct.ipr_dev** %10, i32 %13)
%15 = icmp eq %struct.ipr_dev* %14, null
br i1 %15, label %18, label %16
16: ; preds = %4
%17 = tail call i32 @remove_dup_dev(%struct.ipr_dev* %14, %struct.ipr_dev** %0, i32 %6)
br label %18
18: ; preds = %4, %16
%19 = phi i32 [ %17, %16 ], [ %6, %4 ]
%20 = sext i32 %19 to i64
%21 = icmp slt i64 %9, %20
br i1 %21, label %4, label %22
22: ; preds = %18, %2
%23 = phi i32 [ %1, %2 ], [ %19, %18 ]
ret i32 %23
}