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


x86 assembly (clang, -O0):
<ft_strnew>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
movq   $0x0,-0x20(%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    1152 <ft_strnew+0x42>
movq   $0x0,-0x8(%rbp)
jmp    1195 <ft_strnew+0x85>
jmp    1157 <ft_strnew+0x47>
mov    -0x20(%rbp),%rax
cmp    -0x10(%rbp),%rax
ja     1181 <ft_strnew+0x71>
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    %rcx,%rdx
add    $0x1,%rdx
mov    %rdx,-0x20(%rbp)
movb   $0x0,(%rax,%rcx,1)
jmp    1157 <ft_strnew+0x47>
mov    -0x18(%rbp),%rax
mov    -0x20(%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,%edi
call   1040 <malloc@plt>
test   %rax,%rax
je     114d <ft_strnew+0x2d>
mov    %rax,%rbx
lea    0x1(%r14),%rdx
mov    %rax,%rdi
xor    %esi,%esi
call   1030 <memset@plt>
movb   $0x0,0x1(%rbx,%r14,1)
jmp    114f <ft_strnew+0x2f>
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
store i64 0, i64* %5
%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 eq i8* %11, null
br i1 %12, label %13, label %14
13: ; preds = %1
store i8* null, i8** %2
br label %29
14: ; preds = %1
br label %15
15: ; preds = %19, %14
%16 = load i64, i64* %5
%17 = load i64, i64* %3
%18 = icmp ule i64 %16, %17
br i1 %18, label %19, label %24
19: ; preds = %15
%20 = load i8*, i8** %4
%21 = load i64, i64* %5
%22 = add i64 %21, 1
store i64 %22, i64* %5
%23 = getelementptr inbounds i8, i8* %20, i64 %21
store i8 0, i8* %23
br label %15
24: ; preds = %15
%25 = load i8*, i8** %4
%26 = load i64, i64* %5
%27 = getelementptr inbounds i8, i8* %25, i64 %26
store i8 0, i8* %27
%28 = load i8*, i8** %4
store i8* %28, i8** %2
br label %29
29: ; preds = %24, %13
%30 = load i8*, i8** %2
ret i8* %30
}

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