#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 /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char *);
int strlen(char *);
void main() {
  char *ptr;
  int ptr_len;
  printf("Got a %s pointer.\n",
         (ptr = (char *)malloc(0)) == NULL ? "null" : "valid");
  printf("Got a %s pointer.\n",
         (ptr_len = strlen(ptr = (char *)malloc(0))) == 0 ? "null" : "valid");
  printf("Got a %s pointer.\n",
         (ptr_len = sizeof(ptr = (char *)malloc(0))) == 8 ? "null" : "valid");
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
xor    %edi,%edi
call   1050 <malloc@plt>
mov    %rax,%rcx
mov    %rcx,-0x8(%rbp)
lea    0xecb(%rip),%rsi
lea    0xebf(%rip),%rax
cmp    $0x0,%rcx
cmove  %rax,%rsi
lea    0xe9d(%rip),%rdi
call   1040 <printf@plt>
xor    %edi,%edi
call   1050 <malloc@plt>
mov    %rax,%rdi
mov    %rdi,-0x8(%rbp)
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    %ecx,-0xc(%rbp)
lea    0xe91(%rip),%rsi
lea    0xe85(%rip),%rax
cmp    $0x0,%ecx
cmove  %rax,%rsi
lea    0xe64(%rip),%rdi
call   1040 <printf@plt>
movl   $0x8,-0xc(%rbp)
lea    0xe51(%rip),%rdi
lea    0xe5d(%rip),%rsi
call   1040 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
xor    %edi,%edi
call   1050 <malloc@plt>
test   %rax,%rax
lea    0xecd(%rip),%r14
lea    0xecb(%rip),%rbx
mov    %rbx,%rsi
cmove  %r14,%rsi
lea    0xea5(%rip),%r15
mov    %r15,%rdi
call   1040 <printf@plt>
xor    %edi,%edi
call   1050 <malloc@plt>
mov    %rax,%rdi
call   1030 <strlen@plt>
test   %eax,%eax
cmove  %r14,%rbx
mov    %r15,%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
mov    %r15,%rdi
mov    %r14,%rsi
pop    %rbx
pop    %r14
pop    %r15
jmp    1040 <printf@plt>

LLVM IR (-O0):
@.str = [19 x i8] c"Got a %s pointer.\0A\00"
@.str.1 = [5 x i8] c"null\00"
@.str.2 = [6 x i8] c"valid\00"
define void @main() {
%1 = alloca i8*
%2 = alloca i32
%3 = call i64 @malloc(i32 0)
%4 = inttoptr i64 %3 to i8*
store i8* %4, i8** %1
%5 = icmp eq i8* %4, null
%6 = zext i1 %5 to i64
%7 = select i1 %5, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0)
%8 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %7)
%9 = call i64 @malloc(i32 0)
%10 = inttoptr i64 %9 to i8*
store i8* %10, i8** %1
%11 = call i32 @strlen(i8* %10)
store i32 %11, i32* %2
%12 = icmp eq i32 %11, 0
%13 = zext i1 %12 to i64
%14 = select i1 %12, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0)
%15 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %14)
store i32 8, i32* %2
%16 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [19 x i8] c"Got a %s pointer.\0A\00"
@.str.1 = [5 x i8] c"null\00"
@.str.2 = [6 x i8] c"valid\00"
define void @main() {
%1 = tail call i64 @malloc(i32 0)
%2 = icmp eq i64 %1, 0
%3 = select i1 %2, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0)
%4 = tail call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %3)
%5 = tail call i64 @malloc(i32 0)
%6 = inttoptr i64 %5 to i8*
%7 = tail call i32 @strlen(i8* %6)
%8 = icmp eq i32 %7, 0
%9 = select i1 %8, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0)
%10 = tail call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %9)
%11 = tail call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
ret void
}