#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 */

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, ...);
int /*<<< orphan*/ perror(int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
void handle_error_code(char *msg, int err) {
  if (err == 0) {
    fprintf(stderr, "[ERROR] %s\n", msg);
    err = -1;
  } else {
    fprintf(stderr, "[ERROR] %s with error code %d\n", msg, err);
  }
  perror(NULL);
  exit(err);
}


x86 assembly (clang, -O0):
<handle_error_code>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jne    1170 <handle_error_code+0x40>
mov    0x2e90(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xea3(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
movl   $0xffffffff,-0xc(%rbp)
jmp    118e <handle_error_code+0x5e>
mov    0x2e69(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
mov    -0xc(%rbp),%ecx
lea    0xe85(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1040 <perror@plt>
mov    -0xc(%rbp),%edi
call   1050 <exit@plt>

x86 assembly (clang, -O2):
<handle_error_code>:
push   %rbx
mov    %rdi,%rdx
mov    0x2ea5(%rip),%rax
mov    (%rax),%edi
test   %esi,%esi
jne    1156 <handle_error_code+0x26>
lea    0xeb8(%rip),%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    $0xffffffff,%ebx
jmp    1168 <handle_error_code+0x38>
mov    %esi,%ebx
lea    0xead(%rip),%rsi
mov    %ebx,%ecx
xor    %eax,%eax
call   1030 <fprintf@plt>
xor    %edi,%edi
call   1040 <perror@plt>
mov    %ebx,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [12 x i8] c"[ERROR] %s\0A\00"
@.str.1 = [31 x i8] c"[ERROR] %s with error code %d\0A\00"
define void @handle_error_code(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
%5 = load i32, i32* %4
%6 = icmp eq i32 %5, 0
br i1 %6, label %7, label %11
7: ; preds = %2
%8 = load i32, i32* @stderr
%9 = load i8*, i8** %3
%10 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %8, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* %9)
store i32 -1, i32* %4
br label %16
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = load i8*, i8** %3
%14 = load i32, i32* %4
%15 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %12, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i8* %13, i32 %14)
br label %16
16: ; preds = %11, %7
%17 = call i32 @perror(i32* null)
%18 = load i32, i32* %4
%19 = call i32 @exit(i32 %18)
unreachable
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [12 x i8] c"[ERROR] %s\0A\00"
@.str.1 = [31 x i8] c"[ERROR] %s with error code %d\0A\00"
define void @handle_error_code(i8* %0, i32 %1) {
%3 = icmp eq i32 %1, 0
%4 = load i32, i32* @stderr
br i1 %3, label %5, label %7
5: ; preds = %2
%6 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %4, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %9
7: ; preds = %2
%8 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %4, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i8* %0, i32 %1)
br label %9
9: ; preds = %7, %5
%10 = phi i32 [ -1, %5 ], [ %1, %7 ]
%11 = tail call i32 @perror(i32* null)
%12 = tail call i32 @exit(i32 %10)
unreachable
}