#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);
char *ft_strnew(size_t size) {
  char *str;
  size_t i;
  if (!(str = (char *)malloc(sizeof(char) * (size + 1)))) {
    return (NULL);
  }
  str[size] = '\0';
  i = 0;
  while (i < size) {
    str[i] = '\0';
    i++;
  }
  return (str);
}


x86 assembly (clang, -O0):
<ft_strnew>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
shl    $0x0,%rax
mov    %eax,%edi
call   1030 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    114a <ft_strnew+0x3a>
movq   $0x0,-0x8(%rbp)
jmp    1191 <ft_strnew+0x81>
mov    -0x18(%rbp),%rax
mov    -0x10(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
movq   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    1189 <ft_strnew+0x79>
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    115e <ft_strnew+0x4e>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ft_strnew>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
add    $0x1,%edi
call   1040 <malloc@plt>
test   %rax,%rax
je     1150 <ft_strnew+0x30>
mov    %rax,%rbx
movb   $0x0,(%rax,%r14,1)
test   %r14,%r14
je     1152 <ft_strnew+0x32>
mov    %rbx,%rdi
xor    %esi,%esi
mov    %r14,%rdx
call   1030 <memset@plt>
jmp    1152 <ft_strnew+0x32>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
define i8* @ft_strnew(i64 %0) {
%2 = trunc i64 %0 to i32
%3 = add i32 %2, 1
%4 = tail call i64 @malloc(i32 %3)
%5 = inttoptr i64 %4 to i8*
%6 = icmp eq i64 %4, 0
br i1 %6, label %11, label %7
7: ; preds = %1
%8 = getelementptr inbounds i8, i8* %5, i64 %0
store i8 0, i8* %8
%9 = icmp eq i64 %0, 0
br i1 %9, label %11, label %10
10: ; preds = %7
br label %11
11: ; preds = %10, %7, %1
%12 = phi i8* [ null, %1 ], [ %5, %7 ], [ %5, %10 ]
ret i8* %12
}