#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);
int /*<<< orphan*/ trigger_error(char *);
char *init_str(long long size) {
  char *str;
  long long i;
  str = (char *)malloc(sizeof(char) * size);
  if (!str) {
    trigger_error("Dynamic allocation issue\n");
  }
  i = 0;
  while (i < size) {
    str[i++] = 'a';
  }
  return (str);
}


x86 assembly (clang, -O0):
<init_str>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1156 <init_str+0x36>
lea    0xeaf(%rip),%rdi
call   1030 <trigger_error@plt>
movq   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x8(%rbp),%rax
jge    1188 <init_str+0x68>
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    %rcx,%rdx
add    $0x1,%rdx
mov    %rdx,-0x18(%rbp)
movb   $0x61,(%rax,%rcx,1)
jmp    115e <init_str+0x3e>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<init_str>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
call   1050 <malloc@plt>
mov    %rax,%rbx
test   %rax,%rax
je     1164 <init_str+0x34>
test   %r14,%r14
jle    1159 <init_str+0x29>
mov    %rbx,%rdi
mov    $0x61,%esi
mov    %r14,%rdx
call   1040 <memset@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe95(%rip),%rdi
call   1030 <trigger_error@plt>
test   %r14,%r14
jg     1149 <init_str+0x19>
jmp    1159 <init_str+0x29>

LLVM IR (-O0):
@.str = [26 x i8] c"Dynamic allocation issue\0A\00"
define i8* @init_str(i64 %0) {
%2 = alloca i64
%3 = alloca i8*
%4 = alloca i64
store i64 %0, i64* %2
%5 = load i64, i64* %2
%6 = mul i64 1, %5
%7 = trunc i64 %6 to i32
%8 = call i64 @malloc(i32 %7)
%9 = inttoptr i64 %8 to i8*
store i8* %9, i8** %3
%10 = load i8*, i8** %3
%11 = icmp ne i8* %10, null
br i1 %11, label %14, label %12
12: ; preds = %1
%13 = call i32 @trigger_error(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
br label %14
14: ; preds = %12, %1
store i64 0, i64* %4
br label %15
15: ; preds = %19, %14
%16 = load i64, i64* %4
%17 = load i64, i64* %2
%18 = icmp slt i64 %16, %17
br i1 %18, label %19, label %24
19: ; preds = %15
%20 = load i8*, i8** %3
%21 = load i64, i64* %4
%22 = add nsw i64 %21, 1
store i64 %22, i64* %4
%23 = getelementptr inbounds i8, i8* %20, i64 %21
store i8 97, i8* %23
br label %15
24: ; preds = %15
%25 = load i8*, i8** %3
ret i8* %25
}

LLVM IR (-O2):
@.str = [26 x i8] c"Dynamic allocation issue\0A\00"
define i8* @init_str(i64 %0) {
%2 = trunc i64 %0 to i32
%3 = tail call i64 @malloc(i32 %2)
%4 = inttoptr i64 %3 to i8*
%5 = icmp eq i64 %3, 0
br i1 %5, label %6, label %8
6: ; preds = %1
%7 = tail call i32 @trigger_error(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
br label %8
8: ; preds = %6, %1
%9 = icmp sgt i64 %0, 0
br i1 %9, label %10, label %11
10: ; preds = %8
br label %11
11: ; preds = %10, %8
ret i8* %4
}