#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*/ line;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int EOF;
scalar_t__ compare_file(char *, char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/ *);
int getopt(int, char **, char *);
scalar_t__ malloc(scalar_t__);
char *optarg;
int optind;
int /*<<< orphan*/ parse_config_file(int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ rename(char *, char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ *stdin;
int /*<<< orphan*/ *stdout;
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
scalar_t__ strlen(char *);
int /*<<< orphan*/ substitute_line(char *);
int /*<<< orphan*/ unlink(char *);
int main(int argc, char **argv) {
  char line[2048];
  int c;
  FILE *in, *out;
  char *outfn = NULL, *newfn = NULL;
  int verbose = 0;
  while ((c = getopt(argc, argv, "f:v")) != EOF) {
    switch (c) {
    case 'f':
      in = fopen(optarg, "r");
      if (!in) {
        perror(optarg);
        exit(1);
      }
      parse_config_file(in);
      fclose(in);
      break;
    case 'v':
      verbose++;
      break;
    default:
      fprintf(stderr, "%s: [-f config-file] [file]\n", argv[0]);
      break;
    }
  }
  if (optind < argc) {
    in = fopen(argv[optind], "r");
    if (!in) {
      perror(argv[optind]);
      exit(1);
    }
    optind++;
  } else
    in = stdin;
  if (optind < argc) {
    outfn = argv[optind];
    newfn = (char *)malloc(strlen(outfn) + 20);
    if (!newfn) {
      fprintf(stderr, "Memory error!  Exiting.\n");
      exit(1);
    }
    strcpy(newfn, outfn);
    strcat(newfn, ".new");
    out = fopen(newfn, "w");
    if (!out) {
      perror(newfn);
      exit(1);
    }
  } else {
    out = stdout;
    outfn = 0;
  }
  while (!feof(in)) {
    if (fgets(line, sizeof(line), in) == NULL)
      break;
    substitute_line(line);
    fputs(line, out);
  }
  fclose(in);
  fclose(out);
  if (outfn) {
    if (compare_file(outfn, newfn)) {
      if (verbose)
        printf("No change, keeping %s.\n", outfn);
      unlink(newfn);
    } else {
      if (verbose)
        printf("Creating or replacing %s.\n", outfn);
      rename(newfn, outfn);
    }
  }
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x840,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x830(%rbp)
movq   $0x0,-0x838(%rbp)
movl   $0x0,-0x83c(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xd89(%rip),%rdx
call   1120 <getopt@plt>
mov    %eax,-0x814(%rbp)
mov    0x2d4f(%rip),%rcx
cmp    (%rcx),%eax
je     1357 <main+0x127>
mov    -0x814(%rbp),%eax
mov    %eax,-0x840(%rbp)
sub    $0x66,%eax
je     12bf <main+0x8f>
jmp    12ab <main+0x7b>
mov    -0x840(%rbp),%eax
sub    $0x76,%eax
je     1320 <main+0xf0>
jmp    1334 <main+0x104>
mov    0x2d32(%rip),%rax
mov    (%rax),%rdi
lea    0xd34(%rip),%rsi
call   10f0 <fopen@plt>
mov    %rax,-0x820(%rbp)
cmpq   $0x0,-0x820(%rbp)
jne    1303 <main+0xd3>
mov    0x2d07(%rip),%rax
mov    (%rax),%rdi
call   1100 <perror@plt>
mov    $0x1,%edi
call   1140 <exit@plt>
mov    -0x820(%rbp),%rdi
call   1150 <parse_config_file@plt>
mov    -0x820(%rbp),%rdi
call   1050 <fclose@plt>
jmp    1352 <main+0x122>
mov    -0x83c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x83c(%rbp)
jmp    1352 <main+0x122>
mov    0x2c85(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xcbb(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
jmp    1269 <main+0x39>
mov    0x2c72(%rip),%rax
mov    (%rax),%eax
cmp    -0x8(%rbp),%eax
jge    13d7 <main+0x1a7>
mov    -0x10(%rbp),%rax
mov    0x2c5c(%rip),%rcx
movslq (%rcx),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xc82(%rip),%rsi
call   10f0 <fopen@plt>
mov    %rax,-0x820(%rbp)
cmpq   $0x0,-0x820(%rbp)
jne    13bd <main+0x18d>
mov    -0x10(%rbp),%rax
mov    0x2c29(%rip),%rcx
movslq (%rcx),%rcx
mov    (%rax,%rcx,8),%rdi
call   1100 <perror@plt>
mov    $0x1,%edi
call   1140 <exit@plt>
mov    0x2c0c(%rip),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    0x2c00(%rip),%rax
mov    %ecx,(%rax)
jmp    13e8 <main+0x1b8>
mov    0x2c02(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x820(%rbp)
mov    0x2be1(%rip),%rax
mov    (%rax),%eax
cmp    -0x8(%rbp),%eax
jge    14ca <main+0x29a>
mov    -0x10(%rbp),%rax
mov    0x2bcb(%rip),%rcx
movslq (%rcx),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x830(%rbp)
mov    -0x830(%rbp),%rdi
call   1060 <strlen@plt>
mov    %rax,%rdi
add    $0x14,%rdi
call   10d0 <malloc@plt>
mov    %rax,-0x838(%rbp)
cmpq   $0x0,-0x838(%rbp)
jne    1461 <main+0x231>
mov    0x2b79(%rip),%rax
mov    (%rax),%edi
lea    0xbd3(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
mov    $0x1,%edi
call   1140 <exit@plt>
mov    -0x838(%rbp),%rdi
mov    -0x830(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x838(%rbp),%rdi
lea    0xbba(%rip),%rsi
call   1130 <strcat@plt>
mov    -0x838(%rbp),%rdi
lea    0xbaa(%rip),%rsi
call   10f0 <fopen@plt>
mov    %rax,-0x828(%rbp)
cmpq   $0x0,-0x828(%rbp)
jne    14c5 <main+0x295>
mov    -0x838(%rbp),%rdi
call   1100 <perror@plt>
mov    $0x1,%edi
call   1140 <exit@plt>
jmp    14e6 <main+0x2b6>
mov    0x2ae7(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x828(%rbp)
movq   $0x0,-0x830(%rbp)
jmp    14eb <main+0x2bb>
mov    -0x820(%rbp),%rdi
call   10b0 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    150c <main+0x2dc>
jmp    1557 <main+0x327>
lea    -0x810(%rbp),%rdi
mov    -0x820(%rbp),%rdx
mov    $0x800,%esi
call   1090 <fgets@plt>
cmp    $0x0,%rax
jne    1533 <main+0x303>
jmp    1557 <main+0x327>
lea    -0x810(%rbp),%rdi
call   10e0 <substitute_line@plt>
lea    -0x810(%rbp),%rdi
mov    -0x828(%rbp),%rsi
call   1080 <fputs@plt>
jmp    14eb <main+0x2bb>
mov    -0x820(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x828(%rbp),%rdi
call   1050 <fclose@plt>
cmpq   $0x0,-0x830(%rbp)
je     1603 <main+0x3d3>
mov    -0x830(%rbp),%rdi
mov    -0x838(%rbp),%rsi
call   10c0 <compare_file@plt>
cmp    $0x0,%rax
je     15cb <main+0x39b>
cmpl   $0x0,-0x83c(%rbp)
je     15ba <main+0x38a>
mov    -0x830(%rbp),%rsi
lea    0xa8c(%rip),%rdi
call   1070 <printf@plt>
mov    -0x838(%rbp),%rdi
call   1030 <unlink@plt>
jmp    15fe <main+0x3ce>
cmpl   $0x0,-0x83c(%rbp)
je     15eb <main+0x3bb>
mov    -0x830(%rbp),%rsi
lea    0xa73(%rip),%rdi
call   1070 <printf@plt>
mov    -0x838(%rbp),%rdi
mov    -0x830(%rbp),%rsi
call   1110 <rename@plt>
jmp    1603 <main+0x3d3>
xor    %eax,%eax
add    $0x840,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x808,%rsp
mov    %rsi,%rbx
mov    %edi,%r13d
lea    0xdb2(%rip),%rdx
call   1120 <getopt@plt>
mov    0x2d7e(%rip),%r12
xor    %r15d,%r15d
cmp    (%r12),%eax
jne    12bc <main+0x8c>
mov    0x2d66(%rip),%rbp
mov    0x0(%rbp),%eax
cmp    %r13d,%eax
jge    1346 <main+0x116>
cltq
mov    (%rbx,%rax,8),%rdi
lea    0xd81(%rip),%rsi
call   10f0 <fopen@plt>
mov    %rax,%r14
movslq 0x0(%rbp),%rax
test   %r14,%r14
je     1483 <main+0x253>
add    $0x1,%eax
mov    %eax,0x0(%rbp)
cmp    %r13d,%eax
jl     1359 <main+0x129>
mov    0x2d0a(%rip),%rax
mov    (%rax),%rbx
xor    %r13d,%r13d
xor    %r12d,%r12d
jmp    13b1 <main+0x181>
lea    0xd3d(%rip),%r14
xor    %r15d,%r15d
jmp    1302 <main+0xd2>
nopl   0x0(%rax,%rax,1)
mov    0x2ce9(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xd23(%rip),%rsi
xor    %eax,%eax
call   10a0 <fprintf@plt>
mov    %r13d,%edi
mov    %rbx,%rsi
mov    %r14,%rdx
call   1120 <getopt@plt>
cmp    (%r12),%eax
je     1263 <main+0x33>
cmp    $0x76,%eax
je     1340 <main+0x110>
cmp    $0x66,%eax
jne    12d0 <main+0xa0>
mov    0x2ce5(%rip),%rax
mov    (%rax),%rdi
lea    0xce7(%rip),%rsi
call   10f0 <fopen@plt>
test   %rax,%rax
je     146a <main+0x23a>
mov    %rax,%rbp
mov    %rax,%rdi
call   1150 <parse_config_file@plt>
mov    %rbp,%rdi
call   1050 <fclose@plt>
jmp    12ea <main+0xba>
add    $0x1,%r15d
jmp    12ea <main+0xba>
mov    0x2c93(%rip),%rcx
mov    (%rcx),%r14
cmp    %r13d,%eax
jge    12a7 <main+0x77>
cltq
mov    (%rbx,%rax,8),%r13
mov    %r13,%rdi
call   1060 <strlen@plt>
lea    0x14(%rax),%rdi
call   10d0 <malloc@plt>
test   %rax,%rax
je     1489 <main+0x259>
mov    %rax,%r12
mov    %rax,%rdi
mov    %r13,%rsi
call   1040 <strcpy@plt>
lea    0xcae(%rip),%rsi
mov    %r12,%rdi
call   1130 <strcat@plt>
lea    0xca2(%rip),%rsi
mov    %r12,%rdi
call   10f0 <fopen@plt>
test   %rax,%rax
je     14aa <main+0x27a>
mov    %rax,%rbx
mov    %r14,%rdi
call   10b0 <feof@plt>
test   %eax,%eax
jne    13f4 <main+0x1c4>
mov    %rsp,%rbp
mov    %rbp,%rdi
mov    $0x800,%esi
mov    %r14,%rdx
call   1090 <fgets@plt>
test   %rax,%rax
je     13f4 <main+0x1c4>
mov    %rbp,%rdi
call   10e0 <substitute_line@plt>
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1080 <fputs@plt>
mov    %r14,%rdi
call   10b0 <feof@plt>
test   %eax,%eax
je     13c0 <main+0x190>
mov    %r14,%rdi
call   1050 <fclose@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
test   %r13,%r13
je     1456 <main+0x226>
mov    %r13,%rdi
mov    %r12,%rsi
call   10c0 <compare_file@plt>
test   %rax,%rax
je     1437 <main+0x207>
test   %r15d,%r15d
je     142d <main+0x1fd>
lea    0xc1c(%rip),%rdi
mov    %r13,%rsi
call   1070 <printf@plt>
mov    %r12,%rdi
call   1030 <unlink@plt>
jmp    1456 <main+0x226>
test   %r15d,%r15d
je     144b <main+0x21b>
lea    0xc16(%rip),%rdi
mov    %r13,%rsi
call   1070 <printf@plt>
mov    %r12,%rdi
mov    %r13,%rsi
call   1110 <rename@plt>
xor    %eax,%eax
add    $0x808,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2b87(%rip),%rax
mov    (%rax),%rdi
call   1100 <perror@plt>
mov    $0x1,%edi
call   1140 <exit@plt>
mov    (%rbx,%rax,8),%rdi
jmp    1474 <main+0x244>
mov    0x2b30(%rip),%rax
mov    (%rax),%edi
lea    0xb8a(%rip),%rsi
xor    %eax,%eax
call   10a0 <fprintf@plt>
mov    $0x1,%edi
call   1140 <exit@plt>
mov    %r12,%rdi
jmp    1474 <main+0x244>

LLVM IR (-O0):
@.str = [4 x i8] c"f:v\00"
@EOF = global i32 0
@optarg = global i8* null
@.str.1 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.2 = [29 x i8] c"%s: [-f config-file] [file]\0A\00"
@optind = global i32 0
@stdin = global i32* null
@.str.3 = [25 x i8] c"Memory error! Exiting.\0A\00"
@.str.4 = [5 x i8] c".new\00"
@.str.5 = [2 x i8] c"w\00"
@stdout = global i32* null
@.str.6 = [24 x i8] c"No change, keeping %s.\0A\00"
@.str.7 = [27 x i8] c"Creating or replacing %s.\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [2048 x i8]
%7 = alloca i32
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* null, i8** %10
store i8* null, i8** %11
store i32 0, i32* %12
br label %13
13: ; preds = %44, %2
%14 = load i32, i32* %4
%15 = load i8**, i8*** %5
%16 = call i32 @getopt(i32 %14, i8** %15, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
store i32 %16, i32* %7
%17 = load i32, i32* @EOF
%18 = icmp ne i32 %16, %17
br i1 %18, label %19, label %45
19: ; preds = %13
%20 = load i32, i32* %7
switch i32 %20, label %38 [
i32 102, label %21
i32 118, label %35
]
21: ; preds = %19
%22 = load i8*, i8** @optarg
%23 = call i32* @fopen(i8* %22, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %23, i32** %8
%24 = load i32*, i32** %8
%25 = icmp ne i32* %24, null
br i1 %25, label %30, label %26
26: ; preds = %21
%27 = load i8*, i8** @optarg
%28 = call i32 @perror(i8* %27)
%29 = call i32 @exit(i32 1)
unreachable
30: ; preds = %21
%31 = load i32*, i32** %8
%32 = call i32 @parse_config_file(i32* %31)
%33 = load i32*, i32** %8
%34 = call i32 @fclose(i32* %33)
br label %44
35: ; preds = %19
%36 = load i32, i32* %12
%37 = add nsw i32 %36, 1
store i32 %37, i32* %12
br label %44
38: ; preds = %19
%39 = load i32, i32* @stderr
%40 = load i8**, i8*** %5
%41 = getelementptr inbounds i8*, i8** %40, i64 0
%42 = load i8*, i8** %41
%43 = call i32 (i32, i8*, ...) @fprintf(i32 %39, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i8* %42)
br label %44
44: ; preds = %38, %35, %30
br label %13
45: ; preds = %13
%46 = load i32, i32* @optind
%47 = load i32, i32* %4
%48 = icmp slt i32 %46, %47
br i1 %48, label %49, label %69
49: ; preds = %45
%50 = load i8**, i8*** %5
%51 = load i32, i32* @optind
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds i8*, i8** %50, i64 %52
%54 = load i8*, i8** %53
%55 = call i32* @fopen(i8* %54, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %55, i32** %8
%56 = load i32*, i32** %8
%57 = icmp ne i32* %56, null
br i1 %57, label %66, label %58
58: ; preds = %49
%59 = load i8**, i8*** %5
%60 = load i32, i32* @optind
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds i8*, i8** %59, i64 %61
%63 = load i8*, i8** %62
%64 = call i32 @perror(i8* %63)
%65 = call i32 @exit(i32 1)
unreachable
66: ; preds = %49
%67 = load i32, i32* @optind
%68 = add nsw i32 %67, 1
store i32 %68, i32* @optind
br label %71
69: ; preds = %45
%70 = load i32*, i32** @stdin
store i32* %70, i32** %8
br label %71
71: ; preds = %69, %66
%72 = load i32, i32* @optind
%73 = load i32, i32* %4
%74 = icmp slt i32 %72, %73
br i1 %74, label %75, label %107
75: ; preds = %71
%76 = load i8**, i8*** %5
%77 = load i32, i32* @optind
%78 = sext i32 %77 to i64
%79 = getelementptr inbounds i8*, i8** %76, i64 %78
%80 = load i8*, i8** %79
store i8* %80, i8** %10
%81 = load i8*, i8** %10
%82 = call i64 @strlen(i8* %81)
%83 = add nsw i64 %82, 20
%84 = call i64 @malloc(i64 %83)
%85 = inttoptr i64 %84 to i8*
store i8* %85, i8** %11
%86 = load i8*, i8** %11
%87 = icmp ne i8* %86, null
br i1 %87, label %92, label %88
88: ; preds = %75
%89 = load i32, i32* @stderr
%90 = call i32 (i32, i8*, ...) @fprintf(i32 %89, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0))
%91 = call i32 @exit(i32 1)
unreachable
92: ; preds = %75
%93 = load i8*, i8** %11
%94 = load i8*, i8** %10
%95 = call i32 @strcpy(i8* %93, i8* %94)
%96 = load i8*, i8** %11
%97 = call i32 @strcat(i8* %96, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%98 = load i8*, i8** %11
%99 = call i32* @fopen(i8* %98, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
store i32* %99, i32** %9
%100 = load i32*, i32** %9
%101 = icmp ne i32* %100, null
br i1 %101, label %106, label %102
102: ; preds = %92
%103 = load i8*, i8** %11
%104 = call i32 @perror(i8* %103)
%105 = call i32 @exit(i32 1)
unreachable
106: ; preds = %92
br label %109
107: ; preds = %71
%108 = load i32*, i32** @stdout
store i32* %108, i32** %9
store i8* null, i8** %10
br label %109
109: ; preds = %107, %106
br label %110
110: ; preds = %121, %109
%111 = load i32*, i32** %8
%112 = call i32 @feof(i32* %111)
%113 = icmp ne i32 %112, 0
%114 = xor i1 %113, true
br i1 %114, label %115, label %127
115: ; preds = %110
%116 = getelementptr inbounds [2048 x i8], [2048 x i8]* %6, i64 0, i64 0
%117 = load i32*, i32** %8
%118 = call i32* @fgets(i8* %116, i32 2048, i32* %117)
%119 = icmp eq i32* %118, null
br i1 %119, label %120, label %121
120: ; preds = %115
br label %127
121: ; preds = %115
%122 = getelementptr inbounds [2048 x i8], [2048 x i8]* %6, i64 0, i64 0
%123 = call i32 @substitute_line(i8* %122)
%124 = getelementptr inbounds [2048 x i8], [2048 x i8]* %6, i64 0, i64 0
%125 = load i32*, i32** %9
%126 = call i32 @fputs(i8* %124, i32* %125)
br label %110
127: ; preds = %120, %110
%128 = load i32*, i32** %8
%129 = call i32 @fclose(i32* %128)
%130 = load i32*, i32** %9
%131 = call i32 @fclose(i32* %130)
%132 = load i8*, i8** %10
%133 = icmp ne i8* %132, null
br i1 %133, label %134, label %159
134: ; preds = %127
%135 = load i8*, i8** %10
%136 = load i8*, i8** %11
%137 = call i64 @compare_file(i8* %135, i8* %136)
%138 = icmp ne i64 %137, 0
br i1 %138, label %139, label %148
139: ; preds = %134
%140 = load i32, i32* %12
%141 = icmp ne i32 %140, 0
br i1 %141, label %142, label %145
142: ; preds = %139
%143 = load i8*, i8** %10
%144 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.6, i64 0, i64 0), i8* %143)
br label %145
145: ; preds = %142, %139
%146 = load i8*, i8** %11
%147 = call i32 @unlink(i8* %146)
br label %158
148: ; preds = %134
%149 = load i32, i32* %12
%150 = icmp ne i32 %149, 0
br i1 %150, label %151, label %154
151: ; preds = %148
%152 = load i8*, i8** %10
%153 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.7, i64 0, i64 0), i8* %152)
br label %154
154: ; preds = %151, %148
%155 = load i8*, i8** %11
%156 = load i8*, i8** %10
%157 = call i32 @rename(i8* %155, i8* %156)
br label %158
158: ; preds = %154, %145
br label %159
159: ; preds = %158, %127
ret i32 0
}

LLVM IR (-O2):
@.str = [4 x i8] c"f:v\00"
@EOF = global i32 0
@optarg = global i8* null
@.str.1 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.2 = [29 x i8] c"%s: [-f config-file] [file]\0A\00"
@optind = global i32 0
@stdin = global i32* null
@.str.3 = [25 x i8] c"Memory error! Exiting.\0A\00"
@.str.4 = [5 x i8] c".new\00"
@.str.5 = [2 x i8] c"w\00"
@stdout = global i32* null
@.str.6 = [24 x i8] c"No change, keeping %s.\0A\00"
@.str.7 = [27 x i8] c"Creating or replacing %s.\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca [2048 x i8]
%4 = getelementptr inbounds [2048 x i8], [2048 x i8]* %3, i64 0, i64 0
%5 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%6 = load i32, i32* @EOF
%7 = icmp eq i32 %5, %6
br i1 %7, label %33, label %8
8: ; preds = %2, %28
%9 = phi i32 [ %30, %28 ], [ %5, %2 ]
%10 = phi i32 [ %29, %28 ], [ 0, %2 ]
switch i32 %9, label %24 [
i32 102, label %11
i32 118, label %22
]
11: ; preds = %8
%12 = load i8*, i8** @optarg
%13 = tail call i32* @fopen(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %19
15: ; preds = %11
%16 = load i8*, i8** @optarg
%17 = tail call i32 @perror(i8* %16)
%18 = tail call i32 @exit(i32 1)
unreachable
19: ; preds = %11
%20 = tail call i32 @parse_config_file(i32* %13)
%21 = tail call i32 @fclose(i32* %13)
br label %28
22: ; preds = %8
%23 = add nsw i32 %10, 1
br label %28
24: ; preds = %8
%25 = load i32, i32* @stderr
%26 = load i8*, i8** %1
%27 = tail call i32 (i32, i8*, ...) @fprintf(i32 %25, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i8* %26)
br label %28
28: ; preds = %24, %22, %19
%29 = phi i32 [ %10, %24 ], [ %23, %22 ], [ %10, %19 ]
%30 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%31 = load i32, i32* @EOF
%32 = icmp eq i32 %30, %31
br i1 %32, label %33, label %8
33: ; preds = %28, %2
%34 = phi i32 [ 0, %2 ], [ %29, %28 ]
%35 = load i32, i32* @optind
%36 = icmp slt i32 %35, %0
br i1 %36, label %37, label %52
37: ; preds = %33
%38 = sext i32 %35 to i64
%39 = getelementptr inbounds i8*, i8** %1, i64 %38
%40 = load i8*, i8** %39
%41 = tail call i32* @fopen(i8* %40, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%42 = icmp eq i32* %41, null
%43 = load i32, i32* @optind
br i1 %42, label %44, label %50
44: ; preds = %37
%45 = sext i32 %43 to i64
%46 = getelementptr inbounds i8*, i8** %1, i64 %45
%47 = load i8*, i8** %46
%48 = tail call i32 @perror(i8* %47)
%49 = tail call i32 @exit(i32 1)
unreachable
50: ; preds = %37
%51 = add nsw i32 %43, 1
store i32 %51, i32* @optind
br label %54
52: ; preds = %33
%53 = load i32*, i32** @stdin
br label %54
54: ; preds = %52, %50
%55 = phi i32 [ %51, %50 ], [ %35, %52 ]
%56 = phi i32* [ %41, %50 ], [ %53, %52 ]
%57 = icmp slt i32 %55, %0
br i1 %57, label %58, label %79
58: ; preds = %54
%59 = sext i32 %55 to i64
%60 = getelementptr inbounds i8*, i8** %1, i64 %59
%61 = load i8*, i8** %60
%62 = tail call i64 @strlen(i8* dereferenceable(1) %61)
%63 = add nsw i64 %62, 20
%64 = tail call i64 @malloc(i64 %63)
%65 = inttoptr i64 %64 to i8*
%66 = icmp eq i64 %64, 0
br i1 %66, label %67, label %71
67: ; preds = %58
%68 = load i32, i32* @stderr
%69 = tail call i32 (i32, i8*, ...) @fprintf(i32 %68, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0))
%70 = tail call i32 @exit(i32 1)
unreachable
71: ; preds = %58
%72 = tail call i32 @strcpy(i8* %65, i8* %61)
%73 = tail call i32 @strcat(i8* %65, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%74 = tail call i32* @fopen(i8* %65, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%75 = icmp eq i32* %74, null
br i1 %75, label %76, label %81
76: ; preds = %71
%77 = tail call i32 @perror(i8* %65)
%78 = tail call i32 @exit(i32 1)
unreachable
79: ; preds = %54
%80 = load i32*, i32** @stdout
br label %81
81: ; preds = %71, %79
%82 = phi i32* [ %74, %71 ], [ %80, %79 ]
%83 = phi i8* [ %61, %71 ], [ null, %79 ]
%84 = phi i8* [ %65, %71 ], [ null, %79 ]
%85 = call i32 @feof(i32* %56)
%86 = icmp eq i32 %85, 0
br i1 %86, label %87, label %95
87: ; preds = %81, %90
%88 = call i32* @fgets(i8* %4, i32 2048, i32* %56)
%89 = icmp eq i32* %88, null
br i1 %89, label %95, label %90
90: ; preds = %87
%91 = call i32 @substitute_line(i8* %4)
%92 = call i32 @fputs(i8* %4, i32* %82)
%93 = call i32 @feof(i32* %56)
%94 = icmp eq i32 %93, 0
br i1 %94, label %87, label %95
95: ; preds = %90, %87, %81
%96 = call i32 @fclose(i32* %56)
%97 = call i32 @fclose(i32* %82)
%98 = icmp eq i8* %83, null
br i1 %98, label %113, label %99
99: ; preds = %95
%100 = call i64 @compare_file(i8* %83, i8* %84)
%101 = icmp eq i64 %100, 0
%102 = icmp eq i32 %34, 0
br i1 %101, label %108, label %103
103: ; preds = %99
br i1 %102, label %106, label %104
104: ; preds = %103
%105 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.6, i64 0, i64 0), i8* %83)
br label %106
106: ; preds = %104, %103
%107 = call i32 @unlink(i8* %84)
br label %113
108: ; preds = %99
br i1 %102, label %111, label %109
109: ; preds = %108
%110 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.7, i64 0, i64 0), i8* %83)
br label %111
111: ; preds = %109, %108
%112 = call i32 @rename(i8* %84, i8* %83)
br label %113
113: ; preds = %106, %111, %95
ret i32 0
}