#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 BUFSIZ;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int fread(char *, int, int, int /*<<< orphan*/);
char *malloc(int);
char *realloc(char *, int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
char *get_data_from_stdin(int *len_return) {
  char *cp;
  int count;
  int allocated;
  int n;
  allocated = BUFSIZ;
  cp = malloc(allocated + 1);
  if (!cp) {
    fprintf(stderr, "cannot get memory for message file\n");
    return NULL;
  }
  count = 0;
  while ((n = fread(cp + count, 1, BUFSIZ, stdin)) > 0) {
    count += n;
    if (count + BUFSIZ > allocated) {
      allocated = 2 * allocated;
      cp = realloc(cp, allocated + 1);
      if (!cp) {
        fprintf(stderr, "cannot get memory for message file\n");
        return NULL;
      }
    }
  }
  cp[count] = '\0';
  *len_return = count;
  return cp;
}


x86 assembly (clang, -O0):
<get_data_from_stdin>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    0x2e7d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%edi
add    $0x1,%edi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1194 <get_data_from_stdin+0x54>
mov    0x2e5f(%rip),%rax
mov    (%rax),%edi
lea    0xe7e(%rip),%rsi
call   1040 <fprintf@plt>
movq   $0x0,-0x8(%rbp)
jmp    125c <get_data_from_stdin+0x11c>
movl   $0x0,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
movslq -0x1c(%rbp),%rax
add    %rax,%rdi
mov    0x2e23(%rip),%rax
mov    (%rax),%edx
mov    0x2e32(%rip),%rax
mov    (%rax),%ecx
mov    $0x1,%esi
call   1030 <fread@plt>
mov    %eax,-0x24(%rbp)
cmp    $0x0,%eax
jle    123f <get_data_from_stdin+0xff>
mov    -0x24(%rbp),%eax
add    -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    0x2def(%rip),%rcx
add    (%rcx),%eax
cmp    -0x20(%rbp),%eax
jle    123a <get_data_from_stdin+0xfa>
mov    -0x20(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%esi
add    $0x1,%esi
call   1060 <realloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1235 <get_data_from_stdin+0xf5>
mov    0x2dbe(%rip),%rax
mov    (%rax),%edi
lea    0xddd(%rip),%rsi
call   1040 <fprintf@plt>
movq   $0x0,-0x8(%rbp)
jmp    125c <get_data_from_stdin+0x11c>
jmp    123a <get_data_from_stdin+0xfa>
jmp    119b <get_data_from_stdin+0x5b>
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x1c(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_data_from_stdin>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    0x2e7b(%rip),%r13
mov    0x0(%r13),%r15d
lea    0x1(%r15),%edi
call   1050 <malloc@plt>
test   %rax,%rax
je     11ee <get_data_from_stdin+0xae>
mov    %rax,%r12
mov    0x2e73(%rip),%rbp
mov    0x0(%rbp),%ecx
mov    %rax,%rdi
mov    $0x1,%esi
mov    %r15d,%edx
call   1030 <fread@plt>
test   %eax,%eax
mov    %rbx,(%rsp)
jle    1208 <get_data_from_stdin+0xc8>
xor    %r14d,%r14d
jmp    11c4 <get_data_from_stdin+0x84>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %rax,%r12
add    %r15d,%r15d
mov    0x0(%r13),%edx
movslq %r14d,%rbx
add    %r12,%rbx
mov    0x0(%rbp),%ecx
mov    %rbx,%rdi
mov    $0x1,%esi
call   1030 <fread@plt>
test   %eax,%eax
jle    120e <get_data_from_stdin+0xce>
mov    %r14d,%ecx
mov    %eax,%r14d
add    %ecx,%r14d
mov    0x0(%r13),%edx
lea    (%rdx,%r14,1),%eax
cmp    %r15d,%eax
jle    11aa <get_data_from_stdin+0x6a>
lea    (%r15,%r15,1),%esi
add    $0x1,%esi
mov    %r12,%rdi
call   1060 <realloc@plt>
test   %rax,%rax
jne    11a0 <get_data_from_stdin+0x60>
mov    0x2de3(%rip),%rax
mov    (%rax),%edi
lea    0xe02(%rip),%rsi
call   1040 <fprintf@plt>
xor    %r12d,%r12d
jmp    1218 <get_data_from_stdin+0xd8>
xor    %r14d,%r14d
mov    %r12,%rbx
movb   $0x0,(%rbx)
mov    (%rsp),%rax
mov    %r14d,(%rax)
mov    %r12,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@BUFSIZ = global i32 0
@stderr = global i32 0
@.str = [36 x i8] c"cannot get memory for message file\0A\00"
@stdin = global i32 0
define i8* @get_data_from_stdin(i32* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32* %0, i32** %3
%8 = load i32, i32* @BUFSIZ
store i32 %8, i32* %6
%9 = load i32, i32* %6
%10 = add nsw i32 %9, 1
%11 = call i8* @malloc(i32 %10)
store i8* %11, i8** %4
%12 = load i8*, i8** %4
%13 = icmp ne i8* %12, null
br i1 %13, label %17, label %14
14: ; preds = %1
%15 = load i32, i32* @stderr
%16 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
store i8* null, i8** %2
br label %58
17: ; preds = %1
store i32 0, i32* %5
br label %18
18: ; preds = %49, %17
%19 = load i8*, i8** %4
%20 = load i32, i32* %5
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i8, i8* %19, i64 %21
%23 = load i32, i32* @BUFSIZ
%24 = load i32, i32* @stdin
%25 = call i32 @fread(i8* %22, i32 1, i32 %23, i32 %24)
store i32 %25, i32* %7
%26 = icmp sgt i32 %25, 0
br i1 %26, label %27, label %50
27: ; preds = %18
%28 = load i32, i32* %7
%29 = load i32, i32* %5
%30 = add nsw i32 %29, %28
store i32 %30, i32* %5
%31 = load i32, i32* %5
%32 = load i32, i32* @BUFSIZ
%33 = add nsw i32 %31, %32
%34 = load i32, i32* %6
%35 = icmp sgt i32 %33, %34
br i1 %35, label %36, label %49
36: ; preds = %27
%37 = load i32, i32* %6
%38 = mul nsw i32 2, %37
store i32 %38, i32* %6
%39 = load i8*, i8** %4
%40 = load i32, i32* %6
%41 = add nsw i32 %40, 1
%42 = call i8* @realloc(i8* %39, i32 %41)
store i8* %42, i8** %4
%43 = load i8*, i8** %4
%44 = icmp ne i8* %43, null
br i1 %44, label %48, label %45
45: ; preds = %36
%46 = load i32, i32* @stderr
%47 = call i32 @fprintf(i32 %46, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
store i8* null, i8** %2
br label %58
48: ; preds = %36
br label %49
49: ; preds = %48, %27
br label %18
50: ; preds = %18
%51 = load i8*, i8** %4
%52 = load i32, i32* %5
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds i8, i8* %51, i64 %53
store i8 0, i8* %54
%55 = load i32, i32* %5
%56 = load i32*, i32** %3
store i32 %55, i32* %56
%57 = load i8*, i8** %4
store i8* %57, i8** %2
br label %58
58: ; preds = %50, %45, %14
%59 = load i8*, i8** %2
ret i8* %59
}

LLVM IR (-O2):
@BUFSIZ = global i32 0
@stderr = global i32 0
@.str = [36 x i8] c"cannot get memory for message file\0A\00"
@stdin = global i32 0
define i8* @get_data_from_stdin(i32* nocapture writeonly %0) {
%2 = load i32, i32* @BUFSIZ
%3 = add nsw i32 %2, 1
%4 = tail call i8* @malloc(i32 %3)
%5 = icmp eq i8* %4, null
br i1 %5, label %10, label %6
6: ; preds = %1
%7 = load i32, i32* @stdin
%8 = tail call i32 @fread(i8* %4, i32 1, i32 %2, i32 %7)
%9 = icmp sgt i32 %8, 0
br i1 %9, label %13, label %41
10: ; preds = %1
%11 = load i32, i32* @stderr
%12 = tail call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
br label %45
13: ; preds = %6, %32
%14 = phi i32 [ %39, %32 ], [ %8, %6 ]
%15 = phi i32 [ %35, %32 ], [ %2, %6 ]
%16 = phi i32 [ %18, %32 ], [ 0, %6 ]
%17 = phi i8* [ %34, %32 ], [ %4, %6 ]
%18 = add nsw i32 %14, %16
%19 = load i32, i32* @BUFSIZ
%20 = add nsw i32 %19, %18
%21 = icmp sgt i32 %20, %15
br i1 %21, label %22, label %32
22: ; preds = %13
%23 = shl nsw i32 %15, 1
%24 = or i32 %23, 1
%25 = tail call i8* @realloc(i8* %17, i32 %24)
%26 = icmp eq i8* %25, null
br i1 %26, label %29, label %27
27: ; preds = %22
%28 = load i32, i32* @BUFSIZ
br label %32
29: ; preds = %22
%30 = load i32, i32* @stderr
%31 = tail call i32 @fprintf(i32 %30, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
br label %45
32: ; preds = %27, %13
%33 = phi i32 [ %28, %27 ], [ %19, %13 ]
%34 = phi i8* [ %25, %27 ], [ %17, %13 ]
%35 = phi i32 [ %23, %27 ], [ %15, %13 ]
%36 = sext i32 %18 to i64
%37 = getelementptr inbounds i8, i8* %34, i64 %36
%38 = load i32, i32* @stdin
%39 = tail call i32 @fread(i8* %37, i32 1, i32 %33, i32 %38)
%40 = icmp sgt i32 %39, 0
br i1 %40, label %13, label %41
41: ; preds = %32, %6
%42 = phi i8* [ %4, %6 ], [ %34, %32 ]
%43 = phi i32 [ 0, %6 ], [ %18, %32 ]
%44 = phi i8* [ %4, %6 ], [ %37, %32 ]
store i8 0, i8* %44
store i32 %43, i32* %0
br label %45
45: ; preds = %41, %29, %10
%46 = phi i8* [ null, %29 ], [ %42, %41 ], [ null, %10 ]
ret i8* %46
}