#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*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ getchar();
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ stdin;
int main(void) {
  char input[100];
  char *string;
  int len = 0;
  int x = 0;
  printf("Say something %c\n", 25);
  fgets(input, 100, stdin);
  while (input[x] != '\0') {
    len++;
    x++;
  }
  len -= 1;
  string = (char *)malloc(len * sizeof(char));
  string = input;
  if (string == NULL) {
    puts("Not enough memory!");
    return 0;
  }
  printf("\n\tOriginal String\n%s\n\n\tPointer string\n%s", input, string);
  getchar();
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x7c(%rbp)
movl   $0x0,-0x80(%rbp)
lea    0xe89(%rip),%rdi
mov    $0x19,%esi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x70(%rbp),%rdi
mov    0x2e5a(%rip),%rax
mov    (%rax),%edx
mov    $0x64,%esi
call   1050 <fgets@plt>
movslq -0x80(%rbp),%rax
movsbl -0x70(%rbp,%rax,1),%eax
cmp    $0x0,%eax
je     11c3 <main+0x73>
mov    -0x7c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x7c(%rbp)
mov    -0x80(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x80(%rbp)
jmp    119a <main+0x4a>
mov    -0x7c(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x7c(%rbp)
movslq -0x7c(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x78(%rbp)
lea    -0x70(%rbp),%rax
mov    %rax,-0x78(%rbp)
cmpq   $0x0,-0x78(%rbp)
jne    120a <main+0xba>
lea    0xe19(%rip),%rdi
call   1030 <puts@plt>
movl   $0x0,-0x4(%rbp)
jmp    122e <main+0xde>
lea    -0x70(%rbp),%rsi
mov    -0x78(%rbp),%rdx
lea    0xe0c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1060 <getchar@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0x68,%rsp
lea    0xeb5(%rip),%rdi
mov    $0x19,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    0x2e8a(%rip),%rax
mov    (%rax),%edx
mov    %rsp,%rdi
mov    $0x64,%esi
call   1040 <fgets@plt>
cmpb   $0x0,(%rsp)
je     118e <main+0x4e>
lea    0x1(%rsp),%rax
mov    $0xffffffff,%edi
nopl   (%rax)
add    $0x1,%edi
cmpb   $0x0,(%rax)
lea    0x1(%rax),%rax
jne    1180 <main+0x40>
jmp    1193 <main+0x53>
mov    $0xffffffff,%edi
call   1060 <malloc@plt>
lea    0xe73(%rip),%rdi
mov    %rsp,%rdx
mov    %rdx,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
call   1050 <getchar@plt>
xor    %eax,%eax
add    $0x68,%rsp
ret

LLVM IR (-O0):
@.str = [18 x i8] c"Say something %c\0A\00"
@stdin = global i32 0
@.str.1 = [19 x i8] c"Not enough memory!\00"
@.str.2 = [41 x i8] c"\0A\09Original String\0A%s\0A\0A\09Pointer string\0A%s\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [100 x i8]
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %4
store i32 0, i32* %5
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 25)
%7 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%8 = load i32, i32* @stdin
%9 = call i32 @fgets(i8* %7, i32 100, i32 %8)
br label %10
10: ; preds = %17, %0
%11 = load i32, i32* %5
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 %12
%14 = load i8, i8* %13
%15 = sext i8 %14 to i32
%16 = icmp ne i32 %15, 0
br i1 %16, label %17, label %22
17: ; preds = %10
%18 = load i32, i32* %4
%19 = add nsw i32 %18, 1
store i32 %19, i32* %4
%20 = load i32, i32* %5
%21 = add nsw i32 %20, 1
store i32 %21, i32* %5
br label %10
22: ; preds = %10
%23 = load i32, i32* %4
%24 = sub nsw i32 %23, 1
store i32 %24, i32* %4
%25 = load i32, i32* %4
%26 = sext i32 %25 to i64
%27 = mul i64 %26, 1
%28 = trunc i64 %27 to i32
%29 = call i64 @malloc(i32 %28)
%30 = inttoptr i64 %29 to i8*
store i8* %30, i8** %3
%31 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
store i8* %31, i8** %3
%32 = load i8*, i8** %3
%33 = icmp eq i8* %32, null
br i1 %33, label %34, label %36
34: ; preds = %22
%35 = call i32 @puts(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %1
br label %41
36: ; preds = %22
%37 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%38 = load i8*, i8** %3
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.2, i64 0, i64 0), i8* %37, i8* %38)
%40 = call i32 (...) @getchar()
store i32 0, i32* %1
br label %41
41: ; preds = %36, %34
%42 = load i32, i32* %1
ret i32 %42
}

LLVM IR (-O2):
@.str = [18 x i8] c"Say something %c\0A\00"
@stdin = global i32 0
@.str.2 = [41 x i8] c"\0A\09Original String\0A%s\0A\0A\09Pointer string\0A%s\00"
define i32 @main() {
%1 = alloca [100 x i8]
%2 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 25)
%4 = load i32, i32* @stdin
%5 = call i32 @fgets(i8* %2, i32 100, i32 %4)
%6 = load i8, i8* %2
%7 = icmp eq i8 %6, 0
br i1 %7, label %17, label %8
8: ; preds = %0, %8
%9 = phi i64 [ %10, %8 ], [ 0, %0 ]
%10 = add nuw nsw i64 %9, 1
%11 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 %10
%12 = load i8, i8* %11
%13 = icmp eq i8 %12, 0
br i1 %13, label %14, label %8
14: ; preds = %8
%15 = trunc i64 %10 to i32
%16 = add i32 %15, -1
br label %17
17: ; preds = %14, %0
%18 = phi i32 [ -1, %0 ], [ %16, %14 ]
%19 = call i64 @malloc(i32 %18)
%20 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @.str.2, i64 0, i64 0), i8* %2, i8* %2)
%21 = call i32 (...) @getchar()
ret i32 0
}