#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 */
#define ENOTSUP 128
int errno;
int /*<<< orphan*/ getpid();
int kill(int /*<<< orphan*/, int);
int pthread_kill(int /*<<< orphan*/, int);
int /*<<< orphan*/ pthread_self();
int raise(int sig) {
  int error = pthread_kill(pthread_self(), sig);
  switch (error) {
  case 0:
    return 0;
  case ENOTSUP:
    return kill(getpid(), sig);
  default:
    errno = error;
    return -1;
  }
}


x86 assembly (clang, -O0):
<raise>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
xor    %eax,%eax
call   1060 <pthread_self@plt>
mov    %eax,%edi
mov    -0x8(%rbp),%esi
call   1040 <pthread_kill@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
test   %eax,%eax
je     1185 <raise+0x45>
jmp    1172 <raise+0x32>
mov    -0x10(%rbp),%eax
sub    $0x80,%eax
je     1191 <raise+0x51>
jmp    11aa <raise+0x6a>
movl   $0x0,-0x4(%rbp)
jmp    11bd <raise+0x7d>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,%edi
mov    -0x8(%rbp),%esi
call   1050 <kill@plt>
mov    %eax,-0x4(%rbp)
jmp    11bd <raise+0x7d>
mov    -0xc(%rbp),%ecx
mov    0x2e2c(%rip),%rax
mov    %ecx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<raise>:
push   %rbx
mov    %edi,%ebx
xor    %eax,%eax
call   1060 <pthread_self@plt>
mov    %eax,%edi
mov    %ebx,%esi
call   1040 <pthread_kill@plt>
test   %eax,%eax
je     117d <raise+0x3d>
cmp    $0x80,%eax
jne    116f <raise+0x2f>
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %eax,%edi
mov    %ebx,%esi
pop    %rbx
jmp    1050 <kill@plt>
mov    0x2e6a(%rip),%rcx
mov    %eax,(%rcx)
mov    $0xffffffff,%eax
pop    %rbx
ret

LLVM IR (-O0):
@errno = global i32 0
define i32 @raise(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %3
%5 = call i32 (...) @pthread_self()
%6 = load i32, i32* %3
%7 = call i32 @pthread_kill(i32 %5, i32 %6)
store i32 %7, i32* %4
%8 = load i32, i32* %4
switch i32 %8, label %14 [
i32 0, label %9
i32 128, label %10
]
9: ; preds = %1
store i32 0, i32* %2
br label %16
10: ; preds = %1
%11 = call i32 (...) @getpid()
%12 = load i32, i32* %3
%13 = call i32 @kill(i32 %11, i32 %12)
store i32 %13, i32* %2
br label %16
14: ; preds = %1
%15 = load i32, i32* %4
store i32 %15, i32* @errno
store i32 -1, i32* %2
br label %16
16: ; preds = %14, %10, %9
%17 = load i32, i32* %2
ret i32 %17
}

LLVM IR (-O2):
@errno = global i32 0
define i32 @raise(i32 %0) {
%2 = tail call i32 (...) @pthread_self()
%3 = tail call i32 @pthread_kill(i32 %2, i32 %0)
switch i32 %3, label %7 [
i32 0, label %8
i32 128, label %4
]
4: ; preds = %1
%5 = tail call i32 (...) @getpid()
%6 = tail call i32 @kill(i32 %5, i32 %0)
br label %8
7: ; preds = %1
store i32 %3, i32* @errno
br label %8
8: ; preds = %1, %7, %4
%9 = phi i32 [ -1, %7 ], [ %6, %4 ], [ %3, %1 ]
ret i32 %9
}