#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 */
typedef void uint8_t;

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ memset(void *, int /*<<< orphan*/, int);
int /*<<< orphan*/ stderr;
uint8_t *allocate_ustrmem(int len) {
  void *tmp;
  if (len <= 0) {
    fprintf(stderr, "allocate_ustrmem()\n");
    exit(EXIT_FAILURE);
  }
  tmp = (uint8_t *)malloc(len * sizeof(uint8_t));
  if (tmp != NULL) {
    memset(tmp, 0, len * sizeof(uint8_t));
    return (tmp);
  } else {
    fprintf(stderr, "allocate_ustrmem()\n");
    exit(EXIT_FAILURE);
  }
}


x86 assembly (clang, -O0):
<allocate_ustrmem>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
jg     1178 <allocate_ustrmem+0x38>
mov    0x2e84(%rip),%rax
mov    (%rax),%edi
lea    0xe9b(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2e67(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
movslq -0x4(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11b5 <allocate_ustrmem+0x75>
mov    -0x10(%rbp),%rdi
movslq -0x4(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%edx
xor    %esi,%esi
call   1030 <memset@plt>
mov    -0x10(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret
mov    0x2e24(%rip),%rax
mov    (%rax),%edi
lea    0xe3b(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2e07(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>

x86 assembly (clang, -O2):
<allocate_ustrmem>:
push   %rbp
push   %rbx
push   %rax
test   %edi,%edi
jle    116c <allocate_ustrmem+0x2c>
mov    %edi,%ebp
call   1050 <malloc@plt>
test   %rax,%rax
je     116c <allocate_ustrmem+0x2c>
mov    %rax,%rbx
mov    %rax,%rdi
xor    %esi,%esi
mov    %ebp,%edx
call   1030 <memset@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
mov    0x2e6d(%rip),%rax
mov    (%rax),%edi
lea    0xe84(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2e50(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [20 x i8] c"allocate_ustrmem()\0A\00"
@EXIT_FAILURE = global i32 0
define i8* @allocate_ustrmem(i32 %0) {
%2 = alloca i32
%3 = alloca i8*
store i32 %0, i32* %2
%4 = load i32, i32* %2
%5 = icmp sle i32 %4, 0
br i1 %5, label %6, label %11
6: ; preds = %1
%7 = load i32, i32* @stderr
%8 = call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%9 = load i32, i32* @EXIT_FAILURE
%10 = call i32 @exit(i32 %9)
unreachable
11: ; preds = %1
%12 = load i32, i32* %2
%13 = sext i32 %12 to i64
%14 = mul i64 %13, 1
%15 = trunc i64 %14 to i32
%16 = call i64 @malloc(i32 %15)
%17 = inttoptr i64 %16 to i8*
store i8* %17, i8** %3
%18 = load i8*, i8** %3
%19 = icmp ne i8* %18, null
br i1 %19, label %20, label %28
20: ; preds = %11
%21 = load i8*, i8** %3
%22 = load i32, i32* %2
%23 = sext i32 %22 to i64
%24 = mul i64 %23, 1
%25 = trunc i64 %24 to i32
%26 = call i32 @memset(i8* %21, i32 0, i32 %25)
%27 = load i8*, i8** %3
ret i8* %27
28: ; preds = %11
%29 = load i32, i32* @stderr
%30 = call i32 @fprintf(i32 %29, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%31 = load i32, i32* @EXIT_FAILURE
%32 = call i32 @exit(i32 %31)
unreachable
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [20 x i8] c"allocate_ustrmem()\0A\00"
@EXIT_FAILURE = global i32 0
define i8* @allocate_ustrmem(i32 %0) {
%2 = icmp slt i32 %0, 1
br i1 %2, label %3, label %8
3: ; preds = %1
%4 = load i32, i32* @stderr
%5 = tail call i32 @fprintf(i32 %4, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%6 = load i32, i32* @EXIT_FAILURE
%7 = tail call i32 @exit(i32 %6)
unreachable
8: ; preds = %1
%9 = tail call i64 @malloc(i32 %0)
%10 = inttoptr i64 %9 to i8*
%11 = icmp eq i64 %9, 0
br i1 %11, label %14, label %12
12: ; preds = %8
%13 = tail call i32 @memset(i8* %10, i32 0, i32 %0)
ret i8* %10
14: ; preds = %8
%15 = load i32, i32* @stderr
%16 = tail call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%17 = load i32, i32* @EXIT_FAILURE
%18 = tail call i32 @exit(i32 %17)
unreachable
}