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

/* Variables and functions */
struct cache_t *cache_copy(struct cache_t *, struct cache_t *);
int /*<<< orphan*/ cache_destroy(struct cache_t **, int /*<<< orphan*/ *);
int /*<<< orphan*/ cache_get_capacity(struct cache_t *);
struct cache_t *cache_new(int /*<<< orphan*/);
struct cache_t *cache_new_copy(struct cache_t *cache) {
  struct cache_t *copy, *res;
  copy = cache_new(cache_get_capacity(cache));
  res = cache_copy(copy, cache);
  if (res == NULL)
    cache_destroy(&copy, NULL);
  return copy;
}


x86 assembly (clang, -O0):
<cache_new_copy>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <cache_get_capacity@plt>
mov    %eax,%edi
call   1040 <cache_new@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1030 <cache_copy@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1189 <cache_new_copy+0x49>
lea    -0x10(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1050 <cache_destroy@plt>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cache_new_copy>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
call   1060 <cache_get_capacity@plt>
mov    %eax,%edi
call   1040 <cache_new@plt>
mov    %rax,%rbx
mov    %rax,(%rsp)
mov    %rax,%rdi
mov    %r14,%rsi
call   1030 <cache_copy@plt>
test   %rax,%rax
jne    1178 <cache_new_copy+0x38>
mov    %rsp,%rdi
xor    %esi,%esi
call   1050 <cache_destroy@plt>
mov    (%rsp),%rbx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.cache_t = type { i32 }
define %struct.cache_t* @cache_new_copy(%struct.cache_t* %0) {
%2 = alloca %struct.cache_t*
%3 = alloca %struct.cache_t*
%4 = alloca %struct.cache_t*
store %struct.cache_t* %0, %struct.cache_t** %2
%5 = load %struct.cache_t*, %struct.cache_t** %2
%6 = call i32 @cache_get_capacity(%struct.cache_t* %5)
%7 = call %struct.cache_t* @cache_new(i32 %6)
store %struct.cache_t* %7, %struct.cache_t** %3
%8 = load %struct.cache_t*, %struct.cache_t** %3
%9 = load %struct.cache_t*, %struct.cache_t** %2
%10 = call %struct.cache_t* @cache_copy(%struct.cache_t* %8, %struct.cache_t* %9)
store %struct.cache_t* %10, %struct.cache_t** %4
%11 = load %struct.cache_t*, %struct.cache_t** %4
%12 = icmp eq %struct.cache_t* %11, null
br i1 %12, label %13, label %15
13: ; preds = %1
%14 = call i32 @cache_destroy(%struct.cache_t** %3, i32* null)
br label %15
15: ; preds = %13, %1
%16 = load %struct.cache_t*, %struct.cache_t** %3
ret %struct.cache_t* %16
}

LLVM IR (-O2):
%struct.cache_t = type { i32 }
define %struct.cache_t* @cache_new_copy(%struct.cache_t* %0) {
%2 = alloca %struct.cache_t*
%3 = bitcast %struct.cache_t** %2 to i8*
%4 = tail call i32 @cache_get_capacity(%struct.cache_t* %0)
%5 = tail call %struct.cache_t* @cache_new(i32 %4)
store %struct.cache_t* %5, %struct.cache_t** %2
%6 = tail call %struct.cache_t* @cache_copy(%struct.cache_t* %5, %struct.cache_t* %0)
%7 = icmp eq %struct.cache_t* %6, null
br i1 %7, label %8, label %11
8: ; preds = %1
%9 = call i32 @cache_destroy(%struct.cache_t** %2, i32* null)
%10 = load %struct.cache_t*, %struct.cache_t** %2
br label %11
11: ; preds = %8, %1
%12 = phi %struct.cache_t* [ %10, %8 ], [ %5, %1 ]
ret %struct.cache_t* %12
}