#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 pmm_model {
  int dummy;
};
struct pmm_benchmark {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ insert_bench(struct pmm_model *, struct pmm_benchmark *);
struct pmm_benchmark *lookup_model(struct pmm_model *, int *);
int /*<<< orphan*/ printf(char *);
int remove_benchmarks_at_param(struct pmm_model *, int *,
                               struct pmm_benchmark ***);
struct pmm_benchmark *find_oldapprox(struct pmm_model *m, int *p) {
  struct pmm_benchmark *b;
  struct pmm_benchmark **removed_benchmarks_array;
  int i;
  int n_removed;
  n_removed = remove_benchmarks_at_param(m, p, &removed_benchmarks_array);
  b = lookup_model(m, p);
  if (b == NULL) {
    printf("Error looking up model.\n");
  }
  for (i = 0; i < n_removed; i++) {
    insert_bench(m, removed_benchmarks_array[i]);
  }
  return b;
}


x86 assembly (clang, -O0):
<find_oldapprox>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
lea    -0x20(%rbp),%rdx
call   1040 <remove_benchmarks_at_param@plt>
mov    %eax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1060 <lookup_model@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    118c <find_oldapprox+0x4c>
lea    0xe79(%rip),%rdi
call   1050 <printf@plt>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x28(%rbp),%eax
jge    11c2 <find_oldapprox+0x82>
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
call   1030 <insert_bench@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1193 <find_oldapprox+0x53>
mov    -0x18(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<find_oldapprox>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbp
mov    %rdi,%r12
lea    0x8(%rsp),%rdx
call   1050 <remove_benchmarks_at_param@plt>
mov    %eax,%r15d
mov    %r12,%rdi
mov    %rbp,%rsi
call   1060 <lookup_model@plt>
mov    %rax,%r14
test   %rax,%rax
je     1179 <find_oldapprox+0x39>
test   %r15d,%r15d
jg     118a <find_oldapprox+0x4a>
jmp    11aa <find_oldapprox+0x6a>
lea    0xe80(%rip),%rdi
call   1040 <puts@plt>
test   %r15d,%r15d
jle    11aa <find_oldapprox+0x6a>
mov    %r15d,%ebp
xor    %ebx,%ebx
nop
mov    0x8(%rsp),%rax
mov    (%rax,%rbx,8),%rsi
mov    %r12,%rdi
call   1030 <insert_bench@plt>
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1190 <find_oldapprox+0x50>
mov    %r14,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.pmm_benchmark = type { i32 }
%struct.pmm_model = type { i32 }
@.str = [25 x i8] c"Error looking up model.\0A\00"
define %struct.pmm_benchmark* @find_oldapprox(%struct.pmm_model* %0, i32* %1) {
%3 = alloca %struct.pmm_model*
%4 = alloca i32*
%5 = alloca %struct.pmm_benchmark*
%6 = alloca %struct.pmm_benchmark**
%7 = alloca i32
%8 = alloca i32
store %struct.pmm_model* %0, %struct.pmm_model** %3
store i32* %1, i32** %4
%9 = load %struct.pmm_model*, %struct.pmm_model** %3
%10 = load i32*, i32** %4
%11 = call i32 @remove_benchmarks_at_param(%struct.pmm_model* %9, i32* %10, %struct.pmm_benchmark*** %6)
store i32 %11, i32* %8
%12 = load %struct.pmm_model*, %struct.pmm_model** %3
%13 = load i32*, i32** %4
%14 = call %struct.pmm_benchmark* @lookup_model(%struct.pmm_model* %12, i32* %13)
store %struct.pmm_benchmark* %14, %struct.pmm_benchmark** %5
%15 = load %struct.pmm_benchmark*, %struct.pmm_benchmark** %5
%16 = icmp eq %struct.pmm_benchmark* %15, null
br i1 %16, label %17, label %19
17: ; preds = %2
%18 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
br label %19
19: ; preds = %17, %2
store i32 0, i32* %7
br label %20
20: ; preds = %32, %19
%21 = load i32, i32* %7
%22 = load i32, i32* %8
%23 = icmp slt i32 %21, %22
br i1 %23, label %24, label %35
24: ; preds = %20
%25 = load %struct.pmm_model*, %struct.pmm_model** %3
%26 = load %struct.pmm_benchmark**, %struct.pmm_benchmark*** %6
%27 = load i32, i32* %7
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds %struct.pmm_benchmark*, %struct.pmm_benchmark** %26, i64 %28
%30 = load %struct.pmm_benchmark*, %struct.pmm_benchmark** %29
%31 = call i32 @insert_bench(%struct.pmm_model* %25, %struct.pmm_benchmark* %30)
br label %32
32: ; preds = %24
%33 = load i32, i32* %7
%34 = add nsw i32 %33, 1
store i32 %34, i32* %7
br label %20
35: ; preds = %20
%36 = load %struct.pmm_benchmark*, %struct.pmm_benchmark** %5
ret %struct.pmm_benchmark* %36
}

LLVM IR (-O2):
%struct.pmm_benchmark = type { i32 }
%struct.pmm_model = type { i32 }
@str = [24 x i8] c"Error looking up model.\00"
define %struct.pmm_benchmark* @find_oldapprox(%struct.pmm_model* %0, i32* %1) {
%3 = alloca %struct.pmm_benchmark**
%4 = bitcast %struct.pmm_benchmark*** %3 to i8*
%5 = call i32 @remove_benchmarks_at_param(%struct.pmm_model* %0, i32* %1, %struct.pmm_benchmark*** %3)
%6 = call %struct.pmm_benchmark* @lookup_model(%struct.pmm_model* %0, i32* %1)
%7 = icmp eq %struct.pmm_benchmark* %6, null
br i1 %7, label %8, label %10
8: ; preds = %2
%9 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str, i64 0, i64 0))
br label %10
10: ; preds = %8, %2
%11 = icmp sgt i32 %5, 0
br i1 %11, label %12, label %22
12: ; preds = %10
%13 = zext i32 %5 to i64
br label %14
14: ; preds = %12, %14
%15 = phi i64 [ 0, %12 ], [ %20, %14 ]
%16 = load %struct.pmm_benchmark**, %struct.pmm_benchmark*** %3
%17 = getelementptr inbounds %struct.pmm_benchmark*, %struct.pmm_benchmark** %16, i64 %15
%18 = load %struct.pmm_benchmark*, %struct.pmm_benchmark** %17
%19 = call i32 @insert_bench(%struct.pmm_model* %0, %struct.pmm_benchmark* %18)
%20 = add nuw nsw i64 %15, 1
%21 = icmp eq i64 %20, %13
br i1 %21, label %22, label %14
22: ; preds = %14, %10
ret %struct.pmm_benchmark* %6
}