#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,
            "ERROR: Cannot allocate memory because len = %i in "
            "allocate_ustrmem().\n",
            len);
    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,
            "ERROR: Cannot allocate memory for array 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     117d <allocate_ustrmem+0x3d>
mov    0x2e84(%rip),%rax
mov    (%rax),%edi
mov    -0x4(%rbp),%edx
lea    0xe98(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    0x2e62(%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     11ba <allocate_ustrmem+0x7a>
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    0x2e1f(%rip),%rax
mov    (%rax),%edi
lea    0xe7d(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    0x2e00(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>

x86 assembly (clang, -O2):
<allocate_ustrmem>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebp
test   %edi,%edi
jle    116e <allocate_ustrmem+0x2e>
mov    %ebp,%edi
call   1050 <malloc@plt>
test   %rax,%rax
je     1189 <allocate_ustrmem+0x49>
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    0x2e6b(%rip),%rax
mov    (%rax),%edi
lea    0xe82(%rip),%rsi
mov    %ebp,%edx
xor    %eax,%eax
call   1040 <fprintf@plt>
jmp    11a0 <allocate_ustrmem+0x60>
mov    0x2e50(%rip),%rax
mov    (%rax),%edi
lea    0xeae(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    0x2e31(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [71 x i8] c"ERROR: Cannot allocate memory because len = %i in allocate_ustrmem().\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [61 x i8] c"ERROR: Cannot allocate memory for array allocate_ustrmem().\0A\00"
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 %12
6: ; preds = %1
%7 = load i32, i32* @stderr
%8 = load i32, i32* %2
%9 = call i32 (i32, i8*, ...) @fprintf(i32 %7, i8* getelementptr inbounds ([71 x i8], [71 x i8]* @.str, i64 0, i64 0), i32 %8)
%10 = load i32, i32* @EXIT_FAILURE
%11 = call i32 @exit(i32 %10)
unreachable
12: ; preds = %1
%13 = load i32, i32* %2
%14 = sext i32 %13 to i64
%15 = mul i64 %14, 1
%16 = trunc i64 %15 to i32
%17 = call i64 @malloc(i32 %16)
%18 = inttoptr i64 %17 to i8*
store i8* %18, i8** %3
%19 = load i8*, i8** %3
%20 = icmp ne i8* %19, null
br i1 %20, label %21, label %29
21: ; preds = %12
%22 = load i8*, i8** %3
%23 = load i32, i32* %2
%24 = sext i32 %23 to i64
%25 = mul i64 %24, 1
%26 = trunc i64 %25 to i32
%27 = call i32 @memset(i8* %22, i32 0, i32 %26)
%28 = load i8*, i8** %3
ret i8* %28
29: ; preds = %12
%30 = load i32, i32* @stderr
%31 = call i32 (i32, i8*, ...) @fprintf(i32 %30, i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.1, i64 0, i64 0))
%32 = load i32, i32* @EXIT_FAILURE
%33 = call i32 @exit(i32 %32)
unreachable
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [71 x i8] c"ERROR: Cannot allocate memory because len = %i in allocate_ustrmem().\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [61 x i8] c"ERROR: Cannot allocate memory for array allocate_ustrmem().\0A\00"
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 (i32, i8*, ...) @fprintf(i32 %4, i8* getelementptr inbounds ([71 x i8], [71 x i8]* @.str, i64 0, i64 0), i32 %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 (i32, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.1, i64 0, i64 0))
%17 = load i32, i32* @EXIT_FAILURE
%18 = tail call i32 @exit(i32 %17)
unreachable
}