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

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ free(char *);
int getline(char **, size_t *, int /*<<< orphan*/ *);
int /*<<< orphan*/ rename(char *, char *);
scalar_t__ strcmp(char *, char *);
void addtexttohtml(char *scriptname, char *htmlname) {
  ssize_t read;
  size_t len = 0;
  char *line = NULL;
  FILE *in, *out, *script;
  char tmpname[] = "purejunk.tmp";
  in = fopen(htmlname, "r");
  out = fopen(tmpname, "w");
  script = fopen(scriptname, "r");
  if (in == NULL)
    exit(EXIT_FAILURE);
  if (out == NULL)
    exit(EXIT_FAILURE);
  if (script == NULL)
    exit(EXIT_FAILURE);
  while ((read = getline(&line, &len, in)) != -1) {
    if (strcmp(line, "</body>\n") == 0)
      break;
    fprintf(out, "%s", line);
  }
  while ((read = getline(&line, &len, script)) != -1)
    fprintf(out, "%s", line);
  fprintf(out, "\n\n\n</body>\n\n\n");
  while ((read = getline(&line, &len, in)) != -1)
    fprintf(out, "%s", line);
  if (line)
    free(line);
  fclose(in);
  fclose(out);
  fclose(script);
  rename(tmpname, htmlname);
}


x86 assembly (clang, -O0):
<addtexttohtml>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
mov    0xe59(%rip),%rax
mov    %rax,-0x4d(%rbp)
mov    0xe57(%rip),%eax
mov    %eax,-0x45(%rbp)
mov    0xe52(%rip),%al
mov    %al,-0x41(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe45(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x30(%rbp)
lea    -0x4d(%rbp),%rdi
lea    0xe33(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x38(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe1d(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1212 <addtexttohtml+0x92>
mov    0x2dd5(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
cmpq   $0x0,-0x38(%rbp)
jne    122b <addtexttohtml+0xab>
mov    0x2dbc(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
cmpq   $0x0,-0x40(%rbp)
jne    1244 <addtexttohtml+0xc4>
mov    0x2da3(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
jmp    1249 <addtexttohtml+0xc9>
mov    -0x30(%rbp),%rdx
lea    -0x28(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1090 <getline@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
je     12a0 <addtexttohtml+0x120>
mov    -0x28(%rbp),%rdi
lea    0xda0(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    1285 <addtexttohtml+0x105>
jmp    12a0 <addtexttohtml+0x120>
mov    -0x38(%rbp),%rdi
mov    -0x28(%rbp),%rdx
lea    0xd86(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
jmp    1249 <addtexttohtml+0xc9>
jmp    12a5 <addtexttohtml+0x125>
mov    -0x40(%rbp),%rdx
lea    -0x28(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1090 <getline@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
je     12dd <addtexttohtml+0x15d>
mov    -0x38(%rbp),%rdi
mov    -0x28(%rbp),%rdx
lea    0xd49(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
jmp    12a5 <addtexttohtml+0x125>
mov    -0x38(%rbp),%rdi
lea    0xd35(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x30(%rbp),%rdx
lea    -0x28(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1090 <getline@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
je     1327 <addtexttohtml+0x1a7>
mov    -0x38(%rbp),%rdi
mov    -0x28(%rbp),%rdx
lea    0xcff(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
jmp    12ef <addtexttohtml+0x16f>
cmpq   $0x0,-0x28(%rbp)
je     133b <addtexttohtml+0x1bb>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x30(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x38(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x40(%rbp),%rdi
call   1040 <fclose@plt>
lea    -0x4d(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1080 <rename@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<addtexttohtml>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rsi,%rbp
mov    %rdi,%r12
movq   $0x0,0x8(%rsp)
movq   $0x0,(%rsp)
movabs $0x706d742e6b6e75,%rax
mov    %rax,0x15(%rsp)
movabs $0x6b6e756a65727570,%rax
75 6e 6b
mov    %rax,0x10(%rsp)
lea    0xe33(%rip),%r14
mov    %rsi,%rdi
mov    %r14,%rsi
call   1070 <fopen@plt>
mov    %rax,%r15
lea    0xe20(%rip),%rsi
lea    0x10(%rsp),%rdi
call   1070 <fopen@plt>
mov    %rax,%rbx
mov    %r12,%rdi
mov    %r14,%rsi
call   1070 <fopen@plt>
test   %r15,%r15
je     1361 <addtexttohtml+0x1d1>
test   %rbx,%rbx
je     1361 <addtexttohtml+0x1d1>
mov    %rax,%r12
mov    %rbp,0x20(%rsp)
test   %rax,%rax
je     1361 <addtexttohtml+0x1d1>
mov    %rsp,%rdi
lea    0x8(%rsp),%rsi
mov    %r15,%rdx
call   1090 <getline@plt>
cmp    $0xffffffff,%eax
je     1280 <addtexttohtml+0xf0>
lea    0xdcb(%rip),%r13
mov    %rsp,%rbp
lea    0x8(%rsp),%r14
xchg   %ax,%ax
mov    (%rsp),%rdi
mov    %r13,%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
je     1280 <addtexttohtml+0xf0>
mov    (%rsp),%rdi
mov    %rbx,%rsi
call   1050 <fputs@plt>
mov    %rbp,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   1090 <getline@plt>
cmp    $0xffffffff,%eax
jne    1250 <addtexttohtml+0xc0>
mov    %rsp,%rdi
lea    0x8(%rsp),%rsi
mov    %r12,%rdx
call   1090 <getline@plt>
cmp    $0xffffffff,%eax
je     12bf <addtexttohtml+0x12f>
mov    %rsp,%r14
lea    0x8(%rsp),%rbp
nopl   (%rax)
mov    (%rsp),%rdi
mov    %rbx,%rsi
call   1050 <fputs@plt>
mov    %r14,%rdi
mov    %rbp,%rsi
mov    %r12,%rdx
call   1090 <getline@plt>
cmp    $0xffffffff,%eax
jne    12a0 <addtexttohtml+0x110>
lea    0xd54(%rip),%rdi
mov    $0xd,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   10b0 <fwrite@plt>
mov    %rsp,%rdi
lea    0x8(%rsp),%rsi
mov    %r15,%rdx
call   1090 <getline@plt>
cmp    $0xffffffff,%eax
mov    0x20(%rsp),%r13
je     131f <addtexttohtml+0x18f>
mov    %rsp,%r14
lea    0x8(%rsp),%rbp
nopw   0x0(%rax,%rax,1)
mov    (%rsp),%rdi
mov    %rbx,%rsi
call   1050 <fputs@plt>
mov    %r14,%rdi
mov    %rbp,%rsi
mov    %r15,%rdx
call   1090 <getline@plt>
cmp    $0xffffffff,%eax
jne    1300 <addtexttohtml+0x170>
mov    (%rsp),%rdi
test   %rdi,%rdi
je     132d <addtexttohtml+0x19d>
call   1030 <free@plt>
mov    %r15,%rdi
call   1040 <fclose@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    %r12,%rdi
call   1040 <fclose@plt>
lea    0x10(%rsp),%rdi
mov    %r13,%rsi
call   1080 <rename@plt>
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2c78(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@__const.addtexttohtml.tmpname = [13 x i8] c"purejunk.tmp\00"
@.str = [2 x i8] c"r\00"
@.str.1 = [2 x i8] c"w\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [9 x i8] c"</body>\0A\00"
@.str.3 = [3 x i8] c"%s\00"
@.str.4 = [14 x i8] c"\0A\0A\0A</body>\0A\0A\0A\00"
define void @addtexttohtml(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i64
%7 = alloca i8*
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca i32*
%11 = alloca [13 x i8]
store i8* %0, i8** %3
store i8* %1, i8** %4
store i64 0, i64* %6
store i8* null, i8** %7
%12 = bitcast [13 x i8]* %11 to i8*
%13 = load i8*, i8** %4
%14 = call i32* @fopen(i8* %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %14, i32** %8
%15 = getelementptr inbounds [13 x i8], [13 x i8]* %11, i64 0, i64 0
%16 = call i32* @fopen(i8* %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %16, i32** %9
%17 = load i8*, i8** %3
%18 = call i32* @fopen(i8* %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %18, i32** %10
%19 = load i32*, i32** %8
%20 = icmp eq i32* %19, null
br i1 %20, label %21, label %24
21: ; preds = %2
%22 = load i32, i32* @EXIT_FAILURE
%23 = call i32 @exit(i32 %22)
unreachable
24: ; preds = %2
%25 = load i32*, i32** %9
%26 = icmp eq i32* %25, null
br i1 %26, label %27, label %30
27: ; preds = %24
%28 = load i32, i32* @EXIT_FAILURE
%29 = call i32 @exit(i32 %28)
unreachable
30: ; preds = %24
%31 = load i32*, i32** %10
%32 = icmp eq i32* %31, null
br i1 %32, label %33, label %36
33: ; preds = %30
%34 = load i32, i32* @EXIT_FAILURE
%35 = call i32 @exit(i32 %34)
unreachable
36: ; preds = %30
br label %37
37: ; preds = %46, %36
%38 = load i32*, i32** %8
%39 = call i32 @getline(i8** %7, i64* %6, i32* %38)
store i32 %39, i32* %5
%40 = icmp ne i32 %39, -1
br i1 %40, label %41, label %50
41: ; preds = %37
%42 = load i8*, i8** %7
%43 = call i64 @strcmp(i8* %42, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
%44 = icmp eq i64 %43, 0
br i1 %44, label %45, label %46
45: ; preds = %41
br label %50
46: ; preds = %41
%47 = load i32*, i32** %9
%48 = load i8*, i8** %7
%49 = call i32 (i32*, i8*, ...) @fprintf(i32* %47, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %48)
br label %37
50: ; preds = %45, %37
br label %51
51: ; preds = %55, %50
%52 = load i32*, i32** %10
%53 = call i32 @getline(i8** %7, i64* %6, i32* %52)
store i32 %53, i32* %5
%54 = icmp ne i32 %53, -1
br i1 %54, label %55, label %59
55: ; preds = %51
%56 = load i32*, i32** %9
%57 = load i8*, i8** %7
%58 = call i32 (i32*, i8*, ...) @fprintf(i32* %56, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %57)
br label %51
59: ; preds = %51
%60 = load i32*, i32** %9
%61 = call i32 (i32*, i8*, ...) @fprintf(i32* %60, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0))
br label %62
62: ; preds = %66, %59
%63 = load i32*, i32** %8
%64 = call i32 @getline(i8** %7, i64* %6, i32* %63)
store i32 %64, i32* %5
%65 = icmp ne i32 %64, -1
br i1 %65, label %66, label %70
66: ; preds = %62
%67 = load i32*, i32** %9
%68 = load i8*, i8** %7
%69 = call i32 (i32*, i8*, ...) @fprintf(i32* %67, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %68)
br label %62
70: ; preds = %62
%71 = load i8*, i8** %7
%72 = icmp ne i8* %71, null
br i1 %72, label %73, label %76
73: ; preds = %70
%74 = load i8*, i8** %7
%75 = call i32 @free(i8* %74)
br label %76
76: ; preds = %73, %70
%77 = load i32*, i32** %8
%78 = call i32 @fclose(i32* %77)
%79 = load i32*, i32** %9
%80 = call i32 @fclose(i32* %79)
%81 = load i32*, i32** %10
%82 = call i32 @fclose(i32* %81)
%83 = getelementptr inbounds [13 x i8], [13 x i8]* %11, i64 0, i64 0
%84 = load i8*, i8** %4
%85 = call i32 @rename(i8* %83, i8* %84)
ret void
}

LLVM IR (-O2):
@__const.addtexttohtml.tmpname = [13 x i8] c"purejunk.tmp\00"
@.str = [2 x i8] c"r\00"
@.str.1 = [2 x i8] c"w\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [9 x i8] c"</body>\0A\00"
@.str.4 = [14 x i8] c"\0A\0A\0A</body>\0A\0A\0A\00"
define void @addtexttohtml(i8* nocapture %0, i8* nocapture %1) {
%3 = alloca i64
%4 = alloca i8*
%5 = alloca [13 x i8]
%6 = bitcast i64* %3 to i8*
store i64 0, i64* %3
%7 = bitcast i8** %4 to i8*
store i8* null, i8** %4
%8 = getelementptr inbounds [13 x i8], [13 x i8]* %5, i64 0, i64 0
%9 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%10 = call i32* @fopen(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%11 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%12 = icmp eq i32* %9, null
br i1 %12, label %13, label %16
13: ; preds = %2
%14 = load i32, i32* @EXIT_FAILURE
%15 = tail call i32 @exit(i32 %14)
unreachable
16: ; preds = %2
%17 = icmp eq i32* %10, null
br i1 %17, label %18, label %21
18: ; preds = %16
%19 = load i32, i32* @EXIT_FAILURE
%20 = tail call i32 @exit(i32 %19)
unreachable
21: ; preds = %16
%22 = icmp eq i32* %11, null
br i1 %22, label %26, label %23
23: ; preds = %21
%24 = call i32 @getline(i8** %4, i64* %3, i32* %9)
%25 = icmp eq i32 %24, -1
br i1 %25, label %38, label %29
26: ; preds = %21
%27 = load i32, i32* @EXIT_FAILURE
%28 = tail call i32 @exit(i32 %27)
unreachable
29: ; preds = %23, %33
%30 = load i8*, i8** %4
%31 = call i64 @strcmp(i8* %30, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
%32 = icmp eq i64 %31, 0
br i1 %32, label %38, label %33
33: ; preds = %29
%34 = load i8*, i8** %4
%35 = call i32 @fputs(i8* %34, i32* %10)
%36 = call i32 @getline(i8** %4, i64* %3, i32* %9)
%37 = icmp eq i32 %36, -1
br i1 %37, label %38, label %29
38: ; preds = %33, %29, %23
%39 = call i32 @getline(i8** %4, i64* %3, i32* %11)
%40 = icmp eq i32 %39, -1
br i1 %40, label %46, label %41
41: ; preds = %38, %41
%42 = load i8*, i8** %4
%43 = call i32 @fputs(i8* %42, i32* %10)
%44 = call i32 @getline(i8** %4, i64* %3, i32* %11)
%45 = icmp eq i32 %44, -1
br i1 %45, label %46, label %41
46: ; preds = %41, %38
%47 = call i64 @fwrite(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0), i64 13, i64 1, i32* %10)
%48 = call i32 @getline(i8** %4, i64* %3, i32* %9)
%49 = icmp eq i32 %48, -1
br i1 %49, label %55, label %50
50: ; preds = %46, %50
%51 = load i8*, i8** %4
%52 = call i32 @fputs(i8* %51, i32* %10)
%53 = call i32 @getline(i8** %4, i64* %3, i32* %9)
%54 = icmp eq i32 %53, -1
br i1 %54, label %55, label %50
55: ; preds = %50, %46
%56 = load i8*, i8** %4
%57 = icmp eq i8* %56, null
br i1 %57, label %60, label %58
58: ; preds = %55
%59 = call i32 @free(i8* %56)
br label %60
60: ; preds = %58, %55
%61 = call i32 @fclose(i32* %9)
%62 = call i32 @fclose(i32* %10)
%63 = call i32 @fclose(i32* %11)
%64 = call i32 @rename(i8* %8, i8* %1)
ret void
}