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


x86 assembly (clang, -O0):
<ft_strnew>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
add    $0x1,%rdi
shl    $0x0,%rdi
call   1030 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    1150 <ft_strnew+0x40>
movq   $0x0,-0x8(%rbp)
jmp    1194 <ft_strnew+0x84>
jmp    1155 <ft_strnew+0x45>
mov    -0x18(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    1180 <ft_strnew+0x70>
mov    -0x20(%rbp),%rax
mov    -0x18(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1155 <ft_strnew+0x45>
mov    -0x20(%rbp),%rax
mov    -0x10(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x20(%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     1151 <ft_strnew+0x31>
mov    %rax,%rbx
test   %r14,%r14
je     114a <ft_strnew+0x2a>
mov    %rbx,%rdi
xor    %esi,%esi
mov    %r14,%rdx
call   1030 <memset@plt>
movb   $0x0,(%rbx,%r14,1)
jmp    1153 <ft_strnew+0x33>
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 i64
%5 = alloca i8*
store i64 %0, i64* %3
store i64 0, i64* %4
%6 = load i64, i64* %3
%7 = add i64 %6, 1
%8 = mul i64 %7, 1
%9 = call i64 @malloc(i64 %8)
%10 = inttoptr i64 %9 to i8*
store i8* %10, i8** %5
%11 = icmp ne i8* %10, null
br i1 %11, label %13, label %12
12: ; preds = %1
store i8* null, i8** %2
br label %29
13: ; preds = %1
br label %14
14: ; preds = %18, %13
%15 = load i64, i64* %4
%16 = load i64, i64* %3
%17 = icmp ult i64 %15, %16
br i1 %17, label %18, label %24
18: ; preds = %14
%19 = load i8*, i8** %5
%20 = load i64, i64* %4
%21 = getelementptr inbounds i8, i8* %19, i64 %20
store i8 0, i8* %21
%22 = load i64, i64* %4
%23 = add i64 %22, 1
store i64 %23, i64* %4
br label %14
24: ; preds = %14
%25 = load i8*, i8** %5
%26 = load i64, i64* %3
%27 = getelementptr inbounds i8, i8* %25, i64 %26
store i8 0, i8* %27
%28 = load i8*, i8** %5
store i8* %28, i8** %2
br label %29
29: ; preds = %24, %12
%30 = load i8*, i8** %2
ret i8* %30
}

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 %9, label %8
8: ; preds = %6
br label %9
9: ; preds = %8, %6
%10 = getelementptr inbounds i8, i8* %4, i64 %0
store i8 0, i8* %10
br label %11
11: ; preds = %1, %9
%12 = phi i8* [ %4, %9 ], [ null, %1 ]
ret i8* %12
}