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

/* Variables and functions */
scalar_t__ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
char *getenv(char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ stderr;
void handle_error(char *message) {
  fprintf(stderr, "Something went wrong! Error details:\n\n");
  if (errno) {
    perror(message);
  } else {
    printf("%s.\n", message);
  }
  fprintf(stderr, "\n");
  char buf[1024];
  char *errorfile = getenv("POSEIDON_ERRORFILE");
  if (errorfile) {
    FILE *fr = fopen(errorfile, "r");
    if (fr) {
      while (fgets(buf, sizeof(buf), fr) != NULL) {
        fprintf(stderr, "%s", buf);
      }
      fclose(fr);
    }
  }
  fprintf(stderr, "\n");
  exit(200);
}


x86 assembly (clang, -O0):
<handle_error>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    %rdi,-0x8(%rbp)
mov    0x2e4a(%rip),%rax
mov    (%rax),%edi
lea    0xe61(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    0x2e2b(%rip),%rax
cmpq   $0x0,(%rax)
je     11c5 <handle_error+0x45>
mov    -0x8(%rbp),%rdi
call   1090 <perror@plt>
jmp    11d5 <handle_error+0x55>
mov    -0x8(%rbp),%rsi
lea    0xe57(%rip),%rdi
call   1050 <printf@plt>
mov    0x2e04(%rip),%rax
mov    (%rax),%edi
lea    0xe40(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
lea    0xe39(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x418(%rbp)
cmpq   $0x0,-0x418(%rbp)
je     1290 <handle_error+0x110>
mov    -0x418(%rbp),%rdi
lea    0xe24(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x420(%rbp)
cmpq   $0x0,-0x420(%rbp)
je     128b <handle_error+0x10b>
jmp    123a <handle_error+0xba>
lea    -0x410(%rbp),%rdi
mov    -0x420(%rbp),%rdx
mov    $0x400,%esi
call   1060 <fgets@plt>
cmp    $0x0,%rax
je     127f <handle_error+0xff>
mov    0x2d7d(%rip),%rax
mov    (%rax),%edi
lea    -0x410(%rbp),%rdx
lea    0xdce(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
jmp    123a <handle_error+0xba>
mov    -0x420(%rbp),%rdi
call   1040 <fclose@plt>
jmp    1290 <handle_error+0x110>
mov    0x2d49(%rip),%rax
mov    (%rax),%edi
lea    0xd85(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    $0xc8,%edi
call   10a0 <exit@plt>

x86 assembly (clang, -O2):
<handle_error>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x408,%rsp
mov    %rdi,%rbx
mov    0x2e48(%rip),%r12
mov    (%r12),%edi
lea    0xe5d(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    0x2e27(%rip),%rax
cmpq   $0x0,(%rax)
je     126a <handle_error+0xea>
mov    %rbx,%rdi
call   1090 <perror@plt>
mov    (%r12),%edi
lea    0xe57(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
lea    0xe50(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     124e <handle_error+0xce>
lea    0xe52(%rip),%rsi
mov    %rax,%rdi
call   1080 <fopen@plt>
test   %rax,%rax
je     124e <handle_error+0xce>
mov    %rax,%r15
mov    %rsp,%rdi
mov    $0x400,%esi
mov    %rax,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     1246 <handle_error+0xc6>
lea    0xe28(%rip),%r14
mov    %rsp,%rbx
nopl   0x0(%rax)
mov    (%r12),%edi
mov    %r14,%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    %rbx,%rdi
mov    $0x400,%esi
mov    %r15,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
jne    1220 <handle_error+0xa0>
mov    %r15,%rdi
call   1040 <fclose@plt>
mov    (%r12),%edi
lea    0xdcc(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    $0xc8,%edi
call   10a0 <exit@plt>
lea    0xdb6(%rip),%rdi
mov    %rbx,%rsi
call   1050 <printf@plt>
jmp    11c3 <handle_error+0x43>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [39 x i8] c"Something went wrong! Error details:\0A\0A\00"
@errno = global i64 0
@.str.1 = [5 x i8] c"%s.\0A\00"
@.str.2 = [2 x i8] c"\0A\00"
@.str.3 = [19 x i8] c"POSEIDON_ERRORFILE\00"
@.str.4 = [2 x i8] c"r\00"
@.str.5 = [3 x i8] c"%s\00"
define void @handle_error(i8* %0) {
%2 = alloca i8*
%3 = alloca [1024 x i8]
%4 = alloca i8*
%5 = alloca i32*
store i8* %0, i8** %2
%6 = load i32, i32* @stderr
%7 = call i32 (i32, i8*, ...) @fprintf(i32 %6, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
%8 = load i64, i64* @errno
%9 = icmp ne i64 %8, 0
br i1 %9, label %10, label %13
10: ; preds = %1
%11 = load i8*, i8** %2
%12 = call i32 @perror(i8* %11)
br label %16
13: ; preds = %1
%14 = load i8*, i8** %2
%15 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %14)
br label %16
16: ; preds = %13, %10
%17 = load i32, i32* @stderr
%18 = call i32 (i32, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%19 = call i8* @getenv(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0))
store i8* %19, i8** %4
%20 = load i8*, i8** %4
%21 = icmp ne i8* %20, null
br i1 %21, label %22, label %41
22: ; preds = %16
%23 = load i8*, i8** %4
%24 = call i32* @fopen(i8* %23, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32* %24, i32** %5
%25 = load i32*, i32** %5
%26 = icmp ne i32* %25, null
br i1 %26, label %27, label %40
27: ; preds = %22
br label %28
28: ; preds = %33, %27
%29 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%30 = load i32*, i32** %5
%31 = call i32* @fgets(i8* %29, i32 1024, i32* %30)
%32 = icmp ne i32* %31, null
br i1 %32, label %33, label %37
33: ; preds = %28
%34 = load i32, i32* @stderr
%35 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%36 = call i32 (i32, i8*, ...) @fprintf(i32 %34, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i8* %35)
br label %28
37: ; preds = %28
%38 = load i32*, i32** %5
%39 = call i32 @fclose(i32* %38)
br label %40
40: ; preds = %37, %22
br label %41
41: ; preds = %40, %16
%42 = load i32, i32* @stderr
%43 = call i32 (i32, i8*, ...) @fprintf(i32 %42, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%44 = call i32 @exit(i32 200)
unreachable
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [39 x i8] c"Something went wrong! Error details:\0A\0A\00"
@errno = global i64 0
@.str.1 = [5 x i8] c"%s.\0A\00"
@.str.2 = [2 x i8] c"\0A\00"
@.str.3 = [19 x i8] c"POSEIDON_ERRORFILE\00"
@.str.4 = [2 x i8] c"r\00"
@.str.5 = [3 x i8] c"%s\00"
define void @handle_error(i8* %0) {
%2 = alloca [1024 x i8]
%3 = load i32, i32* @stderr
%4 = tail call i32 (i32, i8*, ...) @fprintf(i32 %3, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
%5 = load i64, i64* @errno
%6 = icmp eq i64 %5, 0
br i1 %6, label %9, label %7
7: ; preds = %1
%8 = tail call i32 @perror(i8* %0)
br label %11
9: ; preds = %1
%10 = tail call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %11
11: ; preds = %9, %7
%12 = load i32, i32* @stderr
%13 = tail call i32 (i32, i8*, ...) @fprintf(i32 %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%14 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%15 = tail call i8* @getenv(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0))
%16 = icmp eq i8* %15, null
br i1 %16, label %30, label %17
17: ; preds = %11
%18 = tail call i32* @fopen(i8* %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%19 = icmp eq i32* %18, null
br i1 %19, label %30, label %20
20: ; preds = %17
%21 = call i32* @fgets(i8* %14, i32 1024, i32* %18)
%22 = icmp eq i32* %21, null
br i1 %22, label %28, label %23
23: ; preds = %20, %23
%24 = load i32, i32* @stderr
%25 = call i32 (i32, i8*, ...) @fprintf(i32 %24, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i8* %14)
%26 = call i32* @fgets(i8* %14, i32 1024, i32* %18)
%27 = icmp eq i32* %26, null
br i1 %27, label %28, label %23
28: ; preds = %23, %20
%29 = call i32 @fclose(i32* %18)
br label %30
30: ; preds = %17, %28, %11
%31 = load i32, i32* @stderr
%32 = call i32 (i32, i8*, ...) @fprintf(i32 %31, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%33 = call i32 @exit(i32 200)
unreachable
}