#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*/ abort();
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fflushall();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *, long,
                           char const *, ...);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
int sys_err(const char *msg, const char *source, long int line, int sw) {
  if (sw) {
    fprintf(stderr, "%s[%ld]: %s(%s)\n", source, line, msg, strerror(errno));
    fflushall();
    abort();
  } else {
    fprintf(stderr, "%s[%ld]: %s\n", source, line, msg);
  }
  return 0;
}


x86 assembly (clang, -O0):
<sys_err>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     11c1 <sys_err+0x81>
mov    0x2e78(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    0x2e4c(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    -0x3c(%rbp),%edi
mov    -0x38(%rbp),%rdx
mov    -0x30(%rbp),%rcx
mov    -0x28(%rbp),%r8
mov    %eax,%r9d
lea    0xe54(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x0,%al
call   1040 <fflushall@plt>
mov    $0x0,%al
call   1030 <abort@plt>
mov    0x2e18(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
mov    -0x8(%rbp),%r8
lea    0xe34(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sys_err>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %rdi,%r15
mov    0x2e89(%rip),%rax
mov    (%rax),%ebp
test   %ecx,%ecx
jne    1183 <sys_err+0x43>
lea    0xead(%rip),%rsi
mov    %ebp,%edi
mov    %rbx,%rdx
mov    %r14,%rcx
mov    %r15,%r8
xor    %eax,%eax
call   1050 <fprintf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2e4e(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
lea    0xe68(%rip),%rsi
mov    %ebp,%edi
mov    %rbx,%rdx
mov    %r14,%rcx
mov    %r15,%r8
mov    %eax,%r9d
xor    %eax,%eax
call   1050 <fprintf@plt>
xor    %eax,%eax
call   1040 <fflushall@plt>
xor    %eax,%eax
call   1030 <abort@plt>

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

LLVM IR (-O2):
@stderr = global i32 0
@.str = [17 x i8] c"%s[%ld]: %s(%s)\0A\00"
@errno = global i32 0
@.str.1 = [13 x i8] c"%s[%ld]: %s\0A\00"
define i32 @sys_err(i8* %0, i8* %1, i64 %2, i32 %3) {
%5 = icmp eq i32 %3, 0
%6 = load i32, i32* @stderr
br i1 %5, label %13, label %7
7: ; preds = %4
%8 = load i32, i32* @errno
%9 = tail call i32 @strerror(i32 %8)
%10 = tail call i32 (i32, i8*, i8*, i64, i8*, ...) @fprintf(i32 %6, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %1, i64 %2, i8* %0, i32 %9)
%11 = tail call i32 (...) @fflushall()
%12 = tail call i32 (...) @abort()
unreachable
13: ; preds = %4
%14 = tail call i32 (i32, i8*, i8*, i64, i8*, ...) @fprintf(i32 %6, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* %1, i64 %2, i8* %0)
ret i32 0
}