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

/* Variables and functions */
struct hashmap *hashmap_create();
int /*<<< orphan*/ hashmap_destroy(struct hashmap *);
int /*<<< orphan*/ hashmap_merge(struct hashmap *, struct hashmap *);
struct hashmap *hashmap_clone(struct hashmap *this) {
  struct hashmap *clone = hashmap_create();
  if (!clone) {
    return NULL;
  }
  if (!hashmap_merge(clone, this)) {
    hashmap_destroy(clone);
    return NULL;
  }
  return clone;
}


x86 assembly (clang, -O0):
<hashmap_clone>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    $0x0,%al
call   1030 <hashmap_create@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    115f <hashmap_clone+0x2f>
movq   $0x0,-0x8(%rbp)
jmp    1193 <hashmap_clone+0x63>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <hashmap_merge@plt>
cmp    $0x0,%eax
jne    118b <hashmap_clone+0x5b>
mov    -0x18(%rbp),%rdi
call   1040 <hashmap_destroy@plt>
movq   $0x0,-0x8(%rbp)
jmp    1193 <hashmap_clone+0x63>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hashmap_clone>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
xor    %eax,%eax
call   1030 <hashmap_create@plt>
test   %rax,%rax
je     115d <hashmap_clone+0x2d>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r14,%rsi
call   1050 <hashmap_merge@plt>
test   %eax,%eax
jne    115f <hashmap_clone+0x2f>
mov    %rbx,%rdi
call   1040 <hashmap_destroy@plt>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.hashmap = type { i32 }
define %struct.hashmap* @hashmap_clone(%struct.hashmap* %0) {
%2 = alloca %struct.hashmap*
%3 = alloca %struct.hashmap*
%4 = alloca %struct.hashmap*
store %struct.hashmap* %0, %struct.hashmap** %3
%5 = call %struct.hashmap* (...) @hashmap_create()
store %struct.hashmap* %5, %struct.hashmap** %4
%6 = load %struct.hashmap*, %struct.hashmap** %4
%7 = icmp ne %struct.hashmap* %6, null
br i1 %7, label %9, label %8
8: ; preds = %1
store %struct.hashmap* null, %struct.hashmap** %2
br label %19
9: ; preds = %1
%10 = load %struct.hashmap*, %struct.hashmap** %4
%11 = load %struct.hashmap*, %struct.hashmap** %3
%12 = call i32 @hashmap_merge(%struct.hashmap* %10, %struct.hashmap* %11)
%13 = icmp ne i32 %12, 0
br i1 %13, label %17, label %14
14: ; preds = %9
%15 = load %struct.hashmap*, %struct.hashmap** %4
%16 = call i32 @hashmap_destroy(%struct.hashmap* %15)
store %struct.hashmap* null, %struct.hashmap** %2
br label %19
17: ; preds = %9
%18 = load %struct.hashmap*, %struct.hashmap** %4
store %struct.hashmap* %18, %struct.hashmap** %2
br label %19
19: ; preds = %17, %14, %8
%20 = load %struct.hashmap*, %struct.hashmap** %2
ret %struct.hashmap* %20
}

LLVM IR (-O2):
%struct.hashmap = type { i32 }
define %struct.hashmap* @hashmap_clone(%struct.hashmap* %0) {
%2 = tail call %struct.hashmap* (...) @hashmap_create()
%3 = icmp eq %struct.hashmap* %2, null
br i1 %3, label %9, label %4
4: ; preds = %1
%5 = tail call i32 @hashmap_merge(%struct.hashmap* %2, %struct.hashmap* %0)
%6 = icmp eq i32 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %4
%8 = tail call i32 @hashmap_destroy(%struct.hashmap* %2)
br label %9
9: ; preds = %4, %1, %7
%10 = phi %struct.hashmap* [ null, %7 ], [ null, %1 ], [ %2, %4 ]
ret %struct.hashmap* %10
}