#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*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int);
void *malloc(int);
int /*<<< orphan*/ memset(void *, int /*<<< orphan*/, int);
int /*<<< orphan*/ stderr;
void *salloc(int size) {
  void *ptr;
  if (size <= 0)
    return 0;
  ptr = malloc(size);
  if (!ptr) {
    fprintf(stderr, "FATAL: Not enough memory (trying to allocate %d bytes)\n",
            size);
    exit(9);
  }
  memset(ptr, 0, size);
  return ptr;
}


x86 assembly (clang, -O0):
<salloc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jg     1162 <salloc+0x22>
movq   $0x0,-0x8(%rbp)
jmp    11b1 <salloc+0x71>
mov    -0xc(%rbp),%edi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    119b <salloc+0x5b>
mov    0x2e60(%rip),%rax
mov    (%rax),%edi
mov    -0xc(%rbp),%edx
lea    0xe74(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x9,%edi
call   1060 <exit@plt>
mov    -0x18(%rbp),%rdi
mov    -0xc(%rbp),%edx
xor    %esi,%esi
call   1030 <memset@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<salloc>:
push   %rbp
push   %rbx
push   %rax
test   %edi,%edi
jle    1164 <salloc+0x24>
mov    %edi,%ebp
call   1050 <malloc@plt>
test   %rax,%rax
je     1170 <salloc+0x30>
mov    %rax,%rbx
mov    %rax,%rdi
xor    %esi,%esi
mov    %ebp,%edx
call   1030 <memset@plt>
jmp    1166 <salloc+0x26>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
mov    0x2e69(%rip),%rax
mov    (%rax),%edi
lea    0xe80(%rip),%rsi
mov    %ebp,%edx
call   1040 <fprintf@plt>
mov    $0x9,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [56 x i8] c"FATAL: Not enough memory (trying to allocate %d bytes)\0A\00"
define i8* @salloc(i32 %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i8*
store i32 %0, i32* %3
%5 = load i32, i32* %3
%6 = icmp sle i32 %5, 0
br i1 %6, label %7, label %8
7: ; preds = %1
store i8* null, i8** %2
br label %23
8: ; preds = %1
%9 = load i32, i32* %3
%10 = call i8* @malloc(i32 %9)
store i8* %10, i8** %4
%11 = load i8*, i8** %4
%12 = icmp ne i8* %11, null
br i1 %12, label %18, label %13
13: ; preds = %8
%14 = load i32, i32* @stderr
%15 = load i32, i32* %3
%16 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str, i64 0, i64 0), i32 %15)
%17 = call i32 @exit(i32 9)
unreachable
18: ; preds = %8
%19 = load i8*, i8** %4
%20 = load i32, i32* %3
%21 = call i32 @memset(i8* %19, i32 0, i32 %20)
%22 = load i8*, i8** %4
store i8* %22, i8** %2
br label %23
23: ; preds = %18, %7
%24 = load i8*, i8** %2
ret i8* %24
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [56 x i8] c"FATAL: Not enough memory (trying to allocate %d bytes)\0A\00"
define i8* @salloc(i32 %0) {
%2 = icmp slt i32 %0, 1
br i1 %2, label %12, label %3
3: ; preds = %1
%4 = tail call i8* @malloc(i32 %0)
%5 = icmp eq i8* %4, null
br i1 %5, label %6, label %10
6: ; preds = %3
%7 = load i32, i32* @stderr
%8 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str, i64 0, i64 0), i32 %0)
%9 = tail call i32 @exit(i32 9)
unreachable
10: ; preds = %3
%11 = tail call i32 @memset(i8* %4, i32 0, i32 %0)
br label %12
12: ; preds = %1, %10
%13 = phi i8* [ %4, %10 ], [ null, %1 ]
ret i8* %13
}