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


x86 assembly (clang, -O0):
<ft_strnew>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
add    $0x1,%rdi
shl    $0x0,%rdi
call   1030 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    1148 <ft_strnew+0x38>
movq   $0x0,-0x8(%rbp)
jmp    1189 <ft_strnew+0x79>
jmp    114d <ft_strnew+0x3d>
cmpq   $0x0,-0x10(%rbp)
je     1175 <ft_strnew+0x65>
mov    -0x18(%rbp),%rax
mov    -0x10(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x10(%rbp)
jmp    114d <ft_strnew+0x3d>
mov    -0x18(%rbp),%rax
mov    -0x10(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
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,%rdi
call   1040 <malloc@plt>
test   %rax,%rax
je     1153 <ft_strnew+0x33>
mov    %rax,%rbx
test   %r14,%r14
je     114e <ft_strnew+0x2e>
mov    %rbx,%rdi
add    $0x1,%rdi
xor    %esi,%esi
mov    %r14,%rdx
call   1030 <memset@plt>
movb   $0x0,(%rbx)
jmp    1155 <ft_strnew+0x35>
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*
store i64 %0, i64* %3
%5 = load i64, i64* %3
%6 = add i64 %5, 1
%7 = mul i64 %6, 1
%8 = call i64 @malloc(i64 %7)
%9 = inttoptr i64 %8 to i8*
store i8* %9, i8** %4
%10 = icmp eq i8* %9, null
br i1 %10, label %11, label %12
11: ; preds = %1
store i8* null, i8** %2
br label %27
12: ; preds = %1
br label %13
13: ; preds = %16, %12
%14 = load i64, i64* %3
%15 = icmp ne i64 %14, 0
br i1 %15, label %16, label %22
16: ; preds = %13
%17 = load i8*, i8** %4
%18 = load i64, i64* %3
%19 = getelementptr inbounds i8, i8* %17, i64 %18
store i8 0, i8* %19
%20 = load i64, i64* %3
%21 = add i64 %20, -1
store i64 %21, i64* %3
br label %13
22: ; preds = %13
%23 = load i8*, i8** %4
%24 = load i64, i64* %3
%25 = getelementptr inbounds i8, i8* %23, i64 %24
store i8 0, i8* %25
%26 = load i8*, i8** %4
store i8* %26, i8** %2
br label %27
27: ; preds = %22, %11
%28 = load i8*, i8** %2
ret i8* %28
}

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