#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 EOF;
int fgetc(int /*<<< orphan*/);
char *malloc(int);
char *realloc(char *, int);
int /*<<< orphan*/ stdin;
char *d_s(char *s) {
  int c;
  int mult = 1;
  long int sz = 0;
  s = malloc(sizeof(char) * 100);
  while ((c = fgetc(stdin)) != '\n' && c != EOF) {
    if (++sz > (mult * 100)) {
      s = realloc(s, sizeof(char) * 100 * ++mult);
    }
    *(s + (sz - 1)) = c;
  }
  *(s + sz) = '\0';
  return s;
}


x86 assembly (clang, -O0):
<d_s>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x1,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    $0x64,%edi
call   1040 <malloc@plt>
mov    %rax,-0x8(%rbp)
mov    0x2e88(%rip),%rax
mov    (%rax),%edi
call   1030 <fgetc@plt>
mov    %eax,%ecx
mov    %ecx,-0xc(%rbp)
xor    %eax,%eax
cmp    $0xa,%ecx
mov    %al,-0x19(%rbp)
je     118c <d_s+0x5c>
mov    -0xc(%rbp),%eax
mov    0x2e5c(%rip),%rcx
cmp    (%rcx),%eax
setne  %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    119c <d_s+0x6c>
jmp    11ef <d_s+0xbf>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
imul   $0x64,-0x10(%rbp),%ecx
movslq %ecx,%rcx
cmp    %rcx,%rax
jle    11d6 <d_s+0xa6>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
cltq
imul   $0x64,%rax,%rax
mov    %eax,%esi
call   1050 <realloc@plt>
mov    %rax,-0x8(%rbp)
mov    -0xc(%rbp),%eax
mov    %al,%dl
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
sub    $0x1,%rcx
mov    %dl,(%rax,%rcx,1)
jmp    1159 <d_s+0x29>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<d_s>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    $0x64,%edi
call   1040 <malloc@plt>
mov    %rax,%r14
mov    0x2e99(%rip),%r15
mov    (%r15),%edi
call   1030 <fgetc@plt>
xor    %ebx,%ebx
cmp    $0xa,%eax
je     11bb <d_s+0x8b>
mov    %eax,%ebp
mov    0x2e79(%rip),%r12
cmp    (%r12),%eax
je     11bb <d_s+0x8b>
mov    $0x1,%r13d
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nop
imul   $0x64,%r13d,%eax
cltq
cmp    %rax,%rbx
jl     119e <d_s+0x6e>
add    $0x1,%r13d
imul   $0x64,%r13d,%esi
mov    %r14,%rdi
call   1050 <realloc@plt>
mov    %rax,%r14
mov    %bpl,(%r14,%rbx,1)
mov    (%r15),%edi
call   1030 <fgetc@plt>
add    $0x1,%rbx
cmp    $0xa,%eax
je     11bb <d_s+0x8b>
mov    %eax,%ebp
cmp    (%r12),%eax
jne    1180 <d_s+0x50>
movb   $0x0,(%r14,%rbx,1)
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stdin = global i32 0
@EOF = global i32 0
define i8* @d_s(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i64
store i8* %0, i8** %2
store i32 1, i32* %4
store i64 0, i64* %5
%6 = call i8* @malloc(i32 100)
store i8* %6, i8** %2
br label %7
7: ; preds = %32, %1
%8 = load i32, i32* @stdin
%9 = call i32 @fgetc(i32 %8)
store i32 %9, i32* %3
%10 = icmp ne i32 %9, 10
br i1 %10, label %11, label %15
11: ; preds = %7
%12 = load i32, i32* %3
%13 = load i32, i32* @EOF
%14 = icmp ne i32 %12, %13
br label %15
15: ; preds = %11, %7
%16 = phi i1 [ false, %7 ], [ %14, %11 ]
br i1 %16, label %17, label %39
17: ; preds = %15
%18 = load i64, i64* %5
%19 = add nsw i64 %18, 1
store i64 %19, i64* %5
%20 = load i32, i32* %4
%21 = mul nsw i32 %20, 100
%22 = sext i32 %21 to i64
%23 = icmp sgt i64 %19, %22
br i1 %23, label %24, label %32
24: ; preds = %17
%25 = load i8*, i8** %2
%26 = load i32, i32* %4
%27 = add nsw i32 %26, 1
store i32 %27, i32* %4
%28 = sext i32 %27 to i64
%29 = mul i64 100, %28
%30 = trunc i64 %29 to i32
%31 = call i8* @realloc(i8* %25, i32 %30)
store i8* %31, i8** %2
br label %32
32: ; preds = %24, %17
%33 = load i32, i32* %3
%34 = trunc i32 %33 to i8
%35 = load i8*, i8** %2
%36 = load i64, i64* %5
%37 = sub nsw i64 %36, 1
%38 = getelementptr inbounds i8, i8* %35, i64 %37
store i8 %34, i8* %38
br label %7
39: ; preds = %15
%40 = load i8*, i8** %2
%41 = load i64, i64* %5
%42 = getelementptr inbounds i8, i8* %40, i64 %41
store i8 0, i8* %42
%43 = load i8*, i8** %2
ret i8* %43
}

LLVM IR (-O2):
@stdin = global i32 0
@EOF = global i32 0
define i8* @d_s(i8* nocapture readnone %0) {
%2 = tail call dereferenceable_or_null(100) i8* @malloc(i32 100)
%3 = load i32, i32* @stdin
%4 = tail call i32 @fgetc(i32 %3)
%5 = icmp ne i32 %4, 10
%6 = load i32, i32* @EOF
%7 = icmp ne i32 %4, %6
%8 = select i1 %5, i1 %7, i1 false
br i1 %8, label %9, label %33
9: ; preds = %1, %22
%10 = phi i32 [ %28, %22 ], [ %4, %1 ]
%11 = phi i64 [ %14, %22 ], [ 0, %1 ]
%12 = phi i32 [ %24, %22 ], [ 1, %1 ]
%13 = phi i8* [ %23, %22 ], [ %2, %1 ]
%14 = add nuw nsw i64 %11, 1
%15 = mul nsw i32 %12, 100
%16 = sext i32 %15 to i64
%17 = icmp slt i64 %11, %16
br i1 %17, label %22, label %18
18: ; preds = %9
%19 = add nsw i32 %12, 1
%20 = mul i32 %19, 100
%21 = tail call i8* @realloc(i8* %13, i32 %20)
br label %22
22: ; preds = %18, %9
%23 = phi i8* [ %21, %18 ], [ %13, %9 ]
%24 = phi i32 [ %19, %18 ], [ %12, %9 ]
%25 = trunc i32 %10 to i8
%26 = getelementptr inbounds i8, i8* %23, i64 %11
store i8 %25, i8* %26
%27 = load i32, i32* @stdin
%28 = tail call i32 @fgetc(i32 %27)
%29 = icmp ne i32 %28, 10
%30 = load i32, i32* @EOF
%31 = icmp ne i32 %28, %30
%32 = select i1 %29, i1 %31, i1 false
br i1 %32, label %9, label %33
33: ; preds = %22, %1
%34 = phi i8* [ %2, %1 ], [ %23, %22 ]
%35 = phi i64 [ 0, %1 ], [ %14, %22 ]
%36 = getelementptr inbounds i8, i8* %34, i64 %35
store i8 0, i8* %36
ret i8* %34
}