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

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fgetpos(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ fsetpos(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
void fgetpos_t() {
  FILE *fp;
  fpos_t position;
  fp = fopen("file.txt", "w+");
  fgetpos(fp, &position);
  fputs("Hello, World!", fp);
  fsetpos(fp, &position);
  fputs("This is going to override previous content", fp);
  fclose(fp);
}


x86 assembly (clang, -O0):
<fgetpos_t>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xea1(%rip),%rdi
lea    0xea3(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0xc(%rbp),%rsi
call   1040 <fgetpos@plt>
mov    -0x8(%rbp),%rsi
lea    0xe85(%rip),%rdi
call   1050 <fputs@plt>
mov    -0x8(%rbp),%rdi
lea    -0xc(%rbp),%rsi
call   1070 <fsetpos@plt>
mov    -0x8(%rbp),%rsi
lea    0xe76(%rip),%rdi
call   1050 <fputs@plt>
mov    -0x8(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fgetpos_t>:
push   %r14
push   %rbx
push   %rax
lea    0xea5(%rip),%rdi
lea    0xea7(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,%rbx
lea    0x4(%rsp),%r14
mov    %rax,%rdi
mov    %r14,%rsi
call   1040 <fgetpos@plt>
lea    0xe8b(%rip),%rdi
mov    $0xd,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1070 <fwrite@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1060 <fsetpos@plt>
lea    0xe75(%rip),%rdi
mov    $0x2a,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1070 <fwrite@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [9 x i8] c"file.txt\00"
@.str.1 = [3 x i8] c"w+\00"
@.str.2 = [14 x i8] c"Hello, World!\00"
@.str.3 = [43 x i8] c"This is going to override previous content\00"
define void @fgetpos_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 @fgetpos(i32* %4, i32* %2)
%6 = load i32*, i32** %1
%7 = call i32 @fputs(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32* %6)
%8 = load i32*, i32** %1
%9 = call i32 @fsetpos(i32* %8, i32* %2)
%10 = load i32*, i32** %1
%11 = call i32 @fputs(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.3, i64 0, i64 0), i32* %10)
%12 = load i32*, i32** %1
%13 = call i32 @fclose(i32* %12)
ret void
}

LLVM IR (-O2):
@.str = [9 x i8] c"file.txt\00"
@.str.1 = [3 x i8] c"w+\00"
@.str.2 = [14 x i8] c"Hello, World!\00"
@.str.3 = [43 x i8] c"This is going to override previous content\00"
define void @fgetpos_t() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = 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))
%4 = call i32 @fgetpos(i32* %3, i32* %1)
%5 = tail call i64 @fwrite(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i64 13, i64 1, i32* %3)
%6 = call i32 @fsetpos(i32* %3, i32* %1)
%7 = call i64 @fwrite(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.3, i64 0, i64 0), i64 42, i64 1, i32* %3)
%8 = call i32 @fclose(i32* %3)
ret void
}