#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 *malloc(int);
int *realloc(int *, int);
int main(void) {
  int *x = malloc(5);
  int *y = malloc(10);
  int *z = malloc(2);
  int a, b, c;
  x = realloc(x, 5);
  y = realloc(y, 5);
  z = realloc(z, 5);
  a = (x[5] == 0xdeadbeef ? 1 : 0);
  b = (y[5] == 0xdeadbeef ? 1 : 0);
  c = (z[5] == 0xdeadbeef ? 1 : 0);
  return a + b + c;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x5,%edi
call   1030 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    $0xa,%edi
call   1030 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    $0x2,%edi
call   1030 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x5,%esi
call   1040 <realloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%rdi
mov    $0x5,%esi
call   1040 <realloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x20(%rbp),%rdi
mov    $0x5,%esi
call   1040 <realloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0x14(%rax),%edx
xor    %eax,%eax
mov    $0x1,%ecx
cmp    $0xdeadbeef,%edx
cmove  %ecx,%eax
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%rax
mov    0x14(%rax),%edx
xor    %eax,%eax
mov    $0x1,%ecx
cmp    $0xdeadbeef,%edx
cmove  %ecx,%eax
mov    %eax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
mov    0x14(%rax),%edx
xor    %eax,%eax
mov    $0x1,%ecx
cmp    $0xdeadbeef,%edx
cmove  %ecx,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x24(%rbp),%eax
add    -0x28(%rbp),%eax
add    -0x2c(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    $0x5,%edi
call   1030 <malloc@plt>
mov    %rax,%rbx
mov    $0xa,%edi
call   1030 <malloc@plt>
mov    %rax,%r14
mov    $0x2,%edi
call   1030 <malloc@plt>
mov    %rax,%r15
mov    %rbx,%rdi
mov    $0x5,%esi
call   1040 <realloc@plt>
mov    %rax,%r12
mov    %r14,%rdi
mov    $0x5,%esi
call   1040 <realloc@plt>
mov    %rax,%rbx
mov    %r15,%rdi
mov    $0x5,%esi
call   1040 <realloc@plt>
xor    %edx,%edx
cmpl   $0xdeadbeef,0x14(%r12)
ad de
sete   %dl
xor    %ecx,%ecx
cmpl   $0xdeadbeef,0x14(%rbx)
sete   %cl
xor    %esi,%esi
cmpl   $0xdeadbeef,0x14(%rax)
sete   %sil
add    %edx,%ecx
add    %esi,%ecx
mov    %ecx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %1
%8 = call i32* @malloc(i32 5)
store i32* %8, i32** %2
%9 = call i32* @malloc(i32 10)
store i32* %9, i32** %3
%10 = call i32* @malloc(i32 2)
store i32* %10, i32** %4
%11 = load i32*, i32** %2
%12 = call i32* @realloc(i32* %11, i32 5)
store i32* %12, i32** %2
%13 = load i32*, i32** %3
%14 = call i32* @realloc(i32* %13, i32 5)
store i32* %14, i32** %3
%15 = load i32*, i32** %4
%16 = call i32* @realloc(i32* %15, i32 5)
store i32* %16, i32** %4
%17 = load i32*, i32** %2
%18 = getelementptr inbounds i32, i32* %17, i64 5
%19 = load i32, i32* %18
%20 = icmp eq i32 %19, -559038737
%21 = zext i1 %20 to i64
%22 = select i1 %20, i32 1, i32 0
store i32 %22, i32* %5
%23 = load i32*, i32** %3
%24 = getelementptr inbounds i32, i32* %23, i64 5
%25 = load i32, i32* %24
%26 = icmp eq i32 %25, -559038737
%27 = zext i1 %26 to i64
%28 = select i1 %26, i32 1, i32 0
store i32 %28, i32* %6
%29 = load i32*, i32** %4
%30 = getelementptr inbounds i32, i32* %29, i64 5
%31 = load i32, i32* %30
%32 = icmp eq i32 %31, -559038737
%33 = zext i1 %32 to i64
%34 = select i1 %32, i32 1, i32 0
store i32 %34, i32* %7
%35 = load i32, i32* %5
%36 = load i32, i32* %6
%37 = add nsw i32 %35, %36
%38 = load i32, i32* %7
%39 = add nsw i32 %37, %38
ret i32 %39
}

LLVM IR (-O2):
define i32 @main() {
%1 = tail call i32* @malloc(i32 5)
%2 = tail call i32* @malloc(i32 10)
%3 = tail call i32* @malloc(i32 2)
%4 = tail call i32* @realloc(i32* %1, i32 5)
%5 = tail call i32* @realloc(i32* %2, i32 5)
%6 = tail call i32* @realloc(i32* %3, i32 5)
%7 = getelementptr inbounds i32, i32* %4, i64 5
%8 = load i32, i32* %7
%9 = icmp eq i32 %8, -559038737
%10 = zext i1 %9 to i32
%11 = getelementptr inbounds i32, i32* %5, i64 5
%12 = load i32, i32* %11
%13 = icmp eq i32 %12, -559038737
%14 = zext i1 %13 to i32
%15 = getelementptr inbounds i32, i32* %6, i64 5
%16 = load i32, i32* %15
%17 = icmp eq i32 %16, -559038737
%18 = zext i1 %17 to i32
%19 = add nuw nsw i32 %14, %10
%20 = add nuw nsw i32 %19, %18
ret i32 %20
}