#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 */
struct sc_error {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ die(char *, int /*<<< orphan*/);
scalar_t__ errno;
scalar_t__ sc_error_code(struct sc_error *);
int /*<<< orphan*/ sc_error_domain(struct sc_error *);
int /*<<< orphan*/ sc_error_msg(struct sc_error *);
scalar_t__ strcmp(int /*<<< orphan*/, char *);
void sc_die_on_error(struct sc_error *error) {
  if (error != NULL) {
    if (strcmp(sc_error_domain(error), "errno") == 0) {
      errno = sc_error_code(error);
      die("%s", sc_error_msg(error));
    } else {
      errno = 0;
      die("%s", sc_error_msg(error));
    }
  }
}


x86 assembly (clang, -O0):
<sc_die_on_error>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     11e4 <sc_die_on_error+0x94>
mov    -0x8(%rbp),%rdi
call   1060 <sc_error_domain@plt>
mov    %eax,%edi
lea    0xe87(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    11ba <sc_die_on_error+0x6a>
mov    -0x8(%rbp),%rdi
call   1030 <sc_error_code@plt>
mov    %rax,%rcx
mov    0x2e45(%rip),%rax
mov    %rcx,(%rax)
mov    -0x8(%rbp),%rdi
call   1050 <sc_error_msg@plt>
mov    %eax,%esi
lea    0xe56(%rip),%rdi
call   1070 <die@plt>
jmp    11df <sc_die_on_error+0x8f>
mov    0x2e1f(%rip),%rax
movq   $0x0,(%rax)
mov    -0x8(%rbp),%rdi
call   1050 <sc_error_msg@plt>
mov    %eax,%esi
lea    0xe2c(%rip),%rdi
call   1070 <die@plt>
jmp    11e4 <sc_die_on_error+0x94>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sc_die_on_error>:
test   %rdi,%rdi
je     1175 <sc_die_on_error+0x25>
push   %rbx
mov    %rdi,%rbx
call   1060 <sc_error_domain@plt>
lea    0xe9b(%rip),%rsi
mov    %eax,%edi
call   1040 <strcmp@plt>
test   %rax,%rax
je     1176 <sc_die_on_error+0x26>
xor    %eax,%eax
jmp    117e <sc_die_on_error+0x2e>
ret
mov    %rbx,%rdi
call   1030 <sc_error_code@plt>
mov    0x2e5b(%rip),%rcx
mov    %rax,(%rcx)
mov    %rbx,%rdi
call   1050 <sc_error_msg@plt>
lea    0xe6f(%rip),%rdi
mov    %eax,%esi
pop    %rbx
jmp    1070 <die@plt>

LLVM IR (-O0):
%struct.sc_error = type { i32 }
@.str = [6 x i8] c"errno\00"
@errno = global i64 0
@.str.1 = [3 x i8] c"%s\00"
define void @sc_die_on_error(%struct.sc_error* %0) {
%2 = alloca %struct.sc_error*
store %struct.sc_error* %0, %struct.sc_error** %2
%3 = load %struct.sc_error*, %struct.sc_error** %2
%4 = icmp ne %struct.sc_error* %3, null
br i1 %4, label %5, label %21
5: ; preds = %1
%6 = load %struct.sc_error*, %struct.sc_error** %2
%7 = call i32 @sc_error_domain(%struct.sc_error* %6)
%8 = call i64 @strcmp(i32 %7, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %16
10: ; preds = %5
%11 = load %struct.sc_error*, %struct.sc_error** %2
%12 = call i64 @sc_error_code(%struct.sc_error* %11)
store i64 %12, i64* @errno
%13 = load %struct.sc_error*, %struct.sc_error** %2
%14 = call i32 @sc_error_msg(%struct.sc_error* %13)
%15 = call i32 @die(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %14)
br label %20
16: ; preds = %5
store i64 0, i64* @errno
%17 = load %struct.sc_error*, %struct.sc_error** %2
%18 = call i32 @sc_error_msg(%struct.sc_error* %17)
%19 = call i32 @die(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %18)
br label %20
20: ; preds = %16, %10
br label %21
21: ; preds = %20, %1
ret void
}

LLVM IR (-O2):
%struct.sc_error = type { i32 }
@.str = [6 x i8] c"errno\00"
@errno = global i64 0
@.str.1 = [3 x i8] c"%s\00"
define void @sc_die_on_error(%struct.sc_error* %0) {
%2 = icmp eq %struct.sc_error* %0, null
br i1 %2, label %13, label %3
3: ; preds = %1
%4 = tail call i32 @sc_error_domain(%struct.sc_error* %0)
%5 = tail call i64 @strcmp(i32 %4, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i64 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %3
%8 = tail call i64 @sc_error_code(%struct.sc_error* %0)
br label %9
9: ; preds = %3, %7
%10 = phi i64 [ %8, %7 ], [ 0, %3 ]
store i64 %10, i64* @errno
%11 = tail call i32 @sc_error_msg(%struct.sc_error* %0)
%12 = tail call i32 @die(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %11)
br label %13
13: ; preds = %9, %1
ret void
}