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


x86 assembly (clang, -O0):
<ft_strnew>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1134 <ft_strnew+0x24>
movq   $0x0,-0x8(%rbp)
jmp    11a4 <ft_strnew+0x94>
mov    -0x10(%rbp),%rax
shl    $0x0,%rax
add    $0x1,%rax
mov    %eax,%edi
call   1030 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1163 <ft_strnew+0x53>
movq   $0x0,-0x8(%rbp)
jmp    11a4 <ft_strnew+0x94>
jmp    1168 <ft_strnew+0x58>
cmpq   $0x0,-0x10(%rbp)
je     1190 <ft_strnew+0x80>
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    1168 <ft_strnew+0x58>
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
test   %rdi,%rdi
je     1152 <ft_strnew+0x32>
mov    %rdi,%r14
add    $0x1,%edi
call   1040 <malloc@plt>
test   %rax,%rax
je     1152 <ft_strnew+0x32>
mov    %rax,%rbx
mov    %rax,%rdi
add    $0x1,%rdi
xor    %esi,%esi
mov    %r14,%rdx
call   1030 <memset@plt>
movb   $0x0,(%rbx)
jmp    1154 <ft_strnew+0x34>
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 = icmp ne i64 %5, 0
br i1 %6, label %8, label %7
7: ; preds = %1
store i8* null, i8** %2
br label %33
8: ; preds = %1
%9 = load i64, i64* %3
%10 = mul i64 1, %9
%11 = add i64 %10, 1
%12 = trunc i64 %11 to i32
%13 = call i64 @malloc(i32 %12)
%14 = inttoptr i64 %13 to i8*
store i8* %14, i8** %4
%15 = load i8*, i8** %4
%16 = icmp ne i8* %15, null
br i1 %16, label %18, label %17
17: ; preds = %8
store i8* null, i8** %2
br label %33
18: ; preds = %8
br label %19
19: ; preds = %22, %18
%20 = load i64, i64* %3
%21 = icmp ne i64 %20, 0
br i1 %21, label %22, label %28
22: ; preds = %19
%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 i64, i64* %3
%27 = add i64 %26, -1
store i64 %27, i64* %3
br label %19
28: ; preds = %19
%29 = load i8*, i8** %4
%30 = load i64, i64* %3
%31 = getelementptr inbounds i8, i8* %29, i64 %30
store i8 0, i8* %31
%32 = load i8*, i8** %4
store i8* %32, i8** %2
br label %33
33: ; preds = %28, %17, %7
%34 = load i8*, i8** %2
ret i8* %34
}

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