#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 */
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ realloc(int *, int);
int main(void) {
  int *p = (int *)malloc(sizeof(int));
  int *q = (int *)realloc(p, sizeof(int));
  *p = 1;
  *q = 2;
  if (p == q)
    printf("%d %d\n", *p, *q);
  else
    printf("foo\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x4,%edi
call   1040 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x4,%esi
call   1050 <realloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
movl   $0x1,(%rax)
mov    -0x18(%rbp),%rax
movl   $0x2,(%rax)
mov    -0x10(%rbp),%rax
cmp    -0x18(%rbp),%rax
jne    11a0 <main+0x70>
mov    -0x10(%rbp),%rax
mov    (%rax),%esi
mov    -0x18(%rbp),%rax
mov    (%rax),%edx
lea    0xe6c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11ae <main+0x7e>
lea    0xe60(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    $0x4,%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    $0x4,%esi
call   1060 <realloc@plt>
movl   $0x1,(%rbx)
movl   $0x2,(%rax)
cmp    %rax,%rbx
je     117a <main+0x3a>
lea    0xe94(%rip),%rdi
call   1030 <puts@plt>
jmp    118f <main+0x4f>
mov    (%rbx),%esi
lea    0xe7d(%rip),%rdi
mov    $0x2,%edx
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [7 x i8] c"%d %d\0A\00"
@.str.1 = [5 x i8] c"foo\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32*
store i32 0, i32* %1
%4 = call i64 @malloc(i32 4)
%5 = inttoptr i64 %4 to i32*
store i32* %5, i32** %2
%6 = load i32*, i32** %2
%7 = call i64 @realloc(i32* %6, i32 4)
%8 = inttoptr i64 %7 to i32*
store i32* %8, i32** %3
%9 = load i32*, i32** %2
store i32 1, i32* %9
%10 = load i32*, i32** %3
store i32 2, i32* %10
%11 = load i32*, i32** %2
%12 = load i32*, i32** %3
%13 = icmp eq i32* %11, %12
br i1 %13, label %14, label %20
14: ; preds = %0
%15 = load i32*, i32** %2
%16 = load i32, i32* %15
%17 = load i32*, i32** %3
%18 = load i32, i32* %17
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %16, i32 %18)
br label %22
20: ; preds = %0
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %22
22: ; preds = %20, %14
ret i32 0
}

LLVM IR (-O2):
@.str = [7 x i8] c"%d %d\0A\00"
@str = [4 x i8] c"foo\00"
define i32 @main() {
%1 = tail call i64 @malloc(i32 4)
%2 = inttoptr i64 %1 to i32*
%3 = tail call i64 @realloc(i32* %2, i32 4)
%4 = inttoptr i64 %3 to i32*
store i32 1, i32* %2
store i32 2, i32* %4
%5 = icmp eq i32* %2, %4
br i1 %5, label %6, label %9
6: ; preds = %0
%7 = load i32, i32* %2
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %7, i32 2)
br label %11
9: ; preds = %0
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @str, i64 0, i64 0))
br label %11
11: ; preds = %9, %6
ret i32 0
}