#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);
int /*<<< orphan*/ print_all(int *, int);
int /*<<< orphan*/ printf(char *);
scalar_t__ realloc(int *, int);
int main(int argc, char const *argv[]) {
  int *p = NULL;
  if (p == NULL) {
    p = (int *)malloc(5 * sizeof(int));
  }
  p[0] = 17;
  print_all(p, 5);
  p = (int *)realloc(p, 11 * sizeof(int));
  p[9] = 9;
  print_all(p, 11);
  free(p);
  p = NULL;
  if (p == NULL) {
    printf("Testing for NULL is positive\n");
  }
  p = (int *)malloc(6 * sizeof(int));
  p[3] = 4444;
  print_all(p, 6);
  free(p);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1187 <main+0x37>
mov    $0x14,%edi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movl   $0x11,(%rax)
mov    -0x18(%rbp),%rdi
mov    $0x5,%esi
call   1070 <print_all@plt>
mov    -0x18(%rbp),%rdi
mov    $0x2c,%esi
call   1060 <realloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movl   $0x9,0x24(%rax)
mov    -0x18(%rbp),%rdi
mov    $0xb,%esi
call   1070 <print_all@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11f2 <main+0xa2>
lea    0xe13(%rip),%rdi
call   1040 <printf@plt>
mov    $0x18,%edi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movl   $0x115c,0xc(%rax)
mov    -0x18(%rbp),%rdi
mov    $0x6,%esi
call   1070 <print_all@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    $0x14,%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
movl   $0x11,(%rax)
mov    %rax,%rdi
mov    $0x5,%esi
call   1070 <print_all@plt>
mov    %rbx,%rdi
mov    $0x2c,%esi
call   1060 <realloc@plt>
mov    %rax,%rbx
movl   $0x9,0x24(%rax)
mov    %rax,%rdi
mov    $0xb,%esi
call   1070 <print_all@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
lea    0xe5c(%rip),%rdi
call   1040 <puts@plt>
mov    $0x18,%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
movl   $0x115c,0xc(%rax)
mov    %rax,%rdi
mov    $0x6,%esi
call   1070 <print_all@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [30 x i8] c"Testing for NULL is positive\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32* null, i32** %6
%7 = load i32*, i32** %6
%8 = icmp eq i32* %7, null
br i1 %8, label %9, label %12
9: ; preds = %2
%10 = call i64 @malloc(i32 20)
%11 = inttoptr i64 %10 to i32*
store i32* %11, i32** %6
br label %12
12: ; preds = %9, %2
%13 = load i32*, i32** %6
%14 = getelementptr inbounds i32, i32* %13, i64 0
store i32 17, i32* %14
%15 = load i32*, i32** %6
%16 = call i32 @print_all(i32* %15, i32 5)
%17 = load i32*, i32** %6
%18 = call i64 @realloc(i32* %17, i32 44)
%19 = inttoptr i64 %18 to i32*
store i32* %19, i32** %6
%20 = load i32*, i32** %6
%21 = getelementptr inbounds i32, i32* %20, i64 9
store i32 9, i32* %21
%22 = load i32*, i32** %6
%23 = call i32 @print_all(i32* %22, i32 11)
%24 = load i32*, i32** %6
%25 = call i32 @free(i32* %24)
store i32* null, i32** %6
%26 = load i32*, i32** %6
%27 = icmp eq i32* %26, null
br i1 %27, label %28, label %30
28: ; preds = %12
%29 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
br label %30
30: ; preds = %28, %12
%31 = call i64 @malloc(i32 24)
%32 = inttoptr i64 %31 to i32*
store i32* %32, i32** %6
%33 = load i32*, i32** %6
%34 = getelementptr inbounds i32, i32* %33, i64 3
store i32 4444, i32* %34
%35 = load i32*, i32** %6
%36 = call i32 @print_all(i32* %35, i32 6)
%37 = load i32*, i32** %6
%38 = call i32 @free(i32* %37)
%39 = load i32, i32* %3
ret i32 %39
}

LLVM IR (-O2):
@str = [29 x i8] c"Testing for NULL is positive\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i64 @malloc(i32 20)
%4 = inttoptr i64 %3 to i32*
store i32 17, i32* %4
%5 = tail call i32 @print_all(i32* %4, i32 5)
%6 = tail call i64 @realloc(i32* %4, i32 44)
%7 = inttoptr i64 %6 to i32*
%8 = getelementptr inbounds i32, i32* %7, i64 9
store i32 9, i32* %8
%9 = tail call i32 @print_all(i32* %7, i32 11)
%10 = tail call i32 @free(i32* %7)
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str, i64 0, i64 0))
%12 = tail call i64 @malloc(i32 24)
%13 = inttoptr i64 %12 to i32*
%14 = getelementptr inbounds i32, i32* %13, i64 3
store i32 4444, i32* %14
%15 = tail call i32 @print_all(i32* %13, i32 6)
%16 = tail call i32 @free(i32* %13)
ret i32 0
}