#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 */
typedef int /*<<< orphan*/ filename;

/* Variables and functions */
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ stdin;
unsigned int strlen(char *);
char *get_fname(void) {
  static char filename[100];
  unsigned len;
  fgets(filename, sizeof(filename), stdin);
  len = strlen(filename);
  if (len >= 1 && filename[len - 1] == '\n')
    filename[len - 1] = '\0';
  return filename;
}


x86 assembly (clang, -O0):
<get_fname>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0x2eb9(%rip),%rax
mov    (%rax),%edx
lea    0x2f08(%rip),%rdi
mov    $0x64,%esi
call   1040 <fgets@plt>
lea    0x2ef7(%rip),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x4(%rbp)
cmpl   $0x1,-0x4(%rbp)
jb     118e <get_fname+0x6e>
mov    -0x4(%rbp),%eax
sub    $0x1,%eax
mov    %eax,%eax
mov    %eax,%ecx
lea    0x2ed4(%rip),%rax
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
jne    118e <get_fname+0x6e>
mov    -0x4(%rbp),%eax
sub    $0x1,%eax
mov    %eax,%eax
mov    %eax,%ecx
lea    0x2eb6(%rip),%rax
movb   $0x0,(%rax,%rcx,1)
lea    0x2eab(%rip),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_fname>:
push   %rbx
mov    0x2ec0(%rip),%rax
mov    (%rax),%edx
lea    0x2f0f(%rip),%rbx
mov    %rbx,%rdi
mov    $0x64,%esi
call   1040 <fgets@plt>
mov    %rbx,%rdi
call   1030 <strlen@plt>
test   %eax,%eax
je     1157 <get_fname+0x37>
add    $0xffffffff,%eax
cmpb   $0xa,(%rax,%rbx,1)
jne    1157 <get_fname+0x37>
movb   $0x0,(%rax,%rbx,1)
lea    0x2ee2(%rip),%rax
pop    %rbx
ret

LLVM IR (-O0):
@get_fname.filename = internal global [100 x i8] zeroinitializer
@stdin = global i32 0
define i8* @get_fname() {
%1 = alloca i32
%2 = load i32, i32* @stdin
%3 = call i32 @fgets(i8* getelementptr inbounds ([100 x i8], [100 x i8]* @get_fname.filename, i64 0, i64 0), i32 100, i32 %2)
%4 = call i32 @strlen(i8* getelementptr inbounds ([100 x i8], [100 x i8]* @get_fname.filename, i64 0, i64 0))
store i32 %4, i32* %1
%5 = load i32, i32* %1
%6 = icmp uge i32 %5, 1
br i1 %6, label %7, label %20
7: ; preds = %0
%8 = load i32, i32* %1
%9 = sub i32 %8, 1
%10 = zext i32 %9 to i64
%11 = getelementptr inbounds [100 x i8], [100 x i8]* @get_fname.filename, i64 0, i64 %10
%12 = load i8, i8* %11
%13 = sext i8 %12 to i32
%14 = icmp eq i32 %13, 10
br i1 %14, label %15, label %20
15: ; preds = %7
%16 = load i32, i32* %1
%17 = sub i32 %16, 1
%18 = zext i32 %17 to i64
%19 = getelementptr inbounds [100 x i8], [100 x i8]* @get_fname.filename, i64 0, i64 %18
store i8 0, i8* %19
br label %20
20: ; preds = %15, %7, %0
ret i8* getelementptr inbounds ([100 x i8], [100 x i8]* @get_fname.filename, i64 0, i64 0)
}

LLVM IR (-O2):
@get_fname.filename = internal global [100 x i8] zeroinitializer
@stdin = global i32 0
define i8* @get_fname() {
%1 = load i32, i32* @stdin
%2 = tail call i32 @fgets(i8* getelementptr inbounds ([100 x i8], [100 x i8]* @get_fname.filename, i64 0, i64 0), i32 100, i32 %1)
%3 = tail call i32 @strlen(i8* getelementptr inbounds ([100 x i8], [100 x i8]* @get_fname.filename, i64 0, i64 0))
%4 = icmp eq i32 %3, 0
br i1 %4, label %12, label %5
5: ; preds = %0
%6 = add i32 %3, -1
%7 = zext i32 %6 to i64
%8 = getelementptr inbounds [100 x i8], [100 x i8]* @get_fname.filename, i64 0, i64 %7
%9 = load i8, i8* %8
%10 = icmp eq i8 %9, 10
br i1 %10, label %11, label %12
11: ; preds = %5
store i8 0, i8* %8
br label %12
12: ; preds = %11, %5, %0
ret i8* getelementptr inbounds ([100 x i8], [100 x i8]* @get_fname.filename, i64 0, i64 0)
}