#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*/);
char *malloc(int /*<<< orphan*/);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ strcpy(char *, char *);
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ strtok(char *, char *);
char *get_line(void) {
  char *input;
  char raw[40];
  fgets(raw, 40, stdin);
  strtok(raw, "\n");
  raw[40] = '\0';
  input = malloc(strlen(raw));
  strcpy(input, raw);
  return input;
}


x86 assembly (clang, -O0):
<get_line>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
lea    -0x30(%rbp),%rdi
mov    0x2e85(%rip),%rax
mov    (%rax),%edx
mov    $0x28,%esi
call   1050 <fgets@plt>
lea    -0x30(%rbp),%rdi
lea    0xe86(%rip),%rsi
call   1070 <strtok@plt>
movb   $0x0,-0x8(%rbp)
lea    -0x30(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_line>:
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    0x2e8a(%rip),%rax
mov    (%rax),%edx
mov    %rsp,%r14
mov    %r14,%rdi
mov    $0x28,%esi
call   1050 <fgets@plt>
lea    0xe89(%rip),%rsi
mov    %r14,%rdi
call   1070 <strtok@plt>
movb   $0x0,0x28(%rsp)
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r14,%rsi
call   1030 <strcpy@plt>
mov    %rbx,%rax
add    $0x28,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@stdin = global i32 0
@.str = [2 x i8] c"\0A\00"
define i8* @get_line() {
%1 = alloca i8*
%2 = alloca [40 x i8]
%3 = getelementptr inbounds [40 x i8], [40 x i8]* %2, i64 0, i64 0
%4 = load i32, i32* @stdin
%5 = call i32 @fgets(i8* %3, i32 40, i32 %4)
%6 = getelementptr inbounds [40 x i8], [40 x i8]* %2, i64 0, i64 0
%7 = call i32 @strtok(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%8 = getelementptr inbounds [40 x i8], [40 x i8]* %2, i64 0, i64 40
store i8 0, i8* %8
%9 = getelementptr inbounds [40 x i8], [40 x i8]* %2, i64 0, i64 0
%10 = call i32 @strlen(i8* %9)
%11 = call i8* @malloc(i32 %10)
store i8* %11, i8** %1
%12 = load i8*, i8** %1
%13 = getelementptr inbounds [40 x i8], [40 x i8]* %2, i64 0, i64 0
%14 = call i32 @strcpy(i8* %12, i8* %13)
%15 = load i8*, i8** %1
ret i8* %15
}

LLVM IR (-O2):
@stdin = global i32 0
@.str = [2 x i8] c"\0A\00"
define i8* @get_line() {
%1 = alloca [40 x i8]
%2 = getelementptr inbounds [40 x i8], [40 x i8]* %1, i64 0, i64 0
%3 = load i32, i32* @stdin
%4 = call i32 @fgets(i8* %2, i32 40, i32 %3)
%5 = call i32 @strtok(i8* %2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%6 = getelementptr inbounds [40 x i8], [40 x i8]* %1, i64 0, i64 40
store i8 0, i8* %6
%7 = call i32 @strlen(i8* %2)
%8 = call i8* @malloc(i32 %7)
%9 = call i32 @strcpy(i8* %8, i8* %2)
ret i8* %8
}