#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*/ *);
int /*<<< orphan*/ fseeko(int /*<<< orphan*/ *, int /*<<< orphan*/,
                          int /*<<< orphan*/);
scalar_t__ getc(int /*<<< orphan*/ *);
int /*<<< orphan*/ putc(char, int /*<<< orphan*/ *);
int /*<<< orphan*/ *tmpfile();
size_t b_stdio_putcgetc(void *dummy) {
  FILE *f = tmpfile();
  size_t i;
  size_t cs;
  for (i = 0; i < 5000000; i++)
    putc('x', f);
  fseeko(f, 0, SEEK_SET);
  for (i = 0; i < 5000000; i++)
    cs += getc(f);
  fclose(f);
  return cs;
}


x86 assembly (clang, -O0):
<b_stdio_putcgetc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x0,%al
call   1040 <tmpfile@plt>
mov    %rax,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
cmpq   $0x4c4b40,-0x18(%rbp)
jae    119c <b_stdio_putcgetc+0x4c>
mov    -0x10(%rbp),%rsi
mov    $0x78,%edi
call   1050 <putc@plt>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    116f <b_stdio_putcgetc+0x1f>
mov    -0x10(%rbp),%rdi
mov    0x2e39(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1060 <fseeko@plt>
movq   $0x0,-0x18(%rbp)
cmpq   $0x4c4b40,-0x18(%rbp)
jae    11e8 <b_stdio_putcgetc+0x98>
mov    -0x10(%rbp),%rdi
call   1070 <getc@plt>
add    -0x20(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    11b8 <b_stdio_putcgetc+0x68>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x20(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<b_stdio_putcgetc>:
push   %r15
push   %r14
push   %rbx
xor    %eax,%eax
call   1040 <tmpfile@plt>
mov    %rax,%r14
mov    $0x4c4b40,%ebx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    $0x78,%edi
mov    %r14,%rsi
call   1050 <putc@plt>
add    $0xffffffffffffffff,%rbx
jne    1170 <b_stdio_putcgetc+0x20>
mov    0x2e56(%rip),%rax
mov    (%rax),%edx
mov    %r14,%rdi
xor    %esi,%esi
call   1060 <fseeko@plt>
mov    $0x4c4b40,%ebx
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
call   1070 <getc@plt>
add    %rax,%r15
add    $0xffffffffffffffff,%rbx
jne    11a0 <b_stdio_putcgetc+0x50>
mov    %r14,%rdi
call   1030 <fclose@plt>
mov    %r15,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@SEEK_SET = global i32 0
define i64 @b_stdio_putcgetc(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i64
%5 = alloca i64
store i8* %0, i8** %2
%6 = call i32* (...) @tmpfile()
store i32* %6, i32** %3
store i64 0, i64* %4
br label %7
7: ; preds = %13, %1
%8 = load i64, i64* %4
%9 = icmp ult i64 %8, 5000000
br i1 %9, label %10, label %16
10: ; preds = %7
%11 = load i32*, i32** %3
%12 = call i32 @putc(i8 signext 120, i32* %11)
br label %13
13: ; preds = %10
%14 = load i64, i64* %4
%15 = add i64 %14, 1
store i64 %15, i64* %4
br label %7
16: ; preds = %7
%17 = load i32*, i32** %3
%18 = load i32, i32* @SEEK_SET
%19 = call i32 @fseeko(i32* %17, i32 0, i32 %18)
store i64 0, i64* %4
br label %20
20: ; preds = %28, %16
%21 = load i64, i64* %4
%22 = icmp ult i64 %21, 5000000
br i1 %22, label %23, label %31
23: ; preds = %20
%24 = load i32*, i32** %3
%25 = call i64 @getc(i32* %24)
%26 = load i64, i64* %5
%27 = add i64 %26, %25
store i64 %27, i64* %5
br label %28
28: ; preds = %23
%29 = load i64, i64* %4
%30 = add i64 %29, 1
store i64 %30, i64* %4
br label %20
31: ; preds = %20
%32 = load i32*, i32** %3
%33 = call i32 @fclose(i32* %32)
%34 = load i64, i64* %5
ret i64 %34
}

LLVM IR (-O2):
@SEEK_SET = global i32 0
define i64 @b_stdio_putcgetc(i8* nocapture readnone %0) {
%2 = tail call i32* (...) @tmpfile()
br label %3
3: ; preds = %1, %3
%4 = phi i64 [ 0, %1 ], [ %6, %3 ]
%5 = tail call i32 @putc(i8 signext 120, i32* %2)
%6 = add nuw nsw i64 %4, 1
%7 = icmp eq i64 %6, 5000000
br i1 %7, label %8, label %3
8: ; preds = %3
%9 = load i32, i32* @SEEK_SET
%10 = tail call i32 @fseeko(i32* %2, i32 0, i32 %9)
br label %11
11: ; preds = %8, %11
%12 = phi i64 [ undef, %8 ], [ %15, %11 ]
%13 = phi i64 [ 0, %8 ], [ %16, %11 ]
%14 = tail call i64 @getc(i32* %2)
%15 = add i64 %14, %12
%16 = add nuw nsw i64 %13, 1
%17 = icmp eq i64 %16, 5000000
br i1 %17, label %18, label %11
18: ; preds = %11
%19 = tail call i32 @fclose(i32* %2)
ret i64 %15
}