#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*/ exit(int);
int /*<<< orphan*/ fgets(char *, int /*<<< orphan*/, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ malloc_usable_size(char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ print_result(char *);
int /*<<< orphan*/ replace_char(char *, char, char);
int file_open(FILE *f) {
  char *source;
  source = (char *)malloc(100 * sizeof(char));
  if (source == NULL) {
    perror("malloc");
    exit(1);
  }
  fgets(source, malloc_usable_size(source), f);
  replace_char(source, '\n', '\0');
  print_result(source);
  free(source);
  return 0;
}


x86 assembly (clang, -O0):
<file_open>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x64,%edi
call   1070 <malloc@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11bb <file_open+0x3b>
lea    0xe54(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <malloc_usable_size@plt>
mov    -0x18(%rbp),%rdi
mov    %eax,%esi
mov    -0x8(%rbp),%rdx
call   1060 <fgets@plt>
mov    -0x10(%rbp),%rdi
mov    $0xa,%esi
xor    %edx,%edx
call   1080 <replace_char@plt>
mov    -0x10(%rbp),%rdi
call   1040 <print_result@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<file_open>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
mov    $0x64,%edi
call   1070 <malloc@plt>
test   %rax,%rax
je     11d7 <file_open+0x57>
mov    %rax,%rbx
mov    %rax,%rdi
call   1050 <malloc_usable_size@plt>
mov    %rbx,%rdi
mov    %eax,%esi
mov    %r14,%rdx
call   1060 <fgets@plt>
mov    %rbx,%rdi
mov    $0xa,%esi
xor    %edx,%edx
call   1080 <replace_char@plt>
mov    %rbx,%rdi
call   1040 <print_result@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe22(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [7 x i8] c"malloc\00"
define i32 @file_open(i32* %0) {
%2 = alloca i32*
%3 = alloca i8*
store i32* %0, i32** %2
%4 = call i64 @malloc(i32 100)
%5 = inttoptr i64 %4 to i8*
store i8* %5, i8** %3
%6 = load i8*, i8** %3
%7 = icmp eq i8* %6, null
br i1 %7, label %8, label %11
8: ; preds = %1
%9 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%10 = call i32 @exit(i32 1)
unreachable
11: ; preds = %1
%12 = load i8*, i8** %3
%13 = load i8*, i8** %3
%14 = call i32 @malloc_usable_size(i8* %13)
%15 = load i32*, i32** %2
%16 = call i32 @fgets(i8* %12, i32 %14, i32* %15)
%17 = load i8*, i8** %3
%18 = call i32 @replace_char(i8* %17, i8 signext 10, i8 signext 0)
%19 = load i8*, i8** %3
%20 = call i32 @print_result(i8* %19)
%21 = load i8*, i8** %3
%22 = call i32 @free(i8* %21)
ret i32 0
}

LLVM IR (-O2):
@.str = [7 x i8] c"malloc\00"
define i32 @file_open(i32* nocapture %0) {
%2 = tail call i64 @malloc(i32 100)
%3 = inttoptr i64 %2 to i8*
%4 = icmp eq i64 %2, 0
br i1 %4, label %5, label %8
5: ; preds = %1
%6 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%7 = tail call i32 @exit(i32 1)
unreachable
8: ; preds = %1
%9 = tail call i32 @malloc_usable_size(i8* %3)
%10 = tail call i32 @fgets(i8* %3, i32 %9, i32* %0)
%11 = tail call i32 @replace_char(i8* %3, i8 signext 10, i8 signext 0)
%12 = tail call i32 @print_result(i8* %3)
%13 = tail call i32 @free(i8* %3)
ret i32 0
}