#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 BUFSIZ;
char *append(char *, char const *);
char *basename(char *);
int /*<<< orphan*/ err(int, char *, char const *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ ferror(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
scalar_t__ fprintf(int /*<<< orphan*/ *, char *);
size_t fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(char *);
scalar_t__ fwrite(char *, int, size_t, int /*<<< orphan*/ *);
char *plandir();
char *strdup(char const *);
void add(const char *pathname, const char *planname) {
  FILE *original, *plan, *status;
  char *path;
  char buf[BUFSIZ];
  size_t got;
  if (!(original = fopen(pathname, "r")))
    err(1, "could not open input file '%s'", pathname);
  path = append(plandir(), "/");
  if (planname) {
    append(path, planname);
  } else {
    char *tmp = strdup(pathname);
    path = append(path, basename(tmp));
    free(tmp);
  }
  if (!(plan = fopen(path, "w")))
    err(1, "could not create plan file '%s'", path);
  while ((got = fread(buf, 1, sizeof buf, original)) > 0)
    if (fwrite(buf, 1, got, plan) == 0)
      err(1, "could not write to plan file '%s'", path);
  if (ferror(original))
    err(1, "could not read from input file '%s'", pathname);
  fclose(plan);
  fclose(original);
  path = append(path, ".status");
  if (!(status = fopen(path, "w")))
    err(1, "could not create plan status file '%s'", path);
  if (fprintf(status, "1") < 0)
    err(1, "could not write to plan status file '%s'", path);
  fclose(status);
  free(path);
}


x86 assembly (clang, -O0):
<add>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e09(%rip),%rax
mov    (%rax),%eax
mov    %rax,-0x60(%rbp)
mov    %rsp,%rcx
mov    %rcx,-0x38(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x58(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x40(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xdf5(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    1233 <add+0x73>
mov    -0x8(%rbp),%rdx
mov    $0x1,%edi
lea    0xdd4(%rip),%rsi
call   10b0 <err@plt>
mov    $0x0,%al
call   1070 <plandir@plt>
mov    %rax,%rdi
lea    0xddd(%rip),%rsi
call   1040 <append@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     126a <add+0xaa>
mov    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <append@plt>
jmp    12a1 <add+0xe1>
mov    -0x8(%rbp),%rdi
call   10e0 <strdup@plt>
mov    %rax,-0x50(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x68(%rbp)
mov    -0x50(%rbp),%rdi
call   10a0 <basename@plt>
mov    -0x68(%rbp),%rdi
mov    %rax,%rsi
call   1040 <append@plt>
mov    %rax,-0x30(%rbp)
mov    -0x50(%rbp),%rdi
call   1030 <free@plt>
mov    -0x30(%rbp),%rdi
lea    0xd77(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    12d4 <add+0x114>
mov    -0x30(%rbp),%rdx
mov    $0x1,%edi
lea    0xd56(%rip),%rsi
call   10b0 <err@plt>
jmp    12d9 <add+0x119>
mov    -0x58(%rbp),%rdi
mov    -0x60(%rbp),%rax
mov    %eax,%edx
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
call   1060 <fread@plt>
mov    %rax,-0x48(%rbp)
cmp    $0x0,%rax
jbe    1339 <add+0x179>
mov    -0x58(%rbp),%rdi
mov    -0x48(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    $0x1,%esi
call   10d0 <fwrite@plt>
cmp    $0x0,%rax
jne    1334 <add+0x174>
mov    -0x30(%rbp),%rdx
mov    $0x1,%edi
lea    0xd16(%rip),%rsi
call   10b0 <err@plt>
jmp    12d9 <add+0x119>
mov    -0x18(%rbp),%rdi
call   1050 <ferror@plt>
cmp    $0x0,%rax
je     1361 <add+0x1a1>
mov    -0x8(%rbp),%rdx
mov    $0x1,%edi
lea    0xd0b(%rip),%rsi
call   10b0 <err@plt>
mov    -0x20(%rbp),%rdi
call   1080 <fclose@plt>
mov    -0x18(%rbp),%rdi
call   1080 <fclose@plt>
mov    -0x30(%rbp),%rdi
lea    0xd0d(%rip),%rsi
call   1040 <append@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
lea    0xc91(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    13ba <add+0x1fa>
mov    -0x30(%rbp),%rdx
mov    $0x1,%edi
lea    0xcde(%rip),%rsi
call   10b0 <err@plt>
mov    -0x28(%rbp),%rdi
lea    0xcf5(%rip),%rsi
call   1090 <fprintf@plt>
cmp    $0x0,%rax
jge    13e9 <add+0x229>
mov    -0x30(%rbp),%rdx
mov    $0x1,%edi
lea    0xcd8(%rip),%rsi
call   10b0 <err@plt>
mov    -0x28(%rbp),%rdi
call   1080 <fclose@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x38(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<add>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    0x2e08(%rip),%rax
mov    (%rax),%r15d
mov    %rsp,%rbx
lea    0xf(%r15),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
lea    0xe0d(%rip),%rsi
mov    %rdi,-0x30(%rbp)
call   10c0 <fopen@plt>
mov    %rax,%r12
test   %rax,%rax
jne    1219 <add+0x59>
lea    0xdf7(%rip),%rsi
mov    $0x1,%edi
mov    -0x30(%rbp),%rdx
call   10b0 <err@plt>
xor    %eax,%eax
call   1070 <plandir@plt>
lea    0xdfa(%rip),%rsi
mov    %rax,%rdi
call   1040 <append@plt>
mov    %rax,%r13
test   %r14,%r14
je     1244 <add+0x84>
mov    %r13,%rdi
mov    %r14,%rsi
call   1040 <append@plt>
jmp    126e <add+0xae>
mov    -0x30(%rbp),%rdi
call   10e0 <strdup@plt>
mov    %rax,%r14
mov    %rax,%rdi
call   10a0 <basename@plt>
mov    %r13,%rdi
mov    %rax,%rsi
call   1040 <append@plt>
mov    %rax,%r13
mov    %r14,%rdi
call   1030 <free@plt>
lea    0xdae(%rip),%rsi
mov    %r13,%rdi
call   10c0 <fopen@plt>
mov    %rax,%r14
test   %rax,%rax
jne    1299 <add+0xd9>
lea    0xd99(%rip),%rsi
mov    $0x1,%edi
mov    %r13,%rdx
call   10b0 <err@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
mov    %r15d,%edx
mov    %r12,%rcx
call   1060 <fread@plt>
test   %rax,%rax
je     12d7 <add+0x117>
mov    %rbx,%rdi
mov    $0x1,%esi
mov    %rax,%rdx
mov    %r14,%rcx
call   10d0 <fwrite@plt>
test   %rax,%rax
jne    1299 <add+0xd9>
mov    $0x1,%edi
lea    0xd70(%rip),%rsi
jmp    1291 <add+0xd1>
mov    %r12,%rdi
call   1050 <ferror@plt>
test   %rax,%rax
je     12f9 <add+0x139>
lea    0xd7c(%rip),%rsi
mov    $0x1,%edi
mov    -0x30(%rbp),%rdx
call   10b0 <err@plt>
mov    %r14,%rdi
call   1080 <fclose@plt>
mov    %r12,%rdi
call   1080 <fclose@plt>
lea    0xd7b(%rip),%rsi
mov    %r13,%rdi
call   1040 <append@plt>
mov    %rax,%r14
lea    0xd01(%rip),%rsi
mov    %rax,%rdi
call   10c0 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1346 <add+0x186>
lea    0xd5a(%rip),%rsi
mov    $0x1,%edi
mov    %r14,%rdx
call   10b0 <err@plt>
lea    0xd6d(%rip),%rsi
mov    %rbx,%rdi
call   1090 <fprintf@plt>
test   %rax,%rax
jns    136e <add+0x1ae>
lea    0xd5b(%rip),%rsi
mov    $0x1,%edi
mov    %r14,%rdx
call   10b0 <err@plt>
mov    %rbx,%rdi
call   1080 <fclose@plt>
mov    %r14,%rdi
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <free@plt>

LLVM IR (-O0):
@BUFSIZ = global i32 0
@.str = [2 x i8] c"r\00"
@.str.1 = [31 x i8] c"could not open input file '%s'\00"
@.str.2 = [2 x i8] c"/\00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [32 x i8] c"could not create plan file '%s'\00"
@.str.5 = [34 x i8] c"could not write to plan file '%s'\00"
@.str.6 = [36 x i8] c"could not read from input file '%s'\00"
@.str.7 = [8 x i8] c".status\00"
@.str.8 = [39 x i8] c"could not create plan status file '%s'\00"
@.str.9 = [2 x i8] c"1\00"
@.str.10 = [41 x i8] c"could not write to plan status file '%s'\00"
define void @add(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i64
%11 = alloca i64
%12 = alloca i8*
store i8* %0, i8** %3
store i8* %1, i8** %4
%13 = load i32, i32* @BUFSIZ
%14 = zext i32 %13 to i64
%15 = call i8* @llvm.stacksave()
store i8* %15, i8** %9
%16 = alloca i8, i64 %14
store i64 %14, i64* %10
%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** %5
%19 = icmp ne i32* %18, null
br i1 %19, label %23, label %20
20: ; preds = %2
%21 = load i8*, i8** %3
%22 = call i32 @err(i32 1, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i8* %21)
br label %23
23: ; preds = %20, %2
%24 = call i8* (...) @plandir()
%25 = call i8* @append(i8* %24, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i8* %25, i8** %8
%26 = load i8*, i8** %4
%27 = icmp ne i8* %26, null
br i1 %27, label %28, label %32
28: ; preds = %23
%29 = load i8*, i8** %8
%30 = load i8*, i8** %4
%31 = call i8* @append(i8* %29, i8* %30)
br label %41
32: ; preds = %23
%33 = load i8*, i8** %3
%34 = call i8* @strdup(i8* %33)
store i8* %34, i8** %12
%35 = load i8*, i8** %8
%36 = load i8*, i8** %12
%37 = call i8* @basename(i8* %36)
%38 = call i8* @append(i8* %35, i8* %37)
store i8* %38, i8** %8
%39 = load i8*, i8** %12
%40 = call i32 @free(i8* %39)
br label %41
41: ; preds = %32, %28
%42 = load i8*, i8** %8
%43 = call i32* @fopen(i8* %42, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %43, i32** %6
%44 = icmp ne i32* %43, null
br i1 %44, label %48, label %45
45: ; preds = %41
%46 = load i8*, i8** %8
%47 = call i32 @err(i32 1, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0), i8* %46)
br label %48
48: ; preds = %45, %41
br label %49
49: ; preds = %62, %48
%50 = trunc i64 %14 to i32
%51 = load i32*, i32** %5
%52 = call i64 @fread(i8* %16, i32 1, i32 %50, i32* %51)
store i64 %52, i64* %11
%53 = icmp ugt i64 %52, 0
br i1 %53, label %54, label %63
54: ; preds = %49
%55 = load i64, i64* %11
%56 = load i32*, i32** %6
%57 = call i64 @fwrite(i8* %16, i32 1, i64 %55, i32* %56)
%58 = icmp eq i64 %57, 0
br i1 %58, label %59, label %62
59: ; preds = %54
%60 = load i8*, i8** %8
%61 = call i32 @err(i32 1, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.5, i64 0, i64 0), i8* %60)
br label %62
62: ; preds = %59, %54
br label %49
63: ; preds = %49
%64 = load i32*, i32** %5
%65 = call i64 @ferror(i32* %64)
%66 = icmp ne i64 %65, 0
br i1 %66, label %67, label %70
67: ; preds = %63
%68 = load i8*, i8** %3
%69 = call i32 @err(i32 1, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.6, i64 0, i64 0), i8* %68)
br label %70
70: ; preds = %67, %63
%71 = load i32*, i32** %6
%72 = call i32 @fclose(i32* %71)
%73 = load i32*, i32** %5
%74 = call i32 @fclose(i32* %73)
%75 = load i8*, i8** %8
%76 = call i8* @append(i8* %75, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.7, i64 0, i64 0))
store i8* %76, i8** %8
%77 = load i8*, i8** %8
%78 = call i32* @fopen(i8* %77, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %78, i32** %7
%79 = icmp ne i32* %78, null
br i1 %79, label %83, label %80
80: ; preds = %70
%81 = load i8*, i8** %8
%82 = call i32 @err(i32 1, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.8, i64 0, i64 0), i8* %81)
br label %83
83: ; preds = %80, %70
%84 = load i32*, i32** %7
%85 = call i64 @fprintf(i32* %84, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.9, i64 0, i64 0))
%86 = icmp slt i64 %85, 0
br i1 %86, label %87, label %90
87: ; preds = %83
%88 = load i8*, i8** %8
%89 = call i32 @err(i32 1, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.10, i64 0, i64 0), i8* %88)
br label %90
90: ; preds = %87, %83
%91 = load i32*, i32** %7
%92 = call i32 @fclose(i32* %91)
%93 = load i8*, i8** %8
%94 = call i32 @free(i8* %93)
%95 = load i8*, i8** %9
ret void
}

LLVM IR (-O2):
@BUFSIZ = global i32 0
@.str = [2 x i8] c"r\00"
@.str.1 = [31 x i8] c"could not open input file '%s'\00"
@.str.2 = [2 x i8] c"/\00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [32 x i8] c"could not create plan file '%s'\00"
@.str.5 = [34 x i8] c"could not write to plan file '%s'\00"
@.str.6 = [36 x i8] c"could not read from input file '%s'\00"
@.str.7 = [8 x i8] c".status\00"
@.str.8 = [39 x i8] c"could not create plan status file '%s'\00"
@.str.9 = [2 x i8] c"1\00"
@.str.10 = [41 x i8] c"could not write to plan status file '%s'\00"
define void @add(i8* %0, i8* %1) {
%3 = load i32, i32* @BUFSIZ
%4 = zext i32 %3 to i64
%5 = alloca i8, i64 %4
%6 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i32* %6, null
br i1 %7, label %8, label %10
8: ; preds = %2
%9 = tail call i32 @err(i32 1, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %10
10: ; preds = %8, %2
%11 = tail call i8* (...) @plandir()
%12 = tail call i8* @append(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%13 = icmp eq i8* %1, null
br i1 %13, label %16, label %14
14: ; preds = %10
%15 = tail call i8* @append(i8* %12, i8* %1)
br label %21
16: ; preds = %10
%17 = tail call i8* @strdup(i8* %0)
%18 = tail call i8* @basename(i8* %17)
%19 = tail call i8* @append(i8* %12, i8* %18)
%20 = tail call i32 @free(i8* %17)
br label %21
21: ; preds = %16, %14
%22 = phi i8* [ %12, %14 ], [ %19, %16 ]
%23 = tail call i32* @fopen(i8* %22, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%24 = icmp eq i32* %23, null
br i1 %24, label %25, label %27
25: ; preds = %21
%26 = tail call i32 @err(i32 1, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0), i8* %22)
br label %27
27: ; preds = %25, %21
%28 = call i64 @fread(i8* %5, i32 1, i32 %3, i32* %6)
%29 = icmp eq i64 %28, 0
br i1 %29, label %39, label %30
30: ; preds = %27, %36
%31 = phi i64 [ %37, %36 ], [ %28, %27 ]
%32 = call i64 @fwrite(i8* %5, i32 1, i64 %31, i32* %23)
%33 = icmp eq i64 %32, 0
br i1 %33, label %34, label %36
34: ; preds = %30
%35 = tail call i32 @err(i32 1, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.5, i64 0, i64 0), i8* %22)
br label %36
36: ; preds = %34, %30
%37 = call i64 @fread(i8* %5, i32 1, i32 %3, i32* %6)
%38 = icmp eq i64 %37, 0
br i1 %38, label %39, label %30
39: ; preds = %36, %27
%40 = tail call i64 @ferror(i32* %6)
%41 = icmp eq i64 %40, 0
br i1 %41, label %44, label %42
42: ; preds = %39
%43 = tail call i32 @err(i32 1, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.6, i64 0, i64 0), i8* %0)
br label %44
44: ; preds = %42, %39
%45 = tail call i32 @fclose(i32* %23)
%46 = tail call i32 @fclose(i32* %6)
%47 = tail call i8* @append(i8* %22, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.7, i64 0, i64 0))
%48 = tail call i32* @fopen(i8* %47, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%49 = icmp eq i32* %48, null
br i1 %49, label %50, label %52
50: ; preds = %44
%51 = tail call i32 @err(i32 1, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.8, i64 0, i64 0), i8* %47)
br label %52
52: ; preds = %50, %44
%53 = tail call i64 @fprintf(i32* %48, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.9, i64 0, i64 0))
%54 = icmp slt i64 %53, 0
br i1 %54, label %55, label %57
55: ; preds = %52
%56 = tail call i32 @err(i32 1, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.10, i64 0, i64 0), i8* %47)
br label %57
57: ; preds = %55, %52
%58 = tail call i32 @fclose(i32* %48)
%59 = tail call i32 @free(i8* %47)
ret void
}