#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 bm_item {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ assert(struct bm_item ***);
int /*<<< orphan*/ free(struct bm_item **);
void *malloc(int);
int /*<<< orphan*/ memcpy(void *, struct bm_item **, int);
struct bm_item **shrink_list(struct bm_item ***in_out_list, size_t osize,
                             size_t nsize) {
  assert(in_out_list);
  if (nsize == 0) {
    free(*in_out_list);
    return (*in_out_list = NULL);
  }
  if (nsize >= osize)
    return *in_out_list;
  void *tmp = malloc(sizeof(struct bm_item *) * nsize);
  if (!tmp)
    return *in_out_list;
  memcpy(tmp, *in_out_list, sizeof(struct bm_item *) * nsize);
  free(*in_out_list);
  return (*in_out_list = tmp);
}


x86 assembly (clang, -O0):
<shrink_list>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <assert@plt>
cmpq   $0x0,-0x20(%rbp)
jne    118c <shrink_list+0x4c>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1030 <free@plt>
mov    -0x10(%rbp),%rax
movq   $0x0,(%rax)
movq   $0x0,-0x8(%rbp)
jmp    120d <shrink_list+0xcd>
mov    -0x20(%rbp),%rax
cmp    -0x18(%rbp),%rax
jb     11aa <shrink_list+0x6a>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x8(%rbp)
jmp    120d <shrink_list+0xcd>
mov    -0x20(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11d8 <shrink_list+0x98>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x8(%rbp)
jmp    120d <shrink_list+0xcd>
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
mov    -0x20(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edx
call   1050 <memcpy@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rax
mov    -0x10(%rbp),%rcx
mov    %rax,(%rcx)
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<shrink_list>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%rbx
mov    %rsi,%r15
mov    %rdi,%r14
call   1040 <assert@plt>
test   %rbx,%rbx
je     118f <shrink_list+0x4f>
cmp    %r15,%rbx
jae    11a2 <shrink_list+0x62>
shl    $0x3,%ebx
mov    %ebx,%edi
call   1060 <malloc@plt>
mov    %rax,%r15
mov    (%r14),%rax
test   %r15,%r15
je     11a5 <shrink_list+0x65>
mov    %r15,%rdi
mov    %rax,%rsi
mov    %ebx,%edx
call   1050 <memcpy@plt>
mov    (%r14),%rdi
call   1030 <free@plt>
mov    %r15,(%r14)
mov    %r15,%rax
jmp    11a5 <shrink_list+0x65>
mov    (%r14),%rdi
call   1030 <free@plt>
movq   $0x0,(%r14)
xor    %eax,%eax
jmp    11a5 <shrink_list+0x65>
mov    (%r14),%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.bm_item = type { i32 }
define %struct.bm_item** @shrink_list(%struct.bm_item*** %0, i64 %1, i64 %2) {
%4 = alloca %struct.bm_item**
%5 = alloca %struct.bm_item***
%6 = alloca i64
%7 = alloca i64
%8 = alloca i8*
store %struct.bm_item*** %0, %struct.bm_item**** %5
store i64 %1, i64* %6
store i64 %2, i64* %7
%9 = load %struct.bm_item***, %struct.bm_item**** %5
%10 = call i32 @assert(%struct.bm_item*** %9)
%11 = load i64, i64* %7
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %18
13: ; preds = %3
%14 = load %struct.bm_item***, %struct.bm_item**** %5
%15 = load %struct.bm_item**, %struct.bm_item*** %14
%16 = call i32 @free(%struct.bm_item** %15)
%17 = load %struct.bm_item***, %struct.bm_item**** %5
store %struct.bm_item** null, %struct.bm_item*** %17
store %struct.bm_item** null, %struct.bm_item*** %4
br label %49
18: ; preds = %3
%19 = load i64, i64* %7
%20 = load i64, i64* %6
%21 = icmp uge i64 %19, %20
br i1 %21, label %22, label %25
22: ; preds = %18
%23 = load %struct.bm_item***, %struct.bm_item**** %5
%24 = load %struct.bm_item**, %struct.bm_item*** %23
store %struct.bm_item** %24, %struct.bm_item*** %4
br label %49
25: ; preds = %18
%26 = load i64, i64* %7
%27 = mul i64 8, %26
%28 = trunc i64 %27 to i32
%29 = call i8* @malloc(i32 %28)
store i8* %29, i8** %8
%30 = load i8*, i8** %8
%31 = icmp ne i8* %30, null
br i1 %31, label %35, label %32
32: ; preds = %25
%33 = load %struct.bm_item***, %struct.bm_item**** %5
%34 = load %struct.bm_item**, %struct.bm_item*** %33
store %struct.bm_item** %34, %struct.bm_item*** %4
br label %49
35: ; preds = %25
%36 = load i8*, i8** %8
%37 = load %struct.bm_item***, %struct.bm_item**** %5
%38 = load %struct.bm_item**, %struct.bm_item*** %37
%39 = load i64, i64* %7
%40 = mul i64 8, %39
%41 = trunc i64 %40 to i32
%42 = call i32 @memcpy(i8* %36, %struct.bm_item** %38, i32 %41)
%43 = load %struct.bm_item***, %struct.bm_item**** %5
%44 = load %struct.bm_item**, %struct.bm_item*** %43
%45 = call i32 @free(%struct.bm_item** %44)
%46 = load i8*, i8** %8
%47 = bitcast i8* %46 to %struct.bm_item**
%48 = load %struct.bm_item***, %struct.bm_item**** %5
store %struct.bm_item** %47, %struct.bm_item*** %48
store %struct.bm_item** %47, %struct.bm_item*** %4
br label %49
49: ; preds = %35, %32, %22, %13
%50 = load %struct.bm_item**, %struct.bm_item*** %4
ret %struct.bm_item** %50
}

LLVM IR (-O2):
%struct.bm_item = type { i32 }
define %struct.bm_item** @shrink_list(%struct.bm_item*** %0, i64 %1, i64 %2) {
%4 = tail call i32 @assert(%struct.bm_item*** %0)
%5 = icmp eq i64 %2, 0
br i1 %5, label %6, label %9
6: ; preds = %3
%7 = load %struct.bm_item**, %struct.bm_item*** %0
%8 = tail call i32 @free(%struct.bm_item** %7)
store %struct.bm_item** null, %struct.bm_item*** %0
br label %25
9: ; preds = %3
%10 = icmp ult i64 %2, %1
br i1 %10, label %13, label %11
11: ; preds = %9
%12 = load %struct.bm_item**, %struct.bm_item*** %0
br label %25
13: ; preds = %9
%14 = trunc i64 %2 to i32
%15 = shl i32 %14, 3
%16 = tail call i8* @malloc(i32 %15)
%17 = icmp eq i8* %16, null
%18 = load %struct.bm_item**, %struct.bm_item*** %0
br i1 %17, label %25, label %19
19: ; preds = %13
%20 = tail call i32 @memcpy(i8* %16, %struct.bm_item** %18, i32 %15)
%21 = load %struct.bm_item**, %struct.bm_item*** %0
%22 = tail call i32 @free(%struct.bm_item** %21)
%23 = bitcast i8* %16 to %struct.bm_item**
%24 = bitcast %struct.bm_item*** %0 to i8**
store i8* %16, i8** %24
br label %25
25: ; preds = %13, %19, %11, %6
%26 = phi %struct.bm_item** [ null, %6 ], [ %12, %11 ], [ %23, %19 ], [ %18, %13 ]
ret %struct.bm_item** %26
}