#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*/ free(char *);
char getchar();
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ realloc(char *, int);
void stroe_in_memory() {
  int index = 1, interval = 1;
  char *string = NULL, input;
  while (1 == 1) {
    if (index % 10 == 0) {
      string = (char *)realloc(string, 10 * interval * sizeof(char));
    } else {
      string = (char *)malloc(10 * sizeof(char));
    }
    if (string != NULL) {
      for (index = 10 * (interval - 1); index < 10 * interval; ++index) {
        if ((input = getchar()) == '\n') {
          *(string + index) = '\0';
          break;
        }
        *(string + index) = input;
      }
      if (input == '\n') {
        break;
      }
      ++interval;
    } else {
      printf("\nCan't find free space in memory\n");
      break;
    }
  }
  printf("\nthe string we get is %s\n", string);
  if (string != NULL) {
    free(string);
  }
}


x86 assembly (clang, -O0):
<stroe_in_memory>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
mov    -0x4(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    11a0 <stroe_in_memory+0x50>
mov    -0x10(%rbp),%rdi
imul   $0xa,-0x8(%rbp),%eax
cltq
shl    $0x0,%rax
mov    %eax,%esi
call   1070 <realloc@plt>
mov    %rax,-0x10(%rbp)
jmp    11ae <stroe_in_memory+0x5e>
mov    $0xa,%edi
call   1060 <malloc@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1237 <stroe_in_memory+0xe7>
mov    -0x8(%rbp),%eax
sub    $0x1,%eax
imul   $0xa,%eax,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
imul   $0xa,-0x8(%rbp),%ecx
cmp    %ecx,%eax
jge    1217 <stroe_in_memory+0xc7>
mov    $0x0,%al
call   1050 <getchar@plt>
mov    %al,-0x11(%rbp)
movsbl %al,%eax
cmp    $0xa,%eax
jne    11fb <stroe_in_memory+0xab>
mov    -0x10(%rbp),%rax
movslq -0x4(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    1217 <stroe_in_memory+0xc7>
mov    -0x11(%rbp),%dl
mov    -0x10(%rbp),%rax
movslq -0x4(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    11c5 <stroe_in_memory+0x75>
movsbl -0x11(%rbp),%eax
cmp    $0xa,%eax
jne    1229 <stroe_in_memory+0xd9>
jmp    124f <stroe_in_memory+0xff>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    124a <stroe_in_memory+0xfa>
lea    0xdc2(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    124f <stroe_in_memory+0xff>
jmp    116e <stroe_in_memory+0x1e>
mov    -0x10(%rbp),%rsi
lea    0xdc8(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
cmpq   $0x0,-0x10(%rbp)
je     1275 <stroe_in_memory+0x125>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<stroe_in_memory>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    $0x1,%ebx
mov    $0x1,%r14d
movabs $0x100000000,%r15
xor    %ebp,%ebp
xor    %r13d,%r13d
imul   $0xcccccccd,%ebx,%eax
add    $0x19999998,%eax
ror    %eax
cmp    $0x19999998,%eax
jbe    11b0 <stroe_in_memory+0x50>
mov    $0xa,%edi
call   1070 <malloc@plt>
jmp    11bf <stroe_in_memory+0x5f>
cs nopw 0x0(%rax,%rax,1)
nop
lea    (%r14,%r14,1),%eax
lea    (%rax,%rax,4),%esi
mov    %r13,%rdi
call   1080 <realloc@plt>
mov    %rax,%r13
test   %rax,%rax
je     1263 <stroe_in_memory+0x103>
lea    (%r14,%r14,1),%ecx
lea    (%rcx,%rcx,4),%eax
cmp    $0x8000000a,%eax
jl     1220 <stroe_in_memory+0xc0>
mov    %ebp,0x4(%rsp)
movslq %ebp,%rbx
mov    %rbx,%rbp
shl    $0x20,%rbp
movslq %eax,%r12
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1060 <getchar@plt>
cmp    $0xa,%al
je     1232 <stroe_in_memory+0xd2>
mov    %al,0x0(%r13,%rbx,1)
add    $0x1,%rbx
add    %r15,%rbp
cmp    %r12,%rbx
jl     11f0 <stroe_in_memory+0x90>
mov    0x4(%rsp),%ebp
jmp    1226 <stroe_in_memory+0xc6>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
lea    (%rcx,%rcx,4),%ebx
add    $0xfffffff6,%ebx
add    $0x1,%r14
add    $0xa,%ebp
jmp    1185 <stroe_in_memory+0x25>
sar    $0x20,%rbp
movb   $0x0,0x0(%r13,%rbp,1)
lea    0xdbd(%rip),%rdi
mov    %r13,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r13,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <free@plt>
lea    0xdb0(%rip),%rdi
call   1040 <puts@plt>
lea    0xd8a(%rip),%rdi
xor    %esi,%esi
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <printf@plt>

LLVM IR (-O0):
@.str = [34 x i8] c"\0ACan't find free space in memory\0A\00"
@.str.1 = [26 x i8] c"\0Athe string we get is %s\0A\00"
define void @stroe_in_memory() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8
store i32 1, i32* %1
store i32 1, i32* %2
store i8* null, i8** %3
br label %5
5: ; preds = %0, %61
%6 = load i32, i32* %1
%7 = srem i32 %6, 10
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %18
9: ; preds = %5
%10 = load i8*, i8** %3
%11 = load i32, i32* %2
%12 = mul nsw i32 10, %11
%13 = sext i32 %12 to i64
%14 = mul i64 %13, 1
%15 = trunc i64 %14 to i32
%16 = call i64 @realloc(i8* %10, i32 %15)
%17 = inttoptr i64 %16 to i8*
store i8* %17, i8** %3
br label %21
18: ; preds = %5
%19 = call i64 @malloc(i32 10)
%20 = inttoptr i64 %19 to i8*
store i8* %20, i8** %3
br label %21
21: ; preds = %18, %9
%22 = load i8*, i8** %3
%23 = icmp ne i8* %22, null
br i1 %23, label %24, label %59
24: ; preds = %21
%25 = load i32, i32* %2
%26 = sub nsw i32 %25, 1
%27 = mul nsw i32 10, %26
store i32 %27, i32* %1
br label %28
28: ; preds = %48, %24
%29 = load i32, i32* %1
%30 = load i32, i32* %2
%31 = mul nsw i32 10, %30
%32 = icmp slt i32 %29, %31
br i1 %32, label %33, label %51
33: ; preds = %28
%34 = call signext i8 (...) @getchar()
store i8 %34, i8* %4
%35 = sext i8 %34 to i32
%36 = icmp eq i32 %35, 10
br i1 %36, label %37, label %42
37: ; preds = %33
%38 = load i8*, i8** %3
%39 = load i32, i32* %1
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i8, i8* %38, i64 %40
store i8 0, i8* %41
br label %51
42: ; preds = %33
%43 = load i8, i8* %4
%44 = load i8*, i8** %3
%45 = load i32, i32* %1
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds i8, i8* %44, i64 %46
store i8 %43, i8* %47
br label %48
48: ; preds = %42
%49 = load i32, i32* %1
%50 = add nsw i32 %49, 1
store i32 %50, i32* %1
br label %28
51: ; preds = %37, %28
%52 = load i8, i8* %4
%53 = sext i8 %52 to i32
%54 = icmp eq i32 %53, 10
br i1 %54, label %55, label %56
55: ; preds = %51
br label %62
56: ; preds = %51
%57 = load i32, i32* %2
%58 = add nsw i32 %57, 1
store i32 %58, i32* %2
br label %61
59: ; preds = %21
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
br label %62
61: ; preds = %56
br label %5
62: ; preds = %59, %55
%63 = load i8*, i8** %3
%64 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* %63)
%65 = load i8*, i8** %3
%66 = icmp ne i8* %65, null
br i1 %66, label %67, label %70
67: ; preds = %62
%68 = load i8*, i8** %3
%69 = call i32 @free(i8* %68)
br label %70
70: ; preds = %67, %62
ret void
}

LLVM IR (-O2):
@.str.1 = [26 x i8] c"\0Athe string we get is %s\0A\00"
@str = [33 x i8] c"\0ACan't find free space in memory\00"
define void @stroe_in_memory() {
br label %1
1: ; preds = %36, %0
%2 = phi i64 [ %38, %36 ], [ 1, %0 ]
%3 = phi i32 [ %39, %36 ], [ 0, %0 ]
%4 = phi i32 [ %37, %36 ], [ 1, %0 ]
%5 = phi i8* [ %17, %36 ], [ null, %0 ]
%6 = sext i32 %3 to i64
%7 = srem i32 %4, 10
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %13
9: ; preds = %1
%10 = trunc i64 %2 to i32
%11 = mul i32 %10, 10
%12 = tail call i64 @realloc(i8* %5, i32 %11)
br label %15
13: ; preds = %1
%14 = tail call i64 @malloc(i32 10)
br label %15
15: ; preds = %13, %9
%16 = phi i64 [ %12, %9 ], [ %14, %13 ]
%17 = inttoptr i64 %16 to i8*
%18 = icmp eq i64 %16, 0
br i1 %18, label %40, label %19
19: ; preds = %15
%20 = trunc i64 %2 to i32
%21 = mul i32 %20, 10
%22 = add i32 %21, -10
%23 = icmp sgt i32 %21, -2147483639
br i1 %23, label %24, label %36
24: ; preds = %19
%25 = sext i32 %21 to i64
br label %26
26: ; preds = %24, %30
%27 = phi i64 [ %6, %24 ], [ %32, %30 ]
%28 = tail call signext i8 (...) @getchar()
%29 = icmp eq i8 %28, 10
br i1 %29, label %43, label %30
30: ; preds = %26
%31 = getelementptr inbounds i8, i8* %17, i64 %27
store i8 %28, i8* %31
%32 = add nsw i64 %27, 1
%33 = icmp slt i64 %32, %25
br i1 %33, label %26, label %34
34: ; preds = %30
%35 = trunc i64 %32 to i32
br label %36
36: ; preds = %34, %19
%37 = phi i32 [ %22, %19 ], [ %35, %34 ]
%38 = add nuw i64 %2, 1
%39 = add i32 %3, 10
br label %1
40: ; preds = %15
%41 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @str, i64 0, i64 0))
%42 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* null)
br label %50
43: ; preds = %26
%44 = inttoptr i64 %16 to i8*
%45 = shl i64 %27, 32
%46 = ashr exact i64 %45, 32
%47 = getelementptr inbounds i8, i8* %44, i64 %46
store i8 0, i8* %47
%48 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* %44)
%49 = tail call i32 @free(i8* %44)
br label %50
50: ; preds = %40, %43
ret void
}