#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ ftell(int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, int /*<<< orphan*/);
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
int main() {
  FILE *pFile = NULL;
  pFile = fopen("rewind.txt", "w+");
  if (pFile == NULL) {
  } else {
    printf("%1ld\n", ftell(pFile));
    fputs("0123456789", pFile);
    printf("%1ld\n", ftell(pFile));
    rewind(pFile);
    printf("%1ld\n", ftell(pFile));
    fclose(pFile);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x0,-0x10(%rbp)
lea    0xe82(%rip),%rdi
lea    0xe86(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    119e <main+0x3e>
jmp    1205 <main+0xa5>
mov    -0x10(%rbp),%rdi
call   1070 <ftell@plt>
mov    %eax,%esi
lea    0xe5e(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%rsi
lea    0xe54(%rip),%rdi
call   1060 <fputs@plt>
mov    -0x10(%rbp),%rdi
call   1070 <ftell@plt>
mov    %eax,%esi
lea    0xe37(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1050 <rewind@plt>
mov    -0x10(%rbp),%rdi
call   1070 <ftell@plt>
mov    %eax,%esi
lea    0xe17(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
lea    0xe95(%rip),%rdi
lea    0xe99(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     11e5 <main+0x85>
mov    %rax,%rbx
mov    %rax,%rdi
call   1060 <ftell@plt>
lea    0xe80(%rip),%r14
mov    %r14,%rdi
mov    %eax,%esi
call   1040 <printf@plt>
lea    0xe75(%rip),%rdi
mov    $0xa,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1080 <fwrite@plt>
mov    %rbx,%rdi
call   1060 <ftell@plt>
mov    %r14,%rdi
mov    %eax,%esi
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1050 <rewind@plt>
mov    %rbx,%rdi
call   1060 <ftell@plt>
mov    %r14,%rdi
mov    %eax,%esi
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [11 x i8] c"rewind.txt\00"
@.str.1 = [3 x i8] c"w+\00"
@.str.2 = [6 x i8] c"%1ld\0A\00"
@.str.3 = [11 x i8] c"0123456789\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
store i32 0, i32* %1
store i32* null, i32** %2
%3 = call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 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** %2
%4 = load i32*, i32** %2
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %7
6: ; preds = %0
br label %23
7: ; preds = %0
%8 = load i32*, i32** %2
%9 = call i32 @ftell(i32* %8)
%10 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 %9)
%11 = load i32*, i32** %2
%12 = call i32 @fputs(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i32* %11)
%13 = load i32*, i32** %2
%14 = call i32 @ftell(i32* %13)
%15 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 %14)
%16 = load i32*, i32** %2
%17 = call i32 @rewind(i32* %16)
%18 = load i32*, i32** %2
%19 = call i32 @ftell(i32* %18)
%20 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 %19)
%21 = load i32*, i32** %2
%22 = call i32 @fclose(i32* %21)
br label %23
23: ; preds = %7, %6
ret i32 0
}

LLVM IR (-O2):
@.str = [11 x i8] c"rewind.txt\00"
@.str.1 = [3 x i8] c"w+\00"
@.str.2 = [6 x i8] c"%1ld\0A\00"
@.str.3 = [11 x i8] c"0123456789\00"
define i32 @main() {
%1 = tail call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%2 = icmp eq i32* %1, null
br i1 %2, label %13, label %3
3: ; preds = %0
%4 = tail call i32 @ftell(i32* %1)
%5 = tail call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 %4)
%6 = tail call i64 @fwrite(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i64 10, i64 1, i32* %1)
%7 = tail call i32 @ftell(i32* %1)
%8 = tail call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 %7)
%9 = tail call i32 @rewind(i32* %1)
%10 = tail call i32 @ftell(i32* %1)
%11 = tail call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 %10)
%12 = tail call i32 @fclose(i32* %1)
br label %13
13: ; preds = %0, %3
ret i32 0
}