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

/* Variables and functions */
int /*<<< orphan*/ dump_to_pie(int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                               char const *);
scalar_t__ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
scalar_t__ ferror(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *, ...);
size_t fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fwrite(char *, size_t, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
char *strerror(scalar_t__);
int /*<<< orphan*/ *tmpfile();
int convert(const char *filename) {
  FILE *p, *f;
  char buffer[1024];
  size_t rsize;
  p = fopen(filename, "r");
  if (!p) {
    fprintf(stderr, "Cannot open \"%s\" for reading: %s\n", filename,
            strerror(errno));
    exit(1);
  }
  f = tmpfile();
  if (!f) {
    fprintf(stderr, "Cannot open temporary file for writing: %s\n",
            strerror(errno));
    exit(1);
  }
  dump_to_pie(f, p, filename);
  fclose(p);
  rewind(f);
  p = fopen(filename, "w");
  while (!feof(f) && !ferror(p) && !ferror(f)) {
    rsize = fread(buffer, 1, sizeof(buffer), f);
    fwrite(buffer, rsize, 1, p);
  }
  if (ferror(f))
    fprintf(stderr, "Error reading: %s\n", strerror(ferror(f)));
  if (ferror(p))
    fprintf(stderr, "Error writing: %s\n", strerror(ferror(p)));
  fclose(p);
  fclose(f);
  return 0;
}


x86 assembly (clang, -O0):
<convert>:
push   %rbp
mov    %rsp,%rbp
sub    $0x450,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe26(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    123f <convert+0x7f>
mov    0x2deb(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x434(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x430(%rbp)
mov    0x2dc9(%rip),%rax
mov    (%rax),%rdi
call   10e0 <strerror@plt>
mov    -0x434(%rbp),%edi
mov    -0x430(%rbp),%rdx
mov    %rax,%rcx
lea    0xdd4(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    $0x0,%al
call   1080 <tmpfile@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1294 <convert+0xd4>
mov    0x2d84(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x438(%rbp)
mov    0x2d6d(%rip),%rax
mov    (%rax),%rdi
call   10e0 <strerror@plt>
mov    -0x438(%rbp),%edi
mov    %rax,%rdx
lea    0xda1(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x8(%rbp),%rdx
call   1060 <dump_to_pie@plt>
mov    -0x10(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x18(%rbp),%rdi
call   1070 <rewind@plt>
mov    -0x8(%rbp),%rdi
lea    0xd8e(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%rdi
call   10a0 <feof@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x439(%rbp)
jne    131d <convert+0x15d>
mov    -0x10(%rbp),%rdi
call   1030 <ferror@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x439(%rbp)
jne    131d <convert+0x15d>
mov    -0x18(%rbp),%rdi
call   1030 <ferror@plt>
cmp    $0x0,%rax
setne  %al
xor    $0xff,%al
mov    %al,-0x439(%rbp)
mov    -0x439(%rbp),%al
test   $0x1,%al
jne    1330 <convert+0x170>
jmp    1372 <convert+0x1b2>
lea    -0x420(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
mov    $0x400,%edx
call   1040 <fread@plt>
mov    %rax,-0x428(%rbp)
lea    -0x420(%rbp),%rdi
mov    -0x428(%rbp),%rsi
mov    -0x10(%rbp),%rcx
mov    $0x1,%edx
call   10d0 <fwrite@plt>
jmp    12cb <convert+0x10b>
mov    -0x18(%rbp),%rdi
call   1030 <ferror@plt>
cmp    $0x0,%rax
je     13bc <convert+0x1fc>
mov    0x2c54(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x440(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <ferror@plt>
mov    %rax,%rdi
call   10e0 <strerror@plt>
mov    -0x440(%rbp),%edi
mov    %rax,%rdx
lea    0xc9d(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <ferror@plt>
cmp    $0x0,%rax
je     1406 <convert+0x246>
mov    0x2c0a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x444(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <ferror@plt>
mov    %rax,%rdi
call   10e0 <strerror@plt>
mov    -0x444(%rbp),%edi
mov    %rax,%rdx
lea    0xc66(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    -0x10(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x18(%rbp),%rdi
call   1050 <fclose@plt>
xor    %eax,%eax
add    $0x450,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<convert>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x408,%rsp
mov    %rdi,%r14
lea    0xe29(%rip),%rsi
call   10b0 <fopen@plt>
test   %rax,%rax
je     131b <convert+0x15b>
mov    %rax,%r15
xor    %eax,%eax
call   1080 <tmpfile@plt>
test   %rax,%rax
je     1353 <convert+0x193>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
call   1060 <dump_to_pie@plt>
mov    %r15,%rdi
call   1050 <fclose@plt>
mov    %rbx,%rdi
call   1070 <rewind@plt>
lea    0xe30(%rip),%rsi
mov    %r14,%rdi
call   10b0 <fopen@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   10a0 <feof@plt>
test   %eax,%eax
je     12bd <convert+0xfd>
mov    %rbx,%rdi
call   1030 <ferror@plt>
test   %rax,%rax
je     126c <convert+0xac>
mov    0x2d91(%rip),%rcx
mov    (%rcx),%ebp
mov    %rax,%rdi
call   10e0 <strerror@plt>
lea    0xdf2(%rip),%rsi
mov    %ebp,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    %r14,%rdi
call   1030 <ferror@plt>
test   %rax,%rax
je     129d <convert+0xdd>
mov    0x2d60(%rip),%rcx
mov    (%rcx),%ebp
mov    %rax,%rdi
call   10e0 <strerror@plt>
lea    0xdd4(%rip),%rsi
mov    %ebp,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    %r14,%rdi
call   1050 <fclose@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
xor    %eax,%eax
add    $0x408,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %rsp,%r15
mov    %r14,%rdi
call   1030 <ferror@plt>
test   %rax,%rax
jne    123b <convert+0x7b>
mov    %rbx,%rdi
call   1030 <ferror@plt>
test   %rax,%rax
jne    123b <convert+0x7b>
mov    %r15,%rdi
mov    $0x1,%esi
mov    $0x400,%edx
mov    %rbx,%rcx
call   1040 <fread@plt>
mov    %r15,%rdi
mov    %rax,%rsi
mov    $0x1,%edx
mov    %r14,%rcx
call   10d0 <fwrite@plt>
mov    %rbx,%rdi
call   10a0 <feof@plt>
test   %eax,%eax
je     12c0 <convert+0x100>
jmp    123b <convert+0x7b>
mov    0x2cbe(%rip),%rax
mov    (%rax),%ebx
mov    0x2cad(%rip),%rax
mov    (%rax),%rdi
call   10e0 <strerror@plt>
lea    0xcc8(%rip),%rsi
mov    %ebx,%edi
mov    %r14,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    0x2c86(%rip),%rax
mov    (%rax),%ebx
mov    0x2c75(%rip),%rax
mov    (%rax),%rdi
call   10e0 <strerror@plt>
lea    0xcb2(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [34 x i8] c"Cannot open \22%s\22 for reading: %s\0A\00"
@errno = global i64 0
@.str.2 = [44 x i8] c"Cannot open temporary file for writing: %s\0A\00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [19 x i8] c"Error reading: %s\0A\00"
@.str.5 = [19 x i8] c"Error writing: %s\0A\00"
define i32 @convert(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca [1024 x i8]
%6 = alloca i64
store i8* %0, i8** %2
%7 = load i8*, i8** %2
%8 = call i32* @fopen(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %8, i32** %3
%9 = load i32*, i32** %3
%10 = icmp ne i32* %9, null
br i1 %10, label %18, label %11
11: ; preds = %1
%12 = load i32, i32* @stderr
%13 = load i8*, i8** %2
%14 = load i64, i64* @errno
%15 = call i8* @strerror(i64 %14)
%16 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %12, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i8* %13, i8* %15)
%17 = call i32 @exit(i32 1)
unreachable
18: ; preds = %1
%19 = call i32* (...) @tmpfile()
store i32* %19, i32** %4
%20 = load i32*, i32** %4
%21 = icmp ne i32* %20, null
br i1 %21, label %28, label %22
22: ; preds = %18
%23 = load i32, i32* @stderr
%24 = load i64, i64* @errno
%25 = call i8* @strerror(i64 %24)
%26 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %23, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.2, i64 0, i64 0), i8* %25)
%27 = call i32 @exit(i32 1)
unreachable
28: ; preds = %18
%29 = load i32*, i32** %4
%30 = load i32*, i32** %3
%31 = load i8*, i8** %2
%32 = call i32 @dump_to_pie(i32* %29, i32* %30, i8* %31)
%33 = load i32*, i32** %3
%34 = call i32 @fclose(i32* %33)
%35 = load i32*, i32** %4
%36 = call i32 @rewind(i32* %35)
%37 = load i8*, i8** %2
%38 = call i32* @fopen(i8* %37, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %38, i32** %3
br label %39
39: ; preds = %54, %28
%40 = load i32*, i32** %4
%41 = call i32 @feof(i32* %40)
%42 = icmp ne i32 %41, 0
br i1 %42, label %52, label %43
43: ; preds = %39
%44 = load i32*, i32** %3
%45 = call i64 @ferror(i32* %44)
%46 = icmp ne i64 %45, 0
br i1 %46, label %52, label %47
47: ; preds = %43
%48 = load i32*, i32** %4
%49 = call i64 @ferror(i32* %48)
%50 = icmp ne i64 %49, 0
%51 = xor i1 %50, true
br label %52
52: ; preds = %47, %43, %39
%53 = phi i1 [ false, %43 ], [ false, %39 ], [ %51, %47 ]
br i1 %53, label %54, label %62
54: ; preds = %52
%55 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%56 = load i32*, i32** %4
%57 = call i64 @fread(i8* %55, i32 1, i32 1024, i32* %56)
store i64 %57, i64* %6
%58 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%59 = load i64, i64* %6
%60 = load i32*, i32** %3
%61 = call i32 @fwrite(i8* %58, i64 %59, i32 1, i32* %60)
br label %39
62: ; preds = %52
%63 = load i32*, i32** %4
%64 = call i64 @ferror(i32* %63)
%65 = icmp ne i64 %64, 0
br i1 %65, label %66, label %72
66: ; preds = %62
%67 = load i32, i32* @stderr
%68 = load i32*, i32** %4
%69 = call i64 @ferror(i32* %68)
%70 = call i8* @strerror(i64 %69)
%71 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %67, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i8* %70)
br label %72
72: ; preds = %66, %62
%73 = load i32*, i32** %3
%74 = call i64 @ferror(i32* %73)
%75 = icmp ne i64 %74, 0
br i1 %75, label %76, label %82
76: ; preds = %72
%77 = load i32, i32* @stderr
%78 = load i32*, i32** %3
%79 = call i64 @ferror(i32* %78)
%80 = call i8* @strerror(i64 %79)
%81 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %77, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0), i8* %80)
br label %82
82: ; preds = %76, %72
%83 = load i32*, i32** %3
%84 = call i32 @fclose(i32* %83)
%85 = load i32*, i32** %4
%86 = call i32 @fclose(i32* %85)
ret i32 0
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [34 x i8] c"Cannot open \22%s\22 for reading: %s\0A\00"
@errno = global i64 0
@.str.2 = [44 x i8] c"Cannot open temporary file for writing: %s\0A\00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [19 x i8] c"Error reading: %s\0A\00"
@.str.5 = [19 x i8] c"Error writing: %s\0A\00"
define i32 @convert(i8* %0) {
%2 = alloca [1024 x i8]
%3 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%4 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %12
6: ; preds = %1
%7 = load i32, i32* @stderr
%8 = load i64, i64* @errno
%9 = tail call i8* @strerror(i64 %8)
%10 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %7, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i8* %0, i8* %9)
%11 = tail call i32 @exit(i32 1)
unreachable
12: ; preds = %1
%13 = tail call i32* (...) @tmpfile()
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %21
15: ; preds = %12
%16 = load i32, i32* @stderr
%17 = load i64, i64* @errno
%18 = tail call i8* @strerror(i64 %17)
%19 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %16, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.2, i64 0, i64 0), i8* %18)
%20 = tail call i32 @exit(i32 1)
unreachable
21: ; preds = %12
%22 = tail call i32 @dump_to_pie(i32* %13, i32* %4, i8* %0)
%23 = tail call i32 @fclose(i32* %4)
%24 = tail call i32 @rewind(i32* %13)
%25 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%26 = tail call i32 @feof(i32* %13)
%27 = icmp eq i32 %26, 0
br i1 %27, label %28, label %39
28: ; preds = %21, %34
%29 = tail call i64 @ferror(i32* %25)
%30 = icmp eq i64 %29, 0
br i1 %30, label %31, label %39
31: ; preds = %28
%32 = tail call i64 @ferror(i32* %13)
%33 = icmp eq i64 %32, 0
br i1 %33, label %34, label %39
34: ; preds = %31
%35 = call i64 @fread(i8* %3, i32 1, i32 1024, i32* %13)
%36 = call i32 @fwrite(i8* %3, i64 %35, i32 1, i32* %25)
%37 = tail call i32 @feof(i32* %13)
%38 = icmp eq i32 %37, 0
br i1 %38, label %28, label %39
39: ; preds = %31, %28, %34, %21
%40 = tail call i64 @ferror(i32* %13)
%41 = icmp eq i64 %40, 0
br i1 %41, label %46, label %42
42: ; preds = %39
%43 = load i32, i32* @stderr
%44 = tail call i8* @strerror(i64 %40)
%45 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %43, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i8* %44)
br label %46
46: ; preds = %42, %39
%47 = tail call i64 @ferror(i32* %25)
%48 = icmp eq i64 %47, 0
br i1 %48, label %53, label %49
49: ; preds = %46
%50 = load i32, i32* @stderr
%51 = tail call i8* @strerror(i64 %47)
%52 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %50, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0), i8* %51)
br label %53
53: ; preds = %49, %46
%54 = tail call i32 @fclose(i32* %25)
%55 = tail call i32 @fclose(i32* %13)
ret i32 0
}