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


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)
cmpq   $0x0,-0x18(%rbp)
je     117f <ft_strnew+0x6f>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1172 <ft_strnew+0x62>
mov    -0x10(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x10(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    114a <ft_strnew+0x3a>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1187 <ft_strnew+0x77>
movq   $0x0,-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,%rbx
add    $0x1,%rbx
mov    %ebx,%edi
call   1040 <malloc@plt>
test   %rax,%rax
je     114e <ft_strnew+0x2e>
mov    %rax,%r14
test   %rbx,%rbx
je     1151 <ft_strnew+0x31>
mov    %r14,%rdi
xor    %esi,%esi
mov    %rbx,%rdx
call   1030 <memset@plt>
jmp    1151 <ft_strnew+0x31>
xor    %r14d,%r14d
mov    %r14,%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*
store i64 %0, i64* %3
%5 = load i64, i64* %3
%6 = add i64 %5, 1
%7 = mul i64 1, %6
%8 = trunc i64 %7 to i32
%9 = call i64 @malloc(i32 %8)
%10 = inttoptr i64 %9 to i8*
store i8* %10, i8** %4
%11 = load i8*, i8** %4
%12 = icmp ne i8* %11, null
br i1 %12, label %13, label %27
13: ; preds = %1
%14 = load i64, i64* %3
%15 = add i64 %14, 1
store i64 %15, i64* %3
br label %16
16: ; preds = %19, %13
%17 = load i64, i64* %3
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %25
19: ; preds = %16
%20 = load i64, i64* %3
%21 = add i64 %20, -1
store i64 %21, i64* %3
%22 = load i8*, i8** %4
%23 = load i64, i64* %3
%24 = getelementptr inbounds i8, i8* %22, i64 %23
store i8 0, i8* %24
br label %16
25: ; preds = %16
%26 = load i8*, i8** %4
store i8* %26, i8** %2
br label %28
27: ; preds = %1
store i8* null, i8** %2
br label %28
28: ; preds = %27, %25
%29 = load i8*, i8** %2
ret i8* %29
}

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