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

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ feof(int /*<<< orphan*/ *);
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fwrite(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, int);
void fwrite_t() {
  FILE *fp;
  char str[] = "This is tutorialspoint.com";
  fp = fopen("file.txt", "w");
  fwrite(str, 1, sizeof(str), fp);
  fclose(fp);
  int c;
  fp = fopen("file.txt", "r");
  while (1) {
    c = fgetc(fp);
    if (feof(fp)) {
      break;
    }
    printf("%c", c);
  }
  fclose(fp);
}


x86 assembly (clang, -O0):
<fwrite_t>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    0xe91(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0xe8e(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    0xe8b(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xe88(%rip),%ax
mov    %ax,-0x18(%rbp)
mov    0xe80(%rip),%al
mov    %al,-0x16(%rbp)
lea    0xe77(%rip),%rdi
lea    0xe79(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x8(%rbp)
lea    -0x30(%rbp),%rdi
mov    -0x8(%rbp),%rcx
mov    $0x1,%esi
mov    $0x1b,%edx
call   1080 <fwrite@plt>
mov    -0x8(%rbp),%rdi
call   1030 <fclose@plt>
lea    0xe40(%rip),%rdi
lea    0xe44(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %eax,-0x34(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <feof@plt>
cmp    $0x0,%rax
je     120f <fwrite_t+0xaf>
jmp    1223 <fwrite_t+0xc3>
mov    -0x34(%rbp),%esi
lea    0xe0f(%rip),%rdi
call   1040 <printf@plt>
jmp    11eb <fwrite_t+0x8b>
mov    -0x8(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fwrite_t>:
push   %rbp
push   %r14
push   %rbx
sub    $0x20,%rsp
movups 0xe9c(%rip),%xmm0
movups %xmm0,0xb(%rsp)
movaps 0xe85(%rip),%xmm0
movaps %xmm0,(%rsp)
lea    0xe95(%rip),%rbx
lea    0xe97(%rip),%rsi
mov    %rbx,%rdi
call   1070 <fopen@plt>
mov    %rax,%rbp
mov    %rsp,%rdi
mov    $0x1,%esi
mov    $0x1b,%edx
mov    %rax,%rcx
call   1080 <fwrite@plt>
mov    %rbp,%rdi
call   1030 <fclose@plt>
lea    0xe6a(%rip),%rsi
mov    %rbx,%rdi
call   1070 <fopen@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1050 <fgetc@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1060 <feof@plt>
test   %rax,%rax
jne    1211 <fwrite_t+0xb1>
lea    0xe43(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r14,%rdi
mov    %ebp,%esi
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1050 <fgetc@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1060 <feof@plt>
test   %rax,%rax
je     11f0 <fwrite_t+0x90>
mov    %rbx,%rdi
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <fclose@plt>

LLVM IR (-O0):
@__const.fwrite_t.str = [27 x i8] c"This is tutorialspoint.com\00"
@.str = [9 x i8] c"file.txt\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [3 x i8] c"%c\00"
define void @fwrite_t() {
%1 = alloca i32*
%2 = alloca [27 x i8]
%3 = alloca i32
%4 = bitcast [27 x i8]* %2 to i8*
%5 = call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %5, i32** %1
%6 = getelementptr inbounds [27 x i8], [27 x i8]* %2, i64 0, i64 0
%7 = load i32*, i32** %1
%8 = call i32 @fwrite(i8* %6, i32 1, i32 27, i32* %7)
%9 = load i32*, i32** %1
%10 = call i32 @fclose(i32* %9)
%11 = call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %11, i32** %1
br label %12
12: ; preds = %0, %19
%13 = load i32*, i32** %1
%14 = call i32 @fgetc(i32* %13)
store i32 %14, i32* %3
%15 = load i32*, i32** %1
%16 = call i64 @feof(i32* %15)
%17 = icmp ne i64 %16, 0
br i1 %17, label %18, label %19
18: ; preds = %12
br label %22
19: ; preds = %12
%20 = load i32, i32* %3
%21 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 %20)
br label %12
22: ; preds = %18
%23 = load i32*, i32** %1
%24 = call i32 @fclose(i32* %23)
ret void
}

LLVM IR (-O2):
@__const.fwrite_t.str = [27 x i8] c"This is tutorialspoint.com\00"
@.str = [9 x i8] c"file.txt\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [3 x i8] c"%c\00"
define void @fwrite_t() {
%1 = alloca [27 x i8]
%2 = getelementptr inbounds [27 x i8], [27 x i8]* %1, i64 0, i64 0
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%4 = call i32 @fwrite(i8* %2, i32 1, i32 27, i32* %3)
%5 = tail call i32 @fclose(i32* %3)
%6 = tail call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%7 = tail call i32 @fgetc(i32* %6)
%8 = tail call i64 @feof(i32* %6)
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %16
10: ; preds = %0, %10
%11 = phi i32 [ %13, %10 ], [ %7, %0 ]
%12 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 %11)
%13 = tail call i32 @fgetc(i32* %6)
%14 = tail call i64 @feof(i32* %6)
%15 = icmp eq i64 %14, 0
br i1 %15, label %10, label %16
16: ; preds = %10, %0
%17 = tail call i32 @fclose(i32* %6)
ret void
}