#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*/ free(int *);
scalar_t__ malloc(int);
scalar_t__ realloc(int *, int);
void no_check_for_null_after_realloc() {
  int *p;
  p = (int *)malloc(sizeof(int) * 5);
  if (p) {
    p[3] = 42;
  }
  int *q = (int *)realloc(p, sizeof(int) * 10);
  if (!q)
    free(p);
  q[7] = 0;
  free(q);
}


x86 assembly (clang, -O0):
<no_check_for_null_after_realloc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x14,%edi
call   1040 <malloc@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     115c <no_check_for_null_after_realloc+0x2c>
mov    -0x8(%rbp),%rax
movl   $0x2a,0xc(%rax)
mov    -0x8(%rbp),%rdi
mov    $0x28,%esi
call   1050 <realloc@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1182 <no_check_for_null_after_realloc+0x52>
mov    -0x8(%rbp),%rdi
call   1030 <free@plt>
mov    -0x10(%rbp),%rax
movl   $0x0,0x1c(%rax)
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<no_check_for_null_after_realloc>:
push   %r14
push   %rbx
push   %rax
mov    $0x14,%edi
call   1040 <malloc@plt>
mov    %rax,%r14
test   %rax,%rax
je     114e <no_check_for_null_after_realloc+0x1e>
movl   $0x2a,0xc(%r14)
mov    %r14,%rdi
mov    $0x28,%esi
call   1050 <realloc@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    116b <no_check_for_null_after_realloc+0x3b>
mov    %r14,%rdi
call   1030 <free@plt>
movl   $0x0,0x1c(%rbx)
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <free@plt>

LLVM IR (-O0):
define void @no_check_for_null_after_realloc() {
%1 = alloca i32*
%2 = alloca i32*
%3 = call i64 @malloc(i32 20)
%4 = inttoptr i64 %3 to i32*
store i32* %4, i32** %1
%5 = load i32*, i32** %1
%6 = icmp ne i32* %5, null
br i1 %6, label %7, label %10
7: ; preds = %0
%8 = load i32*, i32** %1
%9 = getelementptr inbounds i32, i32* %8, i64 3
store i32 42, i32* %9
br label %10
10: ; preds = %7, %0
%11 = load i32*, i32** %1
%12 = call i64 @realloc(i32* %11, i32 40)
%13 = inttoptr i64 %12 to i32*
store i32* %13, i32** %2
%14 = load i32*, i32** %2
%15 = icmp ne i32* %14, null
br i1 %15, label %19, label %16
16: ; preds = %10
%17 = load i32*, i32** %1
%18 = call i32 @free(i32* %17)
br label %19
19: ; preds = %16, %10
%20 = load i32*, i32** %2
%21 = getelementptr inbounds i32, i32* %20, i64 7
store i32 0, i32* %21
%22 = load i32*, i32** %2
%23 = call i32 @free(i32* %22)
ret void
}

LLVM IR (-O2):
define void @no_check_for_null_after_realloc() {
%1 = tail call i64 @malloc(i32 20)
%2 = inttoptr i64 %1 to i32*
%3 = icmp eq i64 %1, 0
br i1 %3, label %6, label %4
4: ; preds = %0
%5 = getelementptr inbounds i32, i32* %2, i64 3
store i32 42, i32* %5
br label %6
6: ; preds = %4, %0
%7 = tail call i64 @realloc(i32* %2, i32 40)
%8 = inttoptr i64 %7 to i32*
%9 = icmp eq i64 %7, 0
br i1 %9, label %10, label %12
10: ; preds = %6
%11 = tail call i32 @free(i32* %2)
br label %12
12: ; preds = %10, %6
%13 = getelementptr inbounds i32, i32* %8, i64 7
store i32 0, i32* %13
%14 = tail call i32 @free(i32* %8)
ret void
}