#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 */
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char *);
scalar_t__ subst_line(char *, char *);
int subst_file(FILE *in, FILE *out) {
  char linebuf1[4096 + 1];
  char linebuf2[4096 + 1];
  char *origline, *newline, *tmpptr;
  char *atptr, *nextptr;
  char *varname, *value;
  int dump;
  while (fgets(linebuf1, 4096, in)) {
    origline = linebuf1;
    newline = linebuf2;
    while (subst_line(origline, newline)) {
      tmpptr = origline;
      origline = newline;
      newline = tmpptr;
    }
    fprintf(out, "%s", origline);
  }
  return 1;
}


x86 assembly (clang, -O0):
<subst_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2070,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x1020(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    $0x1000,%esi
call   1030 <fgets@plt>
cmp    $0x0,%rax
je     11e6 <subst_file+0xb6>
lea    -0x1020(%rbp),%rax
mov    %rax,-0x2038(%rbp)
lea    -0x2030(%rbp),%rax
mov    %rax,-0x2040(%rbp)
mov    -0x2038(%rbp),%rdi
mov    -0x2040(%rbp),%rsi
call   1050 <subst_line@plt>
cmp    $0x0,%rax
je     11ca <subst_file+0x9a>
mov    -0x2038(%rbp),%rax
mov    %rax,-0x2048(%rbp)
mov    -0x2040(%rbp),%rax
mov    %rax,-0x2038(%rbp)
mov    -0x2048(%rbp),%rax
mov    %rax,-0x2040(%rbp)
jmp    117e <subst_file+0x4e>
mov    -0x10(%rbp),%rdi
mov    -0x2038(%rbp),%rdx
lea    0xe24(%rip),%rsi
call   1040 <fprintf@plt>
jmp    1143 <subst_file+0x13>
mov    $0x1,%eax
add    $0x2070,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<subst_file>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x2018,%rsp
mov    %rsi,%r14
mov    %rdi,%r12
lea    0x1010(%rsp),%r15
mov    %r15,%rdi
mov    $0x1000,%esi
mov    %r12,%rdx
call   1040 <fgets@plt>
test   %rax,%rax
je     11af <subst_file+0x7f>
mov    %rsp,%rbp
mov    %rbp,%rcx
mov    %r15,%rbx
nopl   (%rax)
mov    %rbx,%r13
mov    %rcx,%rbx
mov    %r13,%rdi
mov    %rcx,%rsi
call   1050 <subst_line@plt>
mov    %r13,%rcx
test   %rax,%rax
jne    1170 <subst_file+0x40>
mov    %r13,%rdi
mov    %r14,%rsi
call   1030 <fputs@plt>
mov    %r15,%rdi
mov    $0x1000,%esi
mov    %r12,%rdx
call   1040 <fgets@plt>
mov    %rbp,%rcx
mov    %r15,%rbx
test   %rax,%rax
jne    1170 <subst_file+0x40>
mov    $0x1,%eax
add    $0x2018,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%s\00"
define i32 @subst_file(i32* %0, i32* %1) {
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca [4097 x i8]
%6 = alloca [4097 x i8]
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca i8*
%14 = alloca i32
store i32* %0, i32** %3
store i32* %1, i32** %4
br label %15
15: ; preds = %32, %2
%16 = getelementptr inbounds [4097 x i8], [4097 x i8]* %5, i64 0, i64 0
%17 = load i32*, i32** %3
%18 = call i64 @fgets(i8* %16, i32 4096, i32* %17)
%19 = icmp ne i64 %18, 0
br i1 %19, label %20, label %36
20: ; preds = %15
%21 = getelementptr inbounds [4097 x i8], [4097 x i8]* %5, i64 0, i64 0
store i8* %21, i8** %7
%22 = getelementptr inbounds [4097 x i8], [4097 x i8]* %6, i64 0, i64 0
store i8* %22, i8** %8
br label %23
23: ; preds = %28, %20
%24 = load i8*, i8** %7
%25 = load i8*, i8** %8
%26 = call i64 @subst_line(i8* %24, i8* %25)
%27 = icmp ne i64 %26, 0
br i1 %27, label %28, label %32
28: ; preds = %23
%29 = load i8*, i8** %7
store i8* %29, i8** %9
%30 = load i8*, i8** %8
store i8* %30, i8** %7
%31 = load i8*, i8** %9
store i8* %31, i8** %8
br label %23
32: ; preds = %23
%33 = load i32*, i32** %4
%34 = load i8*, i8** %7
%35 = call i32 @fprintf(i32* %33, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %34)
br label %15
36: ; preds = %15
ret i32 1
}

LLVM IR (-O2):
define i32 @subst_file(i32* nocapture %0, i32* nocapture %1) {
%3 = alloca [4097 x i8]
%4 = alloca [4097 x i8]
%5 = getelementptr inbounds [4097 x i8], [4097 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [4097 x i8], [4097 x i8]* %4, i64 0, i64 0
%7 = call i64 @fgets(i8* %5, i32 4096, i32* %0)
%8 = icmp eq i64 %7, 0
br i1 %8, label %21, label %9
9: ; preds = %2, %14
%10 = phi i8* [ %15, %14 ], [ %6, %2 ]
%11 = phi i8* [ %16, %14 ], [ %5, %2 ]
%12 = call i64 @subst_line(i8* %11, i8* %10)
%13 = icmp eq i64 %12, 0
br i1 %13, label %17, label %14
14: ; preds = %9, %17
%15 = phi i8* [ %11, %9 ], [ %6, %17 ]
%16 = phi i8* [ %10, %9 ], [ %5, %17 ]
br label %9
17: ; preds = %9
%18 = call i32 @fputs(i8* %11, i32* %1)
%19 = call i64 @fgets(i8* %5, i32 4096, i32* %0)
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %14
21: ; preds = %17, %2
ret i32 1
}