#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 stat {
  int /*<<< orphan*/ st_ino;
};
struct duptab {
  int dummy;
};
typedef int /*<<< orphan*/ ino_t;

/* Variables and functions */
int /*<<< orphan*/ duptab_add(struct duptab *, struct stat *,
                              int /*<<< orphan*/, int /*<<< orphan*/ *);
scalar_t__ duptab_count(struct duptab *);
int /*<<< orphan*/ *duptab_first(struct duptab *, int *, struct stat *);
struct duptab *duptab_free(struct duptab *);
struct duptab *duptab_new();
int /*<<< orphan*/ *duptab_next(struct duptab *, int *, struct stat *);
struct duptab *dedup_cluster(struct duptab *in) {
  struct duptab *out = duptab_new();
  ino_t *inos;
  int icnt, i;
  struct stat st;
  for (inos = duptab_first(in, &icnt, &st); inos != NULL;
       inos = duptab_next(in, &icnt, &st)) {
    if (icnt < 2)
      continue;
    for (i = 0; i < icnt; i++) {
      st.st_ino = inos[i];
      duptab_add(out, &st, 0, NULL);
    }
  }
  if (duptab_count(out) == 0)
    out = duptab_free(out);
  return out;
}


x86 assembly (clang, -O0):
<dedup_cluster>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x0,%al
call   1070 <duptab_new@plt>
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x1c(%rbp),%rsi
lea    -0x28(%rbp),%rdx
call   1030 <duptab_first@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1207 <dedup_cluster+0xa7>
cmpl   $0x2,-0x1c(%rbp)
jge    11a6 <dedup_cluster+0x46>
jmp    11ed <dedup_cluster+0x8d>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    11e8 <dedup_cluster+0x88>
mov    -0x18(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x28(%rbp),%rsi
xor    %edx,%edx
xor    %eax,%eax
mov    %eax,%ecx
call   1040 <duptab_add@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    11ad <dedup_cluster+0x4d>
jmp    11ed <dedup_cluster+0x8d>
mov    -0x8(%rbp),%rdi
lea    -0x1c(%rbp),%rsi
lea    -0x28(%rbp),%rdx
call   1060 <duptab_next@plt>
mov    %rax,-0x18(%rbp)
jmp    118c <dedup_cluster+0x2c>
mov    -0x10(%rbp),%rdi
call   1080 <duptab_count@plt>
cmp    $0x0,%rax
jne    1227 <dedup_cluster+0xc7>
mov    -0x10(%rbp),%rdi
call   1050 <duptab_free@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dedup_cluster>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%r14
xor    %eax,%eax
call   1070 <duptab_new@plt>
mov    %rax,%r12
lea    0xc(%rsp),%rsi
lea    0x10(%rsp),%rdx
mov    %r14,%rdi
call   1030 <duptab_first@plt>
test   %rax,%rax
je     11f6 <dedup_cluster+0x96>
mov    %rax,%rbx
lea    0x10(%rsp),%r15
lea    0xc(%rsp),%r13
jmp    11c6 <dedup_cluster+0x66>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %r13,%rsi
mov    %r15,%rdx
call   1060 <duptab_next@plt>
mov    %rax,%rbx
test   %rax,%rax
je     11f6 <dedup_cluster+0x96>
cmpl   $0x2,0xc(%rsp)
jl     11b0 <dedup_cluster+0x50>
xor    %ebp,%ebp
nop
mov    (%rbx,%rbp,4),%eax
mov    %eax,0x10(%rsp)
mov    %r12,%rdi
mov    %r15,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
call   1040 <duptab_add@plt>
add    $0x1,%rbp
movslq 0xc(%rsp),%rax
cmp    %rax,%rbp
jl     11d0 <dedup_cluster+0x70>
jmp    11b0 <dedup_cluster+0x50>
mov    %r12,%rdi
call   1080 <duptab_count@plt>
test   %rax,%rax
jne    120e <dedup_cluster+0xae>
mov    %r12,%rdi
call   1050 <duptab_free@plt>
mov    %rax,%r12
mov    %r12,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.duptab = type { i32 }
%struct.stat = type { i32 }
define %struct.duptab* @dedup_cluster(%struct.duptab* %0) {
%2 = alloca %struct.duptab*
%3 = alloca %struct.duptab*
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
%7 = alloca %struct.stat
store %struct.duptab* %0, %struct.duptab** %2
%8 = call %struct.duptab* (...) @duptab_new()
store %struct.duptab* %8, %struct.duptab** %3
%9 = load %struct.duptab*, %struct.duptab** %2
%10 = call i32* @duptab_first(%struct.duptab* %9, i32* %5, %struct.stat* %7)
store i32* %10, i32** %4
br label %11
11: ; preds = %36, %1
%12 = load i32*, i32** %4
%13 = icmp ne i32* %12, null
br i1 %13, label %14, label %39
14: ; preds = %11
%15 = load i32, i32* %5
%16 = icmp slt i32 %15, 2
br i1 %16, label %17, label %18
17: ; preds = %14
br label %36
18: ; preds = %14
store i32 0, i32* %6
br label %19
19: ; preds = %32, %18
%20 = load i32, i32* %6
%21 = load i32, i32* %5
%22 = icmp slt i32 %20, %21
br i1 %22, label %23, label %35
23: ; preds = %19
%24 = load i32*, i32** %4
%25 = load i32, i32* %6
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i32, i32* %24, i64 %26
%28 = load i32, i32* %27
%29 = getelementptr inbounds %struct.stat, %struct.stat* %7, i32 0, i32 0
store i32 %28, i32* %29
%30 = load %struct.duptab*, %struct.duptab** %3
%31 = call i32 @duptab_add(%struct.duptab* %30, %struct.stat* %7, i32 0, i32* null)
br label %32
32: ; preds = %23
%33 = load i32, i32* %6
%34 = add nsw i32 %33, 1
store i32 %34, i32* %6
br label %19
35: ; preds = %19
br label %36
36: ; preds = %35, %17
%37 = load %struct.duptab*, %struct.duptab** %2
%38 = call i32* @duptab_next(%struct.duptab* %37, i32* %5, %struct.stat* %7)
store i32* %38, i32** %4
br label %11
39: ; preds = %11
%40 = load %struct.duptab*, %struct.duptab** %3
%41 = call i64 @duptab_count(%struct.duptab* %40)
%42 = icmp eq i64 %41, 0
br i1 %42, label %43, label %46
43: ; preds = %39
%44 = load %struct.duptab*, %struct.duptab** %3
%45 = call %struct.duptab* @duptab_free(%struct.duptab* %44)
store %struct.duptab* %45, %struct.duptab** %3
br label %46
46: ; preds = %43, %39
%47 = load %struct.duptab*, %struct.duptab** %3
ret %struct.duptab* %47
}

LLVM IR (-O2):
%struct.duptab = type { i32 }
%struct.stat = type { i32 }
define %struct.duptab* @dedup_cluster(%struct.duptab* %0) {
%2 = alloca i32
%3 = alloca %struct.stat
%4 = tail call %struct.duptab* (...) @duptab_new()
%5 = bitcast i32* %2 to i8*
%6 = bitcast %struct.stat* %3 to i8*
%7 = call i32* @duptab_first(%struct.duptab* %0, i32* %2, %struct.stat* %3)
%8 = icmp eq i32* %7, null
br i1 %8, label %27, label %9
9: ; preds = %1
%10 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
br label %11
11: ; preds = %9, %24
%12 = phi i32* [ %7, %9 ], [ %25, %24 ]
%13 = load i32, i32* %2
%14 = icmp sgt i32 %13, 1
br i1 %14, label %15, label %24
15: ; preds = %11, %15
%16 = phi i64 [ %20, %15 ], [ 0, %11 ]
%17 = getelementptr inbounds i32, i32* %12, i64 %16
%18 = load i32, i32* %17
store i32 %18, i32* %10
%19 = call i32 @duptab_add(%struct.duptab* %4, %struct.stat* %3, i32 0, i32* null)
%20 = add nuw nsw i64 %16, 1
%21 = load i32, i32* %2
%22 = sext i32 %21 to i64
%23 = icmp slt i64 %20, %22
br i1 %23, label %15, label %24
24: ; preds = %15, %11
%25 = call i32* @duptab_next(%struct.duptab* %0, i32* %2, %struct.stat* %3)
%26 = icmp eq i32* %25, null
br i1 %26, label %27, label %11
27: ; preds = %24, %1
%28 = call i64 @duptab_count(%struct.duptab* %4)
%29 = icmp eq i64 %28, 0
br i1 %29, label %30, label %32
30: ; preds = %27
%31 = call %struct.duptab* @duptab_free(%struct.duptab* %4)
br label %32
32: ; preds = %30, %27
%33 = phi %struct.duptab* [ %31, %30 ], [ %4, %27 ]
ret %struct.duptab* %33
}