#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*/ SEEK_SET;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ feof(int /*<<< orphan*/ *);
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, int);
void fseek_t() {
  FILE *fp;
  fp = fopen("file.txt", "w+");
  fputs("This is tutorialspoint.com", fp);
  fseek(fp, 7, SEEK_SET);
  fputs(" C Programming Language", 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):
<fseek_t>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xe81(%rip),%rdi
lea    0xe83(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rsi
lea    0xe72(%rip),%rdi
call   1050 <fputs@plt>
mov    -0x8(%rbp),%rdi
mov    0x2e36(%rip),%rax
mov    (%rax),%edx
mov    $0x7,%esi
call   1080 <fseek@plt>
mov    -0x8(%rbp),%rsi
lea    0xe66(%rip),%rdi
call   1050 <fputs@plt>
mov    -0x8(%rbp),%rdi
call   1030 <fclose@plt>
lea    0xe2a(%rip),%rdi
lea    0xe62(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <fgetc@plt>
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
call   1070 <feof@plt>
cmp    $0x0,%rax
je     120a <fseek_t+0x9a>
jmp    121e <fseek_t+0xae>
mov    -0xc(%rbp),%esi
lea    0xe2d(%rip),%rdi
call   1040 <printf@plt>
jmp    11e6 <fseek_t+0x76>
mov    -0x8(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fseek_t>:
push   %rbp
push   %r14
push   %rbx
lea    0xe85(%rip),%rbx
lea    0xe87(%rip),%rsi
mov    %rbx,%rdi
call   1080 <fopen@plt>
mov    %rax,%rbp
lea    0xe78(%rip),%rdi
mov    $0x1a,%esi
mov    $0x1,%edx
mov    %rax,%rcx
call   1090 <fwrite@plt>
mov    0x2e33(%rip),%rax
mov    (%rax),%edx
mov    %rbp,%rdi
mov    $0x7,%esi
call   1070 <fseek@plt>
lea    0xe64(%rip),%rdi
mov    $0x17,%esi
mov    $0x1,%edx
mov    %rbp,%rcx
call   1090 <fwrite@plt>
mov    %rbp,%rdi
call   1030 <fclose@plt>
lea    0xe5b(%rip),%rsi
mov    %rbx,%rdi
call   1080 <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    1231 <fseek_t+0xc1>
lea    0xe34(%rip),%r14
nopl   (%rax)
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     1210 <fseek_t+0xa0>
mov    %rbx,%rdi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <fclose@plt>

LLVM IR (-O0):
@.str = [9 x i8] c"file.txt\00"
@.str.1 = [3 x i8] c"w+\00"
@.str.2 = [27 x i8] c"This is tutorialspoint.com\00"
@SEEK_SET = global i32 0
@.str.3 = [24 x i8] c" C Programming Language\00"
@.str.4 = [2 x i8] c"r\00"
@.str.5 = [3 x i8] c"%c\00"
define void @fseek_t() {
%1 = alloca i32*
%2 = alloca i32
%3 = call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %3, i32** %1
%4 = load i32*, i32** %1
%5 = call i32 @fputs(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i32* %4)
%6 = load i32*, i32** %1
%7 = load i32, i32* @SEEK_SET
%8 = call i32 @fseek(i32* %6, i32 7, i32 %7)
%9 = load i32*, i32** %1
%10 = call i32 @fputs(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i32* %9)
%11 = load i32*, i32** %1
%12 = call i32 @fclose(i32* %11)
%13 = 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.4, i64 0, i64 0))
store i32* %13, i32** %1
br label %14
14: ; preds = %0, %21
%15 = load i32*, i32** %1
%16 = call i32 @fgetc(i32* %15)
store i32 %16, i32* %2
%17 = load i32*, i32** %1
%18 = call i64 @feof(i32* %17)
%19 = icmp ne i64 %18, 0
br i1 %19, label %20, label %21
20: ; preds = %14
br label %24
21: ; preds = %14
%22 = load i32, i32* %2
%23 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32 %22)
br label %14
24: ; preds = %20
%25 = load i32*, i32** %1
%26 = call i32 @fclose(i32* %25)
ret void
}

LLVM IR (-O2):
@.str = [9 x i8] c"file.txt\00"
@.str.1 = [3 x i8] c"w+\00"
@.str.2 = [27 x i8] c"This is tutorialspoint.com\00"
@SEEK_SET = global i32 0
@.str.3 = [24 x i8] c" C Programming Language\00"
@.str.4 = [2 x i8] c"r\00"
@.str.5 = [3 x i8] c"%c\00"
define void @fseek_t() {
%1 = tail call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%2 = tail call i64 @fwrite(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i64 26, i64 1, i32* %1)
%3 = load i32, i32* @SEEK_SET
%4 = tail call i32 @fseek(i32* %1, i32 7, i32 %3)
%5 = tail call i64 @fwrite(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i64 23, i64 1, i32* %1)
%6 = tail call i32 @fclose(i32* %1)
%7 = 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.4, i64 0, i64 0))
%8 = tail call i32 @fgetc(i32* %7)
%9 = tail call i64 @feof(i32* %7)
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %17
11: ; preds = %0, %11
%12 = phi i32 [ %14, %11 ], [ %8, %0 ]
%13 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32 %12)
%14 = tail call i32 @fgetc(i32* %7)
%15 = tail call i64 @feof(i32* %7)
%16 = icmp eq i64 %15, 0
br i1 %16, label %11, label %17
17: ; preds = %11, %0
%18 = tail call i32 @fclose(i32* %7)
ret void
}