#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 *calloc(int, int);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ scanf(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
char *trim_whitespace(char *);
char *get_str() {
  char *buffer = calloc(100, sizeof(char));
  char *output;
  scanf("%s", buffer);
  char *input = trim_whitespace(buffer);
  output = calloc(strlen(input) + 1, sizeof(char));
  strcpy(output, input);
  free(buffer);
  return output;
}


x86 assembly (clang, -O0):
<get_str>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    $0x64,%edi
mov    $0x1,%esi
call   1070 <calloc@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rsi
lea    0xe7a(%rip),%rdi
call   1080 <scanf@plt>
mov    -0x8(%rbp),%rdi
call   1060 <trim_whitespace@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%edi
add    $0x1,%edi
mov    $0x1,%esi
call   1070 <calloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x8(%rbp),%rdi
call   1030 <free@plt>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_str>:
push   %r15
push   %r14
push   %rbx
mov    $0x64,%edi
mov    $0x1,%esi
call   1070 <calloc@plt>
mov    %rax,%r14
lea    0xe82(%rip),%rdi
mov    %rax,%rsi
call   1080 <scanf@plt>
mov    %r14,%rdi
call   1060 <trim_whitespace@plt>
mov    %rax,%r15
mov    %rax,%rdi
call   1050 <strlen@plt>
lea    0x1(%rax),%edi
mov    $0x1,%esi
call   1070 <calloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r15,%rsi
call   1040 <strcpy@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%s\00"
define i8* @get_str() {
%1 = alloca i8*
%2 = alloca i8*
%3 = alloca i8*
%4 = call i8* @calloc(i32 100, i32 1)
store i8* %4, i8** %1
%5 = load i8*, i8** %1
%6 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %5)
%7 = load i8*, i8** %1
%8 = call i8* @trim_whitespace(i8* %7)
store i8* %8, i8** %3
%9 = load i8*, i8** %3
%10 = call i32 @strlen(i8* %9)
%11 = add nsw i32 %10, 1
%12 = call i8* @calloc(i32 %11, i32 1)
store i8* %12, i8** %2
%13 = load i8*, i8** %2
%14 = load i8*, i8** %3
%15 = call i32 @strcpy(i8* %13, i8* %14)
%16 = load i8*, i8** %1
%17 = call i32 @free(i8* %16)
%18 = load i8*, i8** %2
ret i8* %18
}

LLVM IR (-O2):
@.str = [3 x i8] c"%s\00"
define i8* @get_str() {
%1 = tail call dereferenceable_or_null(100) i8* @calloc(i32 100, i32 1)
%2 = tail call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %1)
%3 = tail call i8* @trim_whitespace(i8* %1)
%4 = tail call i32 @strlen(i8* %3)
%5 = add nsw i32 %4, 1
%6 = tail call i8* @calloc(i32 %5, i32 1)
%7 = tail call i32 @strcpy(i8* %6, i8* %3)
%8 = tail call i32 @free(i8* %1)
ret i8* %6
}