#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*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ stdout;
size_t strcspn(char *, char *);
int strlen(char *);
int getlineClean(char *line, int max) {
  printf("\n: ");
  fflush(stdout);
  if (fgets(line, max, stdin) == NULL)
    return 0;
  else {
    line[strcspn(line, "\n")] = '\0';
    return strlen(line);
  }
}


x86 assembly (clang, -O0):
<getlineClean>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
lea    0xe9a(%rip),%rdi
call   1040 <printf@plt>
mov    0x2e66(%rip),%rax
mov    (%rax),%edi
call   1070 <fflush@plt>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    0x2e61(%rip),%rax
mov    (%rax),%edx
call   1060 <fgets@plt>
cmp    $0x0,%rax
jne    11a4 <getlineClean+0x54>
movl   $0x0,-0x4(%rbp)
jmp    11d3 <getlineClean+0x83>
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe4d(%rip),%rsi
call   1050 <strcspn@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getlineClean>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%rbx
lea    0xea1(%rip),%rdi
call   1040 <printf@plt>
mov    0x2e6d(%rip),%rax
mov    (%rax),%edi
call   1070 <fflush@plt>
mov    0x2e6f(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
mov    %ebp,%esi
call   1060 <fgets@plt>
test   %rax,%rax
je     11ab <getlineClean+0x5b>
lea    0xe73(%rip),%rsi
mov    %rbx,%rdi
call   1050 <strcspn@plt>
movb   $0x0,(%rbx,%rax,1)
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1030 <strlen@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"\0A: \00"
@stdout = global i32 0
@stdin = global i32 0
@.str.1 = [2 x i8] c"\0A\00"
define i32 @getlineClean(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
%6 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%7 = load i32, i32* @stdout
%8 = call i32 @fflush(i32 %7)
%9 = load i8*, i8** %4
%10 = load i32, i32* %5
%11 = load i32, i32* @stdin
%12 = call i32* @fgets(i8* %9, i32 %10, i32 %11)
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %15
14: ; preds = %2
store i32 0, i32* %3
br label %22
15: ; preds = %2
%16 = load i8*, i8** %4
%17 = load i8*, i8** %4
%18 = call i64 @strcspn(i8* %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%19 = getelementptr inbounds i8, i8* %16, i64 %18
store i8 0, i8* %19
%20 = load i8*, i8** %4
%21 = call i32 @strlen(i8* %20)
store i32 %21, i32* %3
br label %22
22: ; preds = %15, %14
%23 = load i32, i32* %3
ret i32 %23
}

LLVM IR (-O2):
@.str = [4 x i8] c"\0A: \00"
@stdout = global i32 0
@stdin = global i32 0
@.str.1 = [2 x i8] c"\0A\00"
define i32 @getlineClean(i8* %0, i32 %1) {
%3 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%4 = load i32, i32* @stdout
%5 = tail call i32 @fflush(i32 %4)
%6 = load i32, i32* @stdin
%7 = tail call i32* @fgets(i8* %0, i32 %1, i32 %6)
%8 = icmp eq i32* %7, null
br i1 %8, label %13, label %9
9: ; preds = %2
%10 = tail call i64 @strcspn(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%11 = getelementptr inbounds i8, i8* %0, i64 %10
store i8 0, i8* %11
%12 = tail call i32 @strlen(i8* %0)
br label %13
13: ; preds = %2, %9
%14 = phi i32 [ %12, %9 ], [ 0, %2 ]
ret i32 %14
}