#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(int);
char *create_array(unsigned int size, char c) {
  char *array;
  unsigned int i = 0;
  if (size == 0) {
    return (NULL);
  }
  array = malloc(sizeof(char) * size);
  if (array == NULL) {
    return (NULL);
  } else
    while (i < size) {
      array[i] = c;
      i++;
    }
  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)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x0,-0xc(%rbp)
jne    113f <create_array+0x2f>
movq   $0x0,-0x8(%rbp)
jmp    11a2 <create_array+0x92>
mov    -0xc(%rbp),%eax
shl    $0x0,%rax
mov    %eax,%edi
call   1030 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1169 <create_array+0x59>
movq   $0x0,-0x8(%rbp)
jmp    11a2 <create_array+0x92>
jmp    116e <create_array+0x5e>
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jae    1195 <create_array+0x85>
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    116e <create_array+0x5e>
jmp    119a <create_array+0x8a>
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
store i32 0, i32* %7
%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 1, %13
%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
br label %21
21: ; preds = %25, %20
%22 = load i32, i32* %7
%23 = load i32, i32* %4
%24 = icmp ult i32 %22, %23
br i1 %24, label %25, label %33
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
%31 = load i32, i32* %7
%32 = add i32 %31, 1
store i32 %32, i32* %7
br label %21
33: ; preds = %21
br label %34
34: ; preds = %33
%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
}