#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 */
char *malloc(unsigned int);
char *create_array(unsigned int size, char c) {
  char *array;
  unsigned int i;
  if (size == 0)
    return (NULL);
  array = malloc(size * sizeof(char));
  if (array == NULL)
    return (NULL);
  for (i = 0; i < size; ++i)
    array[i] = c;
  return (array);
}


x86 assembly (clang, -O0):
<create_array>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %sil,%al
mov    %edi,-0xc(%rbp)
mov    %al,-0xd(%rbp)
cmpl   $0x0,-0xc(%rbp)
jne    1138 <create_array+0x28>
movq   $0x0,-0x8(%rbp)
jmp    1198 <create_array+0x88>
mov    -0xc(%rbp),%eax
shl    $0x0,%rax
mov    %eax,%edi
call   1030 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1162 <create_array+0x52>
movq   $0x0,-0x8(%rbp)
jmp    1198 <create_array+0x88>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jae    1190 <create_array+0x80>
mov    -0xd(%rbp),%dl
mov    -0x18(%rbp),%rax
mov    -0x1c(%rbp),%ecx
mov    %dl,(%rax,%rcx,1)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1169 <create_array+0x59>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<create_array>:
push   %rbp
push   %r14
push   %rbx
test   %edi,%edi
je     114a <create_array+0x2a>
mov    %esi,%r14d
mov    %edi,%ebp
call   1040 <malloc@plt>
test   %rax,%rax
je     114a <create_array+0x2a>
mov    %rax,%rbx
mov    %ebp,%edx
movzbl %r14b,%esi
mov    %rax,%rdi
call   1030 <memset@plt>
jmp    114c <create_array+0x2c>
xor    %ebx,%ebx
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i8* @create_array(i32 %0, i8 signext %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8
%6 = alloca i8*
%7 = alloca i32
store i32 %0, i32* %4
store i8 %1, i8* %5
%8 = load i32, i32* %4
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %11
10: ; preds = %2
store i8* null, i8** %3
br label %36
11: ; preds = %2
%12 = load i32, i32* %4
%13 = zext i32 %12 to i64
%14 = mul i64 %13, 1
%15 = trunc i64 %14 to i32
%16 = call i8* @malloc(i32 %15)
store i8* %16, i8** %6
%17 = load i8*, i8** %6
%18 = icmp eq i8* %17, null
br i1 %18, label %19, label %20
19: ; preds = %11
store i8* null, i8** %3
br label %36
20: ; preds = %11
store i32 0, i32* %7
br label %21
21: ; preds = %31, %20
%22 = load i32, i32* %7
%23 = load i32, i32* %4
%24 = icmp ult i32 %22, %23
br i1 %24, label %25, label %34
25: ; preds = %21
%26 = load i8, i8* %5
%27 = load i8*, i8** %6
%28 = load i32, i32* %7
%29 = zext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* %27, i64 %29
store i8 %26, i8* %30
br label %31
31: ; preds = %25
%32 = load i32, i32* %7
%33 = add i32 %32, 1
store i32 %33, i32* %7
br label %21
34: ; preds = %21
%35 = load i8*, i8** %6
store i8* %35, i8** %3
br label %36
36: ; preds = %34, %19, %10
%37 = load i8*, i8** %3
ret i8* %37
}

LLVM IR (-O2):
define noalias i8* @create_array(i32 %0, i8 signext %1) {
%3 = icmp eq i32 %0, 0
br i1 %3, label %9, label %4
4: ; preds = %2
%5 = tail call i8* @malloc(i32 %0)
%6 = icmp eq i8* %5, null
br i1 %6, label %9, label %7
7: ; preds = %4
%8 = zext i32 %0 to i64
br label %9
9: ; preds = %7, %4, %2
%10 = phi i8* [ null, %2 ], [ null, %4 ], [ %5, %7 ]
ret i8* %10
}