#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*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ send_msg(int, char *, int /*<<< orphan*/);
int /*<<< orphan*/ sprintf(char *, char *, ...);
void send_error(int client_sock, short error_type, char *msg) {
  char buf[8192];
  memset(buf, 0, 8192);
  switch (error_type) {
  case 0:
    sprintf(buf, "ERROR\r\n");
    break;
  case 1:
    sprintf(buf, "CLIENT_ERROR %s\r\n", msg);
    break;
  case 2:
    sprintf(buf, "SERVER_ERROR %s\r\n", msg);
    break;
  default:
    sprintf(buf, "ERROR\r\n");
  }
  send_msg(client_sock, buf, 0);
}


x86 assembly (clang, -O0):
<send_error>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2020,%rsp
mov    %si,%ax
mov    %edi,-0x4(%rbp)
mov    %ax,-0x6(%rbp)
mov    %rdx,-0x10(%rbp)
lea    -0x2010(%rbp),%rdi
xor    %esi,%esi
mov    $0x2000,%edx
call   1030 <memset@plt>
movswl -0x6(%rbp),%eax
mov    %eax,-0x2014(%rbp)
test   %eax,%eax
je     119b <send_error+0x6b>
jmp    1173 <send_error+0x43>
mov    -0x2014(%rbp),%eax
sub    $0x1,%eax
je     11b5 <send_error+0x85>
jmp    1187 <send_error+0x57>
mov    -0x2014(%rbp),%eax
sub    $0x2,%eax
je     11d3 <send_error+0xa3>
jmp    11f1 <send_error+0xc1>
lea    -0x2010(%rbp),%rdi
lea    0xe57(%rip),%rsi
mov    $0x0,%al
call   1050 <sprintf@plt>
jmp    1206 <send_error+0xd6>
lea    -0x2010(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xe41(%rip),%rsi
mov    $0x0,%al
call   1050 <sprintf@plt>
jmp    1206 <send_error+0xd6>
lea    -0x2010(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xe35(%rip),%rsi
mov    $0x0,%al
call   1050 <sprintf@plt>
jmp    1206 <send_error+0xd6>
lea    -0x2010(%rbp),%rdi
lea    0xe01(%rip),%rsi
mov    $0x0,%al
call   1050 <sprintf@plt>
mov    -0x4(%rbp),%edi
lea    -0x2010(%rbp),%rsi
xor    %edx,%edx
call   1040 <send_msg@plt>
add    $0x2020,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<send_error>:
push   %rbp
push   %r14
push   %rbx
sub    $0x2000,%rsp
mov    %rdx,%rbx
mov    %esi,%ebp
mov    %edi,%r14d
mov    %rsp,%rdi
xor    %esi,%esi
mov    $0x2000,%edx
call   1030 <memset@plt>
cmp    $0x2,%ebp
je     116e <send_error+0x3e>
cmp    $0x1,%ebp
je     1177 <send_error+0x47>
test   %ebp,%ebp
movabs $0xa0d524f525245,%rax
mov    %rax,(%rsp)
jmp    118b <send_error+0x5b>
lea    0xe9d(%rip),%rsi
jmp    117e <send_error+0x4e>
lea    0xe82(%rip),%rsi
mov    %rsp,%rdi
mov    %rbx,%rdx
xor    %eax,%eax
call   1050 <sprintf@plt>
mov    %rsp,%rsi
mov    %r14d,%edi
xor    %edx,%edx
call   1040 <send_msg@plt>
add    $0x2000,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [8 x i8] c"ERROR\0D\0A\00"
@.str.1 = [18 x i8] c"CLIENT_ERROR %s\0D\0A\00"
@.str.2 = [18 x i8] c"SERVER_ERROR %s\0D\0A\00"
define void @send_error(i32 %0, i16 signext %1, i8* %2) {
%4 = alloca i32
%5 = alloca i16
%6 = alloca i8*
%7 = alloca [8192 x i8]
store i32 %0, i32* %4
store i16 %1, i16* %5
store i8* %2, i8** %6
%8 = getelementptr inbounds [8192 x i8], [8192 x i8]* %7, i64 0, i64 0
%9 = call i32 @memset(i8* %8, i32 0, i32 8192)
%10 = load i16, i16* %5
%11 = sext i16 %10 to i32
switch i32 %11, label %23 [
i32 0, label %12
i32 1, label %15
i32 2, label %19
]
12: ; preds = %3
%13 = getelementptr inbounds [8192 x i8], [8192 x i8]* %7, i64 0, i64 0
%14 = call i32 (i8*, i8*, ...) @sprintf(i8* %13, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
br label %26
15: ; preds = %3
%16 = getelementptr inbounds [8192 x i8], [8192 x i8]* %7, i64 0, i64 0
%17 = load i8*, i8** %6
%18 = call i32 (i8*, i8*, ...) @sprintf(i8* %16, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %17)
br label %26
19: ; preds = %3
%20 = getelementptr inbounds [8192 x i8], [8192 x i8]* %7, i64 0, i64 0
%21 = load i8*, i8** %6
%22 = call i32 (i8*, i8*, ...) @sprintf(i8* %20, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* %21)
br label %26
23: ; preds = %3
%24 = getelementptr inbounds [8192 x i8], [8192 x i8]* %7, i64 0, i64 0
%25 = call i32 (i8*, i8*, ...) @sprintf(i8* %24, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
br label %26
26: ; preds = %23, %19, %15, %12
%27 = load i32, i32* %4
%28 = getelementptr inbounds [8192 x i8], [8192 x i8]* %7, i64 0, i64 0
%29 = call i32 @send_msg(i32 %27, i8* %28, i32 0)
ret void
}

LLVM IR (-O2):
@.str.1 = [18 x i8] c"CLIENT_ERROR %s\0D\0A\00"
@.str.2 = [18 x i8] c"SERVER_ERROR %s\0D\0A\00"
define void @send_error(i32 %0, i16 signext %1, i8* %2) {
%4 = alloca [8192 x i8]
%5 = getelementptr inbounds [8192 x i8], [8192 x i8]* %4, i64 0, i64 0
%6 = call i32 @memset(i8* %5, i32 0, i32 8192)
%7 = sext i16 %1 to i32
switch i32 %7, label %14 [
i32 0, label %8
i32 1, label %10
i32 2, label %12
]
8: ; preds = %3
%9 = bitcast [8192 x i8]* %4 to i64*
store i64 2829396936380997, i64* %9
br label %16
10: ; preds = %3
%11 = call i32 (i8*, i8*, ...) @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %2)
br label %16
12: ; preds = %3
%13 = call i32 (i8*, i8*, ...) @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* %2)
br label %16
14: ; preds = %3
%15 = bitcast [8192 x i8]* %4 to i64*
store i64 2829396936380997, i64* %15
br label %16
16: ; preds = %14, %12, %10, %8
%17 = call i32 @send_msg(i32 %0, i8* %5, i32 0)
ret void
}