#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 */

/* Variables and functions */
int /*<<< orphan*/ assert(int *);
int /*<<< orphan*/ memcpy(int *, int *, int);
int /*<<< orphan*/ my_free(int, int *);
int my_malloc(int, int **);
int main() {
  int *x;
  int *a;
  int retval = my_malloc(100, &a);
  if (retval == 1) {
    retval = my_malloc(100, &x);
    if (retval != 1) {
      my_free(100, x);
      return 0;
    }
  } else {
    my_free(100, a);
    return 0;
  }
  assert(a);
  assert(x);
  memcpy(a, x, 100);
  return 1;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x64,%edi
lea    -0x18(%rbp),%rsi
call   1030 <my_malloc@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x1,-0x1c(%rbp)
jne    11a4 <main+0x64>
mov    $0x64,%edi
lea    -0x10(%rbp),%rsi
call   1030 <my_malloc@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x1,-0x1c(%rbp)
je     119f <main+0x5f>
mov    -0x10(%rbp),%rsi
mov    $0x64,%edi
call   1060 <my_free@plt>
movl   $0x0,-0x4(%rbp)
jmp    11e9 <main+0xa9>
jmp    11be <main+0x7e>
mov    -0x18(%rbp),%rsi
mov    $0x64,%edi
call   1060 <my_free@plt>
movl   $0x0,-0x4(%rbp)
jmp    11e9 <main+0xa9>
mov    -0x18(%rbp),%rdi
call   1040 <assert@plt>
mov    -0x10(%rbp),%rdi
call   1040 <assert@plt>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0x64,%edx
call   1050 <memcpy@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0x18,%rsp
lea    0x8(%rsp),%rsi
mov    $0x64,%edi
call   1030 <my_malloc@plt>
cmp    $0x1,%eax
jne    119e <main+0x5e>
lea    0x10(%rsp),%rsi
mov    $0x64,%edi
call   1030 <my_malloc@plt>
cmp    $0x1,%eax
jne    11a5 <main+0x65>
mov    0x8(%rsp),%rdi
call   1040 <assert@plt>
mov    0x10(%rsp),%rdi
call   1040 <assert@plt>
mov    0x8(%rsp),%rdi
mov    0x10(%rsp),%rsi
mov    $0x64,%edx
call   1050 <memcpy@plt>
mov    $0x1,%eax
add    $0x18,%rsp
ret
mov    0x8(%rsp),%rsi
jmp    11aa <main+0x6a>
mov    0x10(%rsp),%rsi
mov    $0x64,%edi
call   1060 <my_free@plt>
xor    %eax,%eax
add    $0x18,%rsp
ret

LLVM IR (-O0):
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32*
%4 = alloca i32
store i32 0, i32* %1
%5 = call i32 @my_malloc(i32 100, i32** %3)
store i32 %5, i32* %4
%6 = load i32, i32* %4
%7 = icmp eq i32 %6, 1
br i1 %7, label %8, label %16
8: ; preds = %0
%9 = call i32 @my_malloc(i32 100, i32** %2)
store i32 %9, i32* %4
%10 = load i32, i32* %4
%11 = icmp ne i32 %10, 1
br i1 %11, label %12, label %15
12: ; preds = %8
%13 = load i32*, i32** %2
%14 = call i32 @my_free(i32 100, i32* %13)
store i32 0, i32* %1
br label %27
15: ; preds = %8
br label %19
16: ; preds = %0
%17 = load i32*, i32** %3
%18 = call i32 @my_free(i32 100, i32* %17)
store i32 0, i32* %1
br label %27
19: ; preds = %15
%20 = load i32*, i32** %3
%21 = call i32 @assert(i32* %20)
%22 = load i32*, i32** %2
%23 = call i32 @assert(i32* %22)
%24 = load i32*, i32** %3
%25 = load i32*, i32** %2
%26 = call i32 @memcpy(i32* %24, i32* %25, i32 100)
store i32 1, i32* %1
br label %27
27: ; preds = %19, %16, %12
%28 = load i32, i32* %1
ret i32 %28
}

LLVM IR (-O2):
define i32 @main() {
%1 = alloca i32*
%2 = alloca i32*
%3 = bitcast i32** %1 to i8*
%4 = bitcast i32** %2 to i8*
%5 = call i32 @my_malloc(i32 100, i32** %2)
%6 = icmp eq i32 %5, 1
br i1 %6, label %7, label %13
7: ; preds = %0
%8 = call i32 @my_malloc(i32 100, i32** %1)
%9 = icmp eq i32 %8, 1
br i1 %9, label %16, label %10
10: ; preds = %7
%11 = load i32*, i32** %1
%12 = call i32 @my_free(i32 100, i32* %11)
br label %24
13: ; preds = %0
%14 = load i32*, i32** %2
%15 = call i32 @my_free(i32 100, i32* %14)
br label %24
16: ; preds = %7
%17 = load i32*, i32** %2
%18 = call i32 @assert(i32* %17)
%19 = load i32*, i32** %1
%20 = call i32 @assert(i32* %19)
%21 = load i32*, i32** %2
%22 = load i32*, i32** %1
%23 = call i32 @memcpy(i32* %21, i32* %22, i32 100)
br label %24
24: ; preds = %16, %13, %10
%25 = phi i32 [ 0, %10 ], [ 1, %16 ], [ 0, %13 ]
ret i32 %25
}