#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*/ fclose(int /*<<< orphan*/ *);
char *fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ stdin;
int main() {
  char c[256];
  FILE *f;
  char *ret;
  f = fopen("out.txt", "w+");
  if (f == NULL) {
    printf("an error occoured!");
    exit(1);
  }
  printf("Enter a sentence: \n");
  ret = fgets(c, 256, stdin);
  if (ret > 0) {
    fprintf(f, "%s", c);
  }
  fclose(f);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe87(%rip),%rdi
lea    0xe88(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x118(%rbp)
cmpq   $0x0,-0x118(%rbp)
jne    11b0 <main+0x50>
lea    0xe6a(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
lea    0xe67(%rip),%rdi
call   1040 <printf@plt>
lea    -0x110(%rbp),%rdi
mov    0x2e1e(%rip),%rax
mov    (%rax),%edx
mov    $0x100,%esi
call   1050 <fgets@plt>
mov    %rax,-0x120(%rbp)
cmpq   $0x0,-0x120(%rbp)
jbe    1205 <main+0xa5>
mov    -0x118(%rbp),%rdi
lea    -0x110(%rbp),%rdx
lea    0xe32(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x118(%rbp),%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x100,%rsp
lea    0xe81(%rip),%rdi
lea    0xe82(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     11d8 <main+0x68>
mov    %rax,%rbx
lea    0xe84(%rip),%rdi
call   1030 <puts@plt>
mov    0x2e42(%rip),%rax
mov    (%rax),%edx
mov    %rsp,%rdi
mov    $0x100,%esi
call   1070 <fgets@plt>
test   %rax,%rax
je     11c5 <main+0x55>
mov    %rsp,%rdi
mov    %rbx,%rsi
call   1060 <fputs@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x100,%rsp
pop    %rbx
ret
lea    0xe2c(%rip),%rdi
call   1050 <printf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [8 x i8] c"out.txt\00"
@.str.1 = [3 x i8] c"w+\00"
@.str.2 = [19 x i8] c"an error occoured!\00"
@.str.3 = [20 x i8] c"Enter a sentence: \0A\00"
@stdin = global i32 0
@.str.4 = [3 x i8] c"%s\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [256 x i8]
%3 = alloca i32*
%4 = alloca i8*
store i32 0, i32* %1
%5 = call i32* @fopen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %5, i32** %3
%6 = load i32*, i32** %3
%7 = icmp eq i32* %6, null
br i1 %7, label %8, label %11
8: ; preds = %0
%9 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
%10 = call i32 @exit(i32 1)
unreachable
11: ; preds = %0
%12 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
%13 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%14 = load i32, i32* @stdin
%15 = call i8* @fgets(i8* %13, i32 256, i32 %14)
store i8* %15, i8** %4
%16 = load i8*, i8** %4
%17 = icmp ugt i8* %16, null
br i1 %17, label %18, label %22
18: ; preds = %11
%19 = load i32*, i32** %3
%20 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%21 = call i32 @fprintf(i32* %19, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %20)
br label %22
22: ; preds = %18, %11
%23 = load i32*, i32** %3
%24 = call i32 @fclose(i32* %23)
ret i32 0
}

LLVM IR (-O2):
@.str = [8 x i8] c"out.txt\00"
@.str.1 = [3 x i8] c"w+\00"
@.str.2 = [19 x i8] c"an error occoured!\00"
@stdin = global i32 0
@str = [19 x i8] c"Enter a sentence: \00"
define i32 @main() {
%1 = alloca [256 x i8]
%2 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 0
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %8
5: ; preds = %0
%6 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
%7 = tail call i32 @exit(i32 1)
unreachable
8: ; preds = %0
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str, i64 0, i64 0))
%10 = load i32, i32* @stdin
%11 = call i8* @fgets(i8* %2, i32 256, i32 %10)
%12 = icmp eq i8* %11, null
br i1 %12, label %15, label %13
13: ; preds = %8
%14 = call i32 @fputs(i8* %2, i32* %3)
br label %15
15: ; preds = %13, %8
%16 = call i32 @fclose(i32* %3)
ret i32 0
}