#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*/ errno;
int /*<<< orphan*/ sprintf(char *, char *, int);
char *strerror(int /*<<< orphan*/);
int /*<<< orphan*/ tosLog_error(char *, char *, char *, ...);
void tosError_log(int errCode, int errCodeDetail) {
  char err[40];
  switch (errCode) {
  case 6000:
    tosLog_error("Win32API", "error", "%d", errCodeDetail);
    break;
  case 6001:
    sprintf(err, "%d", errCodeDetail);
    tosLog_error("WinSocket", "error", err);
    break;
  default:
    tosLog_error("c-runtime", "error", strerror(errno));
  }
}


x86 assembly (clang, -O0):
<tosError_log>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x34(%rbp)
sub    $0x1770,%eax
je     1167 <tosError_log+0x37>
jmp    1154 <tosError_log+0x24>
mov    -0x34(%rbp),%eax
sub    $0x1771,%eax
je     118b <tosError_log+0x5b>
jmp    11bc <tosError_log+0x8c>
mov    -0x8(%rbp),%ecx
lea    0xe8f(%rip),%rdi
lea    0xe91(%rip),%rsi
lea    0xe90(%rip),%rdx
mov    $0x0,%al
call   1030 <tosLog_error@plt>
jmp    11e2 <tosError_log+0xb2>
lea    -0x30(%rbp),%rdi
mov    -0x8(%rbp),%edx
lea    0xe76(%rip),%rsi
call   1040 <sprintf@plt>
lea    -0x30(%rbp),%rdx
lea    0xe69(%rip),%rdi
lea    0xe59(%rip),%rsi
mov    $0x0,%al
call   1030 <tosLog_error@plt>
jmp    11e2 <tosError_log+0xb2>
mov    0x2e1d(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
mov    %rax,%rdx
lea    0xe48(%rip),%rdi
lea    0xe2e(%rip),%rsi
mov    $0x0,%al
call   1030 <tosLog_error@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tosError_log>:
push   %rbx
sub    $0x30,%rsp
mov    %esi,%ecx
cmp    $0x1771,%edi
je     1168 <tosError_log+0x38>
cmp    $0x1770,%edi
jne    119a <tosError_log+0x6a>
lea    0xeb2(%rip),%rdi
lea    0xeb4(%rip),%rsi
lea    0xeb3(%rip),%rdx
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbx
jmp    1030 <tosLog_error@plt>
lea    0xea0(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    %ecx,%edx
call   1040 <sprintf@plt>
lea    0xe8f(%rip),%rdi
lea    0xe7f(%rip),%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1030 <tosLog_error@plt>
add    $0x30,%rsp
pop    %rbx
ret
mov    0x2e3f(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
lea    0xe6d(%rip),%rdi
lea    0xe53(%rip),%rsi
mov    %rax,%rdx
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbx
jmp    1030 <tosLog_error@plt>

LLVM IR (-O0):
@.str = [9 x i8] c"Win32API\00"
@.str.1 = [6 x i8] c"error\00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [10 x i8] c"WinSocket\00"
@.str.4 = [10 x i8] c"c-runtime\00"
@errno = global i32 0
define void @tosError_log(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca [40 x i8]
store i32 %0, i32* %3
store i32 %1, i32* %4
%6 = load i32, i32* %3
switch i32 %6, label %16 [
i32 6000, label %7
i32 6001, label %10
]
7: ; preds = %2
%8 = load i32, i32* %4
%9 = call i32 (i8*, i8*, i8*, ...) @tosLog_error(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %8)
br label %20
10: ; preds = %2
%11 = getelementptr inbounds [40 x i8], [40 x i8]* %5, i64 0, i64 0
%12 = load i32, i32* %4
%13 = call i32 @sprintf(i8* %11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %12)
%14 = getelementptr inbounds [40 x i8], [40 x i8]* %5, i64 0, i64 0
%15 = call i32 (i8*, i8*, i8*, ...) @tosLog_error(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %14)
br label %20
16: ; preds = %2
%17 = load i32, i32* @errno
%18 = call i8* @strerror(i32 %17)
%19 = call i32 (i8*, i8*, i8*, ...) @tosLog_error(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %18)
br label %20
20: ; preds = %16, %10, %7
ret void
}

LLVM IR (-O2):
@.str = [9 x i8] c"Win32API\00"
@.str.1 = [6 x i8] c"error\00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [10 x i8] c"WinSocket\00"
@.str.4 = [10 x i8] c"c-runtime\00"
@errno = global i32 0
define void @tosError_log(i32 %0, i32 %1) {
%3 = alloca [40 x i8]
%4 = getelementptr inbounds [40 x i8], [40 x i8]* %3, i64 0, i64 0
switch i32 %0, label %10 [
i32 6000, label %5
i32 6001, label %7
]
5: ; preds = %2
%6 = tail call i32 (i8*, i8*, i8*, ...) @tosLog_error(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %1)
br label %14
7: ; preds = %2
%8 = call i32 @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %1)
%9 = call i32 (i8*, i8*, i8*, ...) @tosLog_error(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %4)
br label %14
10: ; preds = %2
%11 = load i32, i32* @errno
%12 = tail call i8* @strerror(i32 %11)
%13 = tail call i32 (i8*, i8*, i8*, ...) @tosLog_error(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %12)
br label %14
14: ; preds = %10, %7, %5
ret void
}