#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 */
scalar_t__ errno;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, int, int, int,
                           char *);
int /*<<< orphan*/ stderr;
char *strerror(scalar_t__);
int handleTargaError(FILE *fh, int errorCode, const char *function,
                     size_t line) {
  char *errorMessage = NULL;
  if ((errorMessage = strerror(errno)) == NULL) {
    errorMessage = "uknown error";
  }
  fprintf(stderr, "[%s():%i] error(%i) - #%i, '%s'.\n", (char *)function,
          (int)line, errorCode, (int)errno, errorMessage);
  if (fh != NULL) {
    fclose(fh);
  }
  return -1;
}


x86 assembly (clang, -O0):
<handleTargaError>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
mov    0x2e82(%rip),%rax
mov    (%rax),%rdi
call   1050 <strerror@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    1177 <handleTargaError+0x47>
lea    0xe8d(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    0x2e62(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rax
mov    %eax,%ecx
mov    -0xc(%rbp),%r8d
mov    0x2e43(%rip),%rax
mov    (%rax),%rax
mov    %eax,%r9d
mov    -0x28(%rbp),%rax
lea    0xe67(%rip),%rsi
mov    %rax,(%rsp)
call   1040 <fprintf@plt>
cmpq   $0x0,-0x8(%rbp)
je     11c3 <handleTargaError+0x93>
mov    -0x8(%rbp),%rdi
call   1030 <fclose@plt>
mov    $0xffffffff,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<handleTargaError>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rcx,%r14
mov    %rdx,%r15
mov    %esi,%ebp
mov    %rdi,%rbx
mov    0x2e8a(%rip),%r12
mov    (%r12),%rdi
call   1050 <strerror@plt>
test   %rax,%rax
lea    0xe9f(%rip),%rcx
cmovne %rax,%rcx
mov    0x2e74(%rip),%rax
mov    (%rax),%edi
mov    (%r12),%r9d
mov    %rcx,(%rsp)
lea    0xe90(%rip),%rsi
mov    %r15,%rdx
mov    %r14d,%ecx
mov    %ebp,%r8d
call   1040 <fprintf@plt>
test   %rbx,%rbx
je     1198 <handleTargaError+0x68>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    $0xffffffff,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@errno = global i64 0
@.str = [13 x i8] c"uknown error\00"
@stderr = global i32 0
@.str.1 = [34 x i8] c"[%s():%i] error(%i) - #%i, '%s'.\0A\00"
define i32 @handleTargaError(i32* %0, i32 %1, i8* %2, i64 %3) {
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i8*
store i32* %0, i32** %5
store i32 %1, i32* %6
store i8* %2, i8** %7
store i64 %3, i64* %8
store i8* null, i8** %9
%10 = load i64, i64* @errno
%11 = call i8* @strerror(i64 %10)
store i8* %11, i8** %9
%12 = icmp eq i8* %11, null
br i1 %12, label %13, label %14
13: ; preds = %4
store i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8** %9
br label %14
14: ; preds = %13, %4
%15 = load i32, i32* @stderr
%16 = load i8*, i8** %7
%17 = load i64, i64* %8
%18 = trunc i64 %17 to i32
%19 = load i32, i32* %6
%20 = load i64, i64* @errno
%21 = trunc i64 %20 to i32
%22 = load i8*, i8** %9
%23 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i8* %16, i32 %18, i32 %19, i32 %21, i8* %22)
%24 = load i32*, i32** %5
%25 = icmp ne i32* %24, null
br i1 %25, label %26, label %29
26: ; preds = %14
%27 = load i32*, i32** %5
%28 = call i32 @fclose(i32* %27)
br label %29
29: ; preds = %26, %14
ret i32 -1
}

LLVM IR (-O2):
@errno = global i64 0
@.str = [13 x i8] c"uknown error\00"
@stderr = global i32 0
@.str.1 = [34 x i8] c"[%s():%i] error(%i) - #%i, '%s'.\0A\00"
define i32 @handleTargaError(i32* %0, i32 %1, i8* %2, i64 %3) {
%5 = load i64, i64* @errno
%6 = tail call i8* @strerror(i64 %5)
%7 = icmp eq i8* %6, null
%8 = select i1 %7, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* %6
%9 = load i32, i32* @stderr
%10 = trunc i64 %3 to i32
%11 = load i64, i64* @errno
%12 = trunc i64 %11 to i32
%13 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i8* %2, i32 %10, i32 %1, i32 %12, i8* %8)
%14 = icmp eq i32* %0, null
br i1 %14, label %17, label %15
15: ; preds = %4
%16 = tail call i32 @fclose(i32* %0)
br label %17
17: ; preds = %15, %4
ret i32 -1
}