#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 EOF;
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ putchar(int);
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
int /*<<< orphan*/ *tmpfile();
int main() {
  int c;
  FILE *fp = tmpfile();
  while ((c = fgetc(fp)) != EOF) {
    putchar(c);
  }
  rewind(fp);
  while ((c = fgetc(fp)) != EOF) {
    putchar(c);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1060 <tmpfile@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %eax,-0x8(%rbp)
mov    0x2e7b(%rip),%rcx
cmp    (%rcx),%eax
je     1182 <main+0x42>
mov    -0x8(%rbp),%edi
call   1030 <putchar@plt>
jmp    115a <main+0x1a>
mov    -0x10(%rbp),%rdi
call   1040 <rewind@plt>
mov    -0x10(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %eax,-0x8(%rbp)
mov    0x2e4a(%rip),%rcx
cmp    (%rcx),%eax
je     11b3 <main+0x73>
mov    -0x8(%rbp),%edi
call   1030 <putchar@plt>
jmp    118b <main+0x4b>
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
xor    %eax,%eax
call   1060 <tmpfile@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1050 <fgetc@plt>
mov    0x2e8b(%rip),%r14
cmp    (%r14),%eax
je     1184 <main+0x44>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %eax,%edi
call   1030 <putchar@plt>
mov    %rbx,%rdi
call   1050 <fgetc@plt>
cmp    (%r14),%eax
jne    1170 <main+0x30>
mov    %rbx,%rdi
call   1040 <rewind@plt>
nopl   0x0(%rax)
mov    %rbx,%rdi
call   1050 <fgetc@plt>
cmp    (%r14),%eax
je     11a6 <main+0x66>
mov    %eax,%edi
call   1030 <putchar@plt>
jmp    1190 <main+0x50>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@EOF = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32*
store i32 0, i32* %1
%4 = call i32* (...) @tmpfile()
store i32* %4, i32** %3
br label %5
5: ; preds = %10, %0
%6 = load i32*, i32** %3
%7 = call i32 @fgetc(i32* %6)
store i32 %7, i32* %2
%8 = load i32, i32* @EOF
%9 = icmp ne i32 %7, %8
br i1 %9, label %10, label %13
10: ; preds = %5
%11 = load i32, i32* %2
%12 = call i32 @putchar(i32 %11)
br label %5
13: ; preds = %5
%14 = load i32*, i32** %3
%15 = call i32 @rewind(i32* %14)
br label %16
16: ; preds = %21, %13
%17 = load i32*, i32** %3
%18 = call i32 @fgetc(i32* %17)
store i32 %18, i32* %2
%19 = load i32, i32* @EOF
%20 = icmp ne i32 %18, %19
br i1 %20, label %21, label %24
21: ; preds = %16
%22 = load i32, i32* %2
%23 = call i32 @putchar(i32 %22)
br label %16
24: ; preds = %16
%25 = load i32, i32* %1
ret i32 %25
}

LLVM IR (-O2):
@EOF = global i32 0
define i32 @main() {
%1 = tail call i32* (...) @tmpfile()
%2 = tail call i32 @fgetc(i32* %1)
%3 = load i32, i32* @EOF
%4 = icmp eq i32 %2, %3
br i1 %4, label %11, label %5
5: ; preds = %0, %5
%6 = phi i32 [ %8, %5 ], [ %2, %0 ]
%7 = tail call i32 @putchar(i32 %6)
%8 = tail call i32 @fgetc(i32* %1)
%9 = load i32, i32* @EOF
%10 = icmp eq i32 %8, %9
br i1 %10, label %11, label %5
11: ; preds = %5, %0
%12 = tail call i32 @rewind(i32* %1)
%13 = tail call i32 @fgetc(i32* %1)
%14 = load i32, i32* @EOF
%15 = icmp eq i32 %13, %14
br i1 %15, label %22, label %16
16: ; preds = %11, %16
%17 = phi i32 [ %19, %16 ], [ %13, %11 ]
%18 = tail call i32 @putchar(i32 %17)
%19 = tail call i32 @fgetc(i32* %1)
%20 = load i32, i32* @EOF
%21 = icmp eq i32 %19, %20
br i1 %21, label %22, label %16
22: ; preds = %16, %11
ret i32 0
}