#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 /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
void rewind_t() {
  char str[] = "This is tutorialspoint.com";
  FILE *fp;
  int ch;
  fp = fopen("file.txt", "w");
  fwrite(str, 1, sizeof(str), fp);
  fclose(fp);
  fp = fopen("file.txt", "r");
  while (1) {
    ch = fgetc(fp);
    if (feof(fp)) {
      break;
    }
    printf("%c", ch);
  }
  rewind(fp);
  printf("\n");
  while (1) {
    ch = fgetc(fp);
    if (feof(fp)) {
      break;
    }
    printf("%c", ch);
  }
  fclose(fp);
}


x86 assembly (clang, -O0):
<rewind_t>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    0xe81(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xe7e(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    0xe7b(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    0xe78(%rip),%ax
mov    %ax,-0x8(%rbp)
mov    0xe70(%rip),%al
mov    %al,-0x6(%rbp)
lea    0xe67(%rip),%rdi
lea    0xe69(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x28(%rbp)
lea    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rcx
mov    $0x1,%esi
mov    $0x1b,%edx
call   1090 <fwrite@plt>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
lea    0xe30(%rip),%rdi
lea    0xe34(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
call   1060 <fgetc@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x28(%rbp),%rdi
call   1070 <feof@plt>
cmp    $0x0,%rax
je     121f <rewind_t+0xaf>
jmp    1235 <rewind_t+0xc5>
mov    -0x2c(%rbp),%esi
lea    0xdff(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11fb <rewind_t+0x8b>
mov    -0x28(%rbp),%rdi
call   1050 <rewind@plt>
lea    0xde6(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x28(%rbp),%rdi
call   1060 <fgetc@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x28(%rbp),%rdi
call   1070 <feof@plt>
cmp    $0x0,%rax
je     1270 <rewind_t+0x100>
jmp    1286 <rewind_t+0x116>
mov    -0x2c(%rbp),%esi
lea    0xdae(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    124c <rewind_t+0xdc>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rewind_t>:
push   %rbp
push   %rbx
sub    $0x28,%rsp
movups 0xe8e(%rip),%xmm0
movups %xmm0,0xb(%rsp)
movaps 0xe77(%rip),%xmm0
movaps %xmm0,(%rsp)
lea    0xe87(%rip),%rbx
lea    0xe89(%rip),%rsi
mov    %rbx,%rdi
call   1080 <fopen@plt>
mov    %rax,%rbp
mov    %rsp,%rdi
mov    $0x1,%esi
mov    $0x1b,%edx
mov    %rax,%rcx
call   1090 <fwrite@plt>
mov    %rbp,%rdi
call   1040 <fclose@plt>
lea    0xe5c(%rip),%rsi
mov    %rbx,%rdi
call   1080 <fopen@plt>
mov    %rax,%rbx
mov    %rax,%rdi
nopl   0x0(%rax,%rax,1)
call   1060 <fgetc@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1070 <feof@plt>
test   %rax,%rax
jne    1200 <rewind_t+0x90>
mov    %ebp,%edi
call   1030 <putchar@plt>
mov    %rbx,%rdi
jmp    11e0 <rewind_t+0x70>
mov    %rbx,%rdi
call   1050 <rewind@plt>
mov    $0xa,%edi
nopl   (%rax)
call   1030 <putchar@plt>
mov    %rbx,%rdi
call   1060 <fgetc@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1070 <feof@plt>
test   %rax,%rax
jne    1230 <rewind_t+0xc0>
mov    %ebp,%edi
jmp    1210 <rewind_t+0xa0>
mov    %rbx,%rdi
add    $0x28,%rsp
pop    %rbx
pop    %rbp
jmp    1040 <fclose@plt>

LLVM IR (-O0):
@__const.rewind_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"
@.str.4 = [2 x i8] c"\0A\00"
define void @rewind_t() {
%1 = alloca [27 x i8]
%2 = alloca i32*
%3 = alloca i32
%4 = bitcast [27 x i8]* %1 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** %2
%6 = getelementptr inbounds [27 x i8], [27 x i8]* %1, i64 0, i64 0
%7 = load i32*, i32** %2
%8 = call i32 @fwrite(i8* %6, i32 1, i32 27, i32* %7)
%9 = load i32*, i32** %2
%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** %2
br label %12
12: ; preds = %0, %19
%13 = load i32*, i32** %2
%14 = call i32 @fgetc(i32* %13)
store i32 %14, i32* %3
%15 = load i32*, i32** %2
%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 (i8*, ...) @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** %2
%24 = call i32 @rewind(i32* %23)
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
br label %26
26: ; preds = %22, %33
%27 = load i32*, i32** %2
%28 = call i32 @fgetc(i32* %27)
store i32 %28, i32* %3
%29 = load i32*, i32** %2
%30 = call i64 @feof(i32* %29)
%31 = icmp ne i64 %30, 0
br i1 %31, label %32, label %33
32: ; preds = %26
br label %36
33: ; preds = %26
%34 = load i32, i32* %3
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 %34)
br label %26
36: ; preds = %32
%37 = load i32*, i32** %2
%38 = call i32 @fclose(i32* %37)
ret void
}

LLVM IR (-O2):
@__const.rewind_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"
define void @rewind_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 @putchar(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 @rewind(i32* %6)
%18 = tail call i32 @putchar(i32 10)
%19 = tail call i32 @fgetc(i32* %6)
%20 = tail call i64 @feof(i32* %6)
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %28
22: ; preds = %16, %22
%23 = phi i32 [ %25, %22 ], [ %19, %16 ]
%24 = tail call i32 @putchar(i32 %23)
%25 = tail call i32 @fgetc(i32* %6)
%26 = tail call i64 @feof(i32* %6)
%27 = icmp eq i64 %26, 0
br i1 %27, label %22, label %28
28: ; preds = %22, %16
%29 = tail call i32 @fclose(i32* %6)
ret void
}