#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 */
char *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ *stdout;
char *extended_fgets(char *line, int size, FILE *file) {
  extern FILE *save_file;
  extern FILE *playback_file;
  char *result;
  if (playback_file != NULL) {
    result = fgets(line, size, playback_file);
    fputs(line, stdout);
  } else
    result = fgets(line, size, file);
  if (save_file != NULL)
    fputs(line, save_file);
  return (result);
}


x86 assembly (clang, -O0):
<extended_fgets>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    0x2e96(%rip),%rax
cmpq   $0x0,(%rax)
je     1176 <extended_fgets+0x56>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    0x2e7e(%rip),%rax
mov    (%rax),%rdx
call   1040 <fgets@plt>
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    0x2e6f(%rip),%rax
mov    (%rax),%rsi
call   1030 <fputs@plt>
jmp    118a <extended_fgets+0x6a>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x18(%rbp),%rdx
call   1040 <fgets@plt>
mov    %rax,-0x20(%rbp)
mov    0x2e57(%rip),%rax
cmpq   $0x0,(%rax)
je     11ae <extended_fgets+0x8e>
mov    -0x8(%rbp),%rdi
mov    0x2e42(%rip),%rax
mov    (%rax),%rsi
call   1030 <fputs@plt>
mov    -0x20(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<extended_fgets>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    0x2ea2(%rip),%rax
mov    (%rax),%rax
test   %rax,%rax
je     1155 <extended_fgets+0x35>
mov    %rax,%rdx
call   1040 <fgets@plt>
mov    %rax,%r14
mov    0x2e90(%rip),%rax
mov    (%rax),%rsi
mov    %rbx,%rdi
call   1030 <fputs@plt>
jmp    115d <extended_fgets+0x3d>
call   1040 <fgets@plt>
mov    %rax,%r14
mov    0x2e84(%rip),%rax
mov    (%rax),%rsi
test   %rsi,%rsi
je     1174 <extended_fgets+0x54>
mov    %rbx,%rdi
call   1030 <fputs@plt>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@playback_file = external global i32*
@stdout = global i32* null
@save_file = external global i32*
define i8* @extended_fgets(i8* %0, i32 %1, i32* %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i8*
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32* %2, i32** %6
%8 = load i32*, i32** @playback_file
%9 = icmp ne i32* %8, null
br i1 %9, label %10, label %18
10: ; preds = %3
%11 = load i8*, i8** %4
%12 = load i32, i32* %5
%13 = load i32*, i32** @playback_file
%14 = call i8* @fgets(i8* %11, i32 %12, i32* %13)
store i8* %14, i8** %7
%15 = load i8*, i8** %4
%16 = load i32*, i32** @stdout
%17 = call i32 @fputs(i8* %15, i32* %16)
br label %23
18: ; preds = %3
%19 = load i8*, i8** %4
%20 = load i32, i32* %5
%21 = load i32*, i32** %6
%22 = call i8* @fgets(i8* %19, i32 %20, i32* %21)
store i8* %22, i8** %7
br label %23
23: ; preds = %18, %10
%24 = load i32*, i32** @save_file
%25 = icmp ne i32* %24, null
br i1 %25, label %26, label %30
26: ; preds = %23
%27 = load i8*, i8** %4
%28 = load i32*, i32** @save_file
%29 = call i32 @fputs(i8* %27, i32* %28)
br label %30
30: ; preds = %26, %23
%31 = load i8*, i8** %7
ret i8* %31
}

LLVM IR (-O2):
@playback_file = external global i32*
@stdout = global i32* null
@save_file = external global i32*
define i8* @extended_fgets(i8* %0, i32 %1, i32* nocapture %2) {
%4 = load i32*, i32** @playback_file
%5 = icmp eq i32* %4, null
br i1 %5, label %10, label %6
6: ; preds = %3
%7 = tail call i8* @fgets(i8* %0, i32 %1, i32* %4)
%8 = load i32*, i32** @stdout
%9 = tail call i32 @fputs(i8* %0, i32* %8)
br label %12
10: ; preds = %3
%11 = tail call i8* @fgets(i8* %0, i32 %1, i32* %2)
br label %12
12: ; preds = %10, %6
%13 = phi i8* [ %7, %6 ], [ %11, %10 ]
%14 = load i32*, i32** @save_file
%15 = icmp eq i32* %14, null
br i1 %15, label %18, label %16
16: ; preds = %12
%17 = tail call i32 @fputs(i8* %0, i32* %14)
br label %18
18: ; preds = %16, %12
ret i8* %13
}