#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 */
char *ft_strcat(char *, char *);
char *malloc(int);
int read(int /*<<< orphan*/, char *, int);
char *stdin_to_str(void) {
  int buffer_size;
  char *buffer;
  char *temp;
  int ret;
  buffer_size = 1024;
  temp = NULL;
  buffer = malloc(sizeof(char) * buffer_size);
  buffer[0] = '\0';
  ret = read(0, buffer, buffer_size);
  while (ret > 0) {
    temp = malloc(sizeof(char) * buffer_size);
    ret = read(0, temp, buffer_size);
    buffer = ft_strcat(buffer, temp);
  }
  return (buffer);
}


x86 assembly (clang, -O0):
<stdin_to_str>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x400,-0x4(%rbp)
movq   $0x0,-0x18(%rbp)
movslq -0x4(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rsi
mov    -0x4(%rbp),%edx
xor    %edi,%edi
call   1040 <read@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jle    11b6 <stdin_to_str+0x86>
movslq -0x4(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rsi
mov    -0x4(%rbp),%edx
xor    %edi,%edi
call   1040 <read@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <ft_strcat@plt>
mov    %rax,-0x10(%rbp)
jmp    1172 <stdin_to_str+0x42>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<stdin_to_str>:
push   %rbp
push   %r14
push   %rbx
mov    $0x400,%edi
call   1050 <malloc@plt>
mov    %rax,%r14
movb   $0x0,(%rax)
xor    %edi,%edi
mov    %rax,%rsi
mov    $0x400,%edx
call   1040 <read@plt>
test   %eax,%eax
jle    1190 <stdin_to_str+0x60>
nopw   0x0(%rax,%rax,1)
mov    $0x400,%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
xor    %edi,%edi
mov    %rax,%rsi
mov    $0x400,%edx
call   1040 <read@plt>
mov    %eax,%ebp
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <ft_strcat@plt>
mov    %rax,%r14
test   %ebp,%ebp
jg     1160 <stdin_to_str+0x30>
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i8* @stdin_to_str() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
store i32 1024, i32* %1
store i8* null, i8** %3
%5 = load i32, i32* %1
%6 = sext i32 %5 to i64
%7 = mul i64 1, %6
%8 = trunc i64 %7 to i32
%9 = call i8* @malloc(i32 %8)
store i8* %9, i8** %2
%10 = load i8*, i8** %2
%11 = getelementptr inbounds i8, i8* %10, i64 0
store i8 0, i8* %11
%12 = load i8*, i8** %2
%13 = load i32, i32* %1
%14 = call i32 @read(i32 0, i8* %12, i32 %13)
store i32 %14, i32* %4
br label %15
15: ; preds = %18, %0
%16 = load i32, i32* %4
%17 = icmp sgt i32 %16, 0
br i1 %17, label %18, label %30
18: ; preds = %15
%19 = load i32, i32* %1
%20 = sext i32 %19 to i64
%21 = mul i64 1, %20
%22 = trunc i64 %21 to i32
%23 = call i8* @malloc(i32 %22)
store i8* %23, i8** %3
%24 = load i8*, i8** %3
%25 = load i32, i32* %1
%26 = call i32 @read(i32 0, i8* %24, i32 %25)
store i32 %26, i32* %4
%27 = load i8*, i8** %2
%28 = load i8*, i8** %3
%29 = call i8* @ft_strcat(i8* %27, i8* %28)
store i8* %29, i8** %2
br label %15
30: ; preds = %15
%31 = load i8*, i8** %2
ret i8* %31
}

LLVM IR (-O2):
define i8* @stdin_to_str() {
%1 = tail call dereferenceable_or_null(1024) i8* @malloc(i32 1024)
store i8 0, i8* %1
%2 = tail call i32 @read(i32 0, i8* %1, i32 1024)
%3 = icmp sgt i32 %2, 0
br i1 %3, label %4, label %10
4: ; preds = %0, %4
%5 = phi i8* [ %8, %4 ], [ %1, %0 ]
%6 = tail call dereferenceable_or_null(1024) i8* @malloc(i32 1024)
%7 = tail call i32 @read(i32 0, i8* %6, i32 1024)
%8 = tail call i8* @ft_strcat(i8* %5, i8* %6)
%9 = icmp sgt i32 %7, 0
br i1 %9, label %4, label %10
10: ; preds = %4, %0
%11 = phi i8* [ %1, %0 ], [ %8, %4 ]
ret i8* %11
}