#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 */
int /*<<< orphan*/ exit(int);
scalar_t__ malloc(int);
char *ft_strnew(size_t size) {
  size_t i;
  char *ptr;
  ptr = (char *)malloc(sizeof(char) * (size + 1));
  if (ptr) {
    i = 0;
    while (i < size) {
      ptr[i] = '\0';
      i++;
    }
    ptr[i] = '\0';
    return (ptr);
  } else
    exit(1);
  return (NULL);
}


x86 assembly (clang, -O0):
<ft_strnew>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x1,%rax
shl    $0x0,%rax
mov    %eax,%edi
call   1030 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1197 <ft_strnew+0x77>
movq   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%rax
cmp    -0x8(%rbp),%rax
jae    1181 <ft_strnew+0x61>
mov    -0x18(%rbp),%rax
mov    -0x10(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1156 <ft_strnew+0x36>
mov    -0x18(%rbp),%rax
mov    -0x10(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret
mov    $0x1,%edi
call   1040 <exit@plt>

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     1169 <ft_strnew+0x39>
mov    %rax,%rbx
test   %r14,%r14
je     1159 <ft_strnew+0x29>
mov    %rbx,%rdi
xor    %esi,%esi
mov    %r14,%rdx
call   1030 <memset@plt>
movb   $0x0,(%rbx,%r14,1)
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    $0x1,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
define i8* @ft_strnew(i64 %0) {
%2 = alloca i64
%3 = alloca i64
%4 = alloca i8*
store i64 %0, i64* %2
%5 = load i64, i64* %2
%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 %29
13: ; preds = %1
store i64 0, i64* %3
br label %14
14: ; preds = %18, %13
%15 = load i64, i64* %3
%16 = load i64, i64* %2
%17 = icmp ult i64 %15, %16
br i1 %17, label %18, label %24
18: ; preds = %14
%19 = load i8*, i8** %4
%20 = load i64, i64* %3
%21 = getelementptr inbounds i8, i8* %19, i64 %20
store i8 0, i8* %21
%22 = load i64, i64* %3
%23 = add i64 %22, 1
store i64 %23, i64* %3
br label %14
24: ; preds = %14
%25 = load i8*, i8** %4
%26 = load i64, i64* %3
%27 = getelementptr inbounds i8, i8* %25, i64 %26
store i8 0, i8* %27
%28 = load i8*, i8** %4
ret i8* %28
29: ; preds = %1
%30 = call i32 @exit(i32 1)
unreachable
}

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 %12, label %7
7: ; preds = %1
%8 = icmp eq i64 %0, 0
br i1 %8, label %10, label %9
9: ; preds = %7
br label %10
10: ; preds = %9, %7
%11 = getelementptr inbounds i8, i8* %5, i64 %0
store i8 0, i8* %11
ret i8* %5
12: ; preds = %1
%13 = tail call i32 @exit(i32 1)
unreachable
}