#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 scalar_t__ pthread_t;

/* Variables and functions */
int /*<<< orphan*/ det_fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ exit(int const);
scalar_t__ get_error_envvar();
int /*<<< orphan*/ pthread_kill(scalar_t__, int);
int /*<<< orphan*/ stderr;
void optionalKillOnOverflow(const int err_ret_val, pthread_t parent) {
  if (get_error_envvar()) {
    det_fprintf(stderr, "Exiting application because of buffer overflow.\n");
    if (parent)
      pthread_kill(parent, 1);
    exit(err_ret_val);
  }
}


x86 assembly (clang, -O0):
<optionalKillOnOverflow>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   1030 <get_error_envvar@plt>
cmp    $0x0,%rax
je     1196 <optionalKillOnOverflow+0x56>
mov    0x2e79(%rip),%rax
mov    (%rax),%edi
lea    0xe90(%rip),%rsi
call   1060 <det_fprintf@plt>
cmpq   $0x0,-0x10(%rbp)
je     118e <optionalKillOnOverflow+0x4e>
mov    -0x10(%rbp),%rdi
mov    $0x1,%esi
call   1040 <pthread_kill@plt>
mov    -0x4(%rbp),%edi
call   1050 <exit@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<optionalKillOnOverflow>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%ebp
xor    %eax,%eax
call   1030 <get_error_envvar@plt>
test   %rax,%rax
jne    115b <optionalKillOnOverflow+0x1b>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
mov    0x2e7e(%rip),%rax
mov    (%rax),%edi
lea    0xe95(%rip),%rsi
call   1060 <det_fprintf@plt>
test   %rbx,%rbx
je     1182 <optionalKillOnOverflow+0x42>
mov    %rbx,%rdi
mov    $0x1,%esi
call   1040 <pthread_kill@plt>
mov    %ebp,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [49 x i8] c"Exiting application because of buffer overflow.\0A\00"
define void @optionalKillOnOverflow(i32 %0, i64 %1) {
%3 = alloca i32
%4 = alloca i64
store i32 %0, i32* %3
store i64 %1, i64* %4
%5 = call i64 (...) @get_error_envvar()
%6 = icmp ne i64 %5, 0
br i1 %6, label %7, label %18
7: ; preds = %2
%8 = load i32, i32* @stderr
%9 = call i32 @det_fprintf(i32 %8, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0))
%10 = load i64, i64* %4
%11 = icmp ne i64 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %7
%13 = load i64, i64* %4
%14 = call i32 @pthread_kill(i64 %13, i32 1)
br label %15
15: ; preds = %12, %7
%16 = load i32, i32* %3
%17 = call i32 @exit(i32 %16)
unreachable
18: ; preds = %2
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [49 x i8] c"Exiting application because of buffer overflow.\0A\00"
define void @optionalKillOnOverflow(i32 %0, i64 %1) {
%3 = tail call i64 (...) @get_error_envvar()
%4 = icmp eq i64 %3, 0
br i1 %4, label %13, label %5
5: ; preds = %2
%6 = load i32, i32* @stderr
%7 = tail call i32 @det_fprintf(i32 %6, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i64 %1, 0
br i1 %8, label %11, label %9
9: ; preds = %5
%10 = tail call i32 @pthread_kill(i64 %1, i32 1)
br label %11
11: ; preds = %9, %5
%12 = tail call i32 @exit(i32 %0)
unreachable
13: ; preds = %2
ret void
}