#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(char *);
int /*<<< orphan*/ memset(char *, char, int);
int puts(char *);
char *xmalloc(int);
int main(void) {
  char *test = xmalloc(512);
  (puts("Allocation"), test != NULL) ? (puts("SUCC\n")) : (puts("FAIL\n"));
  memset(test, 'T', 512);
  puts(test);
  {
    free((test));
    (test) = NULL;
  };
  (puts("\nFree"), test == NULL) ? (puts("SUCC")) : (puts("FAIL"));
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x200,%edi
call   1060 <xmalloc@plt>
mov    %rax,-0x10(%rbp)
lea    0xe9c(%rip),%rdi
call   1040 <puts@plt>
cmpq   $0x0,-0x10(%rbp)
je     1185 <main+0x45>
lea    0xe90(%rip),%rdi
call   1040 <puts@plt>
jmp    1191 <main+0x51>
lea    0xe85(%rip),%rdi
call   1040 <puts@plt>
mov    -0x10(%rbp),%rdi
mov    $0x54,%esi
mov    $0x200,%edx
call   1050 <memset@plt>
mov    -0x10(%rbp),%rdi
call   1040 <puts@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x10(%rbp)
lea    0xe52(%rip),%rdi
call   1040 <puts@plt>
cmpq   $0x0,-0x10(%rbp)
jne    11e6 <main+0xa6>
lea    0xe41(%rip),%rdi
call   1040 <puts@plt>
jmp    11f2 <main+0xb2>
lea    0xe35(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    $0x200,%edi
call   1060 <xmalloc@plt>
mov    %rax,%rbx
lea    0xeab(%rip),%rdi
call   1040 <puts@plt>
test   %rbx,%rbx
lea    0xead(%rip),%rax
lea    0xea0(%rip),%rdi
cmove  %rax,%rdi
call   1040 <puts@plt>
mov    %rbx,%rdi
mov    $0x54,%esi
mov    $0x200,%edx
call   1050 <memset@plt>
mov    %rbx,%rdi
call   1040 <puts@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
lea    0xe7a(%rip),%rdi
call   1040 <puts@plt>
lea    0xe74(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [11 x i8] c"Allocation\00"
@.str.1 = [6 x i8] c"SUCC\0A\00"
@.str.2 = [6 x i8] c"FAIL\0A\00"
@.str.3 = [6 x i8] c"\0AFree\00"
@.str.4 = [5 x i8] c"SUCC\00"
@.str.5 = [5 x i8] c"FAIL\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
store i32 0, i32* %1
%3 = call i8* @xmalloc(i32 512)
store i8* %3, i8** %2
%4 = call i32 @puts(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%5 = load i8*, i8** %2
%6 = icmp ne i8* %5, null
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = call i32 @puts(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
br label %11
9: ; preds = %0
%10 = call i32 @puts(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
br label %11
11: ; preds = %9, %7
%12 = phi i32 [ %8, %7 ], [ %10, %9 ]
%13 = load i8*, i8** %2
%14 = call i32 @memset(i8* %13, i8 signext 84, i32 512)
%15 = load i8*, i8** %2
%16 = call i32 @puts(i8* %15)
%17 = load i8*, i8** %2
%18 = call i32 @free(i8* %17)
store i8* null, i8** %2
%19 = call i32 @puts(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%20 = load i8*, i8** %2
%21 = icmp eq i8* %20, null
br i1 %21, label %22, label %24
22: ; preds = %11
%23 = call i32 @puts(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
br label %26
24: ; preds = %11
%25 = call i32 @puts(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
br label %26
26: ; preds = %24, %22
%27 = phi i32 [ %23, %22 ], [ %25, %24 ]
ret i32 0
}

LLVM IR (-O2):
@.str = [11 x i8] c"Allocation\00"
@.str.1 = [6 x i8] c"SUCC\0A\00"
@.str.2 = [6 x i8] c"FAIL\0A\00"
@.str.3 = [6 x i8] c"\0AFree\00"
@.str.4 = [5 x i8] c"SUCC\00"
define i32 @main() {
%1 = tail call i8* @xmalloc(i32 512)
%2 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq i8* %1, null
%4 = select i1 %3, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0)
%5 = tail call i32 @puts(i8* dereferenceable(1) %4)
%6 = tail call i32 @memset(i8* %1, i8 signext 84, i32 512)
%7 = tail call i32 @puts(i8* dereferenceable(1) %1)
%8 = tail call i32 @free(i8* %1)
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
ret i32 0
}