#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*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ os_flush();
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ stdin;
char *strchr(char *, char);
FILE *os_open_script_file(void) {
  char name[256];
  char *nl;
  os_flush();
  printf("Script file: ");
  fgets(name, 256, stdin);
  nl = strchr(name, '\n');
  if (nl)
    *nl = 0;
  return fopen(name, "rt");
}


x86 assembly (clang, -O0):
<os_open_script_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x110,%rsp
mov    $0x0,%al
call   1050 <os_flush@plt>
lea    0xe97(%rip),%rdi
call   1040 <printf@plt>
lea    -0x100(%rbp),%rdi
mov    0x2e6c(%rip),%rax
mov    (%rax),%edx
mov    $0x100,%esi
call   1060 <fgets@plt>
lea    -0x100(%rbp),%rdi
mov    $0xa,%esi
call   1030 <strchr@plt>
mov    %rax,-0x108(%rbp)
cmpq   $0x0,-0x108(%rbp)
je     11b8 <os_open_script_file+0x68>
mov    -0x108(%rbp),%rax
movb   $0x0,(%rax)
lea    -0x100(%rbp),%rdi
lea    0xe48(%rip),%rsi
call   1070 <fopen@plt>
add    $0x110,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<os_open_script_file>:
push   %rbx
sub    $0x100,%rsp
xor    %eax,%eax
call   1050 <os_flush@plt>
lea    0xe9a(%rip),%rdi
call   1040 <printf@plt>
mov    0x2e76(%rip),%rax
mov    (%rax),%edx
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x100,%esi
call   1060 <fgets@plt>
mov    %rbx,%rdi
mov    $0xa,%esi
call   1030 <strchr@plt>
test   %rax,%rax
je     1199 <os_open_script_file+0x49>
movb   $0x0,(%rax)
lea    0xe6e(%rip),%rsi
mov    %rsp,%rdi
call   1070 <fopen@plt>
add    $0x100,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [14 x i8] c"Script file: \00"
@stdin = global i32 0
@.str.1 = [3 x i8] c"rt\00"
define i32* @os_open_script_file() {
%1 = alloca [256 x i8]
%2 = alloca i8*
%3 = call i32 (...) @os_flush()
%4 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%5 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 0
%6 = load i32, i32* @stdin
%7 = call i32 @fgets(i8* %5, i32 256, i32 %6)
%8 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 0
%9 = call i8* @strchr(i8* %8, i8 signext 10)
store i8* %9, i8** %2
%10 = load i8*, i8** %2
%11 = icmp ne i8* %10, null
br i1 %11, label %12, label %14
12: ; preds = %0
%13 = load i8*, i8** %2
store i8 0, i8* %13
br label %14
14: ; preds = %12, %0
%15 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 0
%16 = call i32* @fopen(i8* %15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
ret i32* %16
}

LLVM IR (-O2):
@.str = [14 x i8] c"Script file: \00"
@stdin = global i32 0
@.str.1 = [3 x i8] c"rt\00"
define noalias i32* @os_open_script_file() {
%1 = alloca [256 x i8]
%2 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 0
%3 = tail call i32 (...) @os_flush()
%4 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%5 = load i32, i32* @stdin
%6 = call i32 @fgets(i8* %2, i32 256, i32 %5)
%7 = call i8* @strchr(i8* %2, i8 signext 10)
%8 = icmp eq i8* %7, null
br i1 %8, label %10, label %9
9: ; preds = %0
store i8 0, i8* %7
br label %10
10: ; preds = %9, %0
%11 = call i32* @fopen(i8* %2, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
ret i32* %11
}