#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*/ assert(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const);
int /*<<< orphan*/ m_chat(char const *);
int /*<<< orphan*/ m_list_user(int);
int /*<<< orphan*/ m_login(char const *);
int /*<<< orphan*/ stderr;
int strtol(char const *, int /*<<< orphan*/ *, int);
int msg_handler(const char *msg) {
  int id;
  assert(msg != NULL);
  switch (msg[0]) {
  case 'l':
    m_login(msg + 5);
    break;
  case 'L':
    id = strtol(msg + 2, NULL, 10);
    m_list_user(id);
    break;
  case 'Q':
    break;
  case 'C':
    m_chat(msg + 3);
    break;
  case 'B':
    break;
  case 'F':
    break;
  default:
    fprintf(stderr, "unkown msg type:%c\n", msg[0]);
    goto err;
    break;
  }
  return 0;
err:
  return -1;
}


x86 assembly (clang, -O0):
<msg_handler>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
test   %rax,%rax
setne  %al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
add    $0xffffffbe,%eax
mov    %eax,%ecx
mov    %rcx,-0x20(%rbp)
sub    $0x2a,%eax
ja     1204 <msg_handler+0xa4>
mov    -0x20(%rbp),%rax
lea    0xe5e(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x10(%rbp),%rdi
add    $0x5,%rdi
call   1040 <m_login@plt>
jmp    1225 <msg_handler+0xc5>
mov    -0x10(%rbp),%rdi
add    $0x2,%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1070 <strtol@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
call   1030 <m_list_user@plt>
jmp    1225 <msg_handler+0xc5>
jmp    1225 <msg_handler+0xc5>
mov    -0x10(%rbp),%rdi
add    $0x3,%rdi
call   1080 <m_chat@plt>
jmp    1225 <msg_handler+0xc5>
jmp    1225 <msg_handler+0xc5>
jmp    1225 <msg_handler+0xc5>
mov    0x2dd5(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
lea    0xe94(%rip),%rsi
movsbl (%rax),%edx
call   1060 <fprintf@plt>
jmp    1231 <msg_handler+0xd1>
movl   $0x0,-0x4(%rbp)
jmp    1238 <msg_handler+0xd8>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<msg_handler>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
xor    %edi,%edi
test   %rbx,%rbx
setne  %dil
call   1050 <assert@plt>
movsbl (%rbx),%eax
lea    -0x42(%rax),%ecx
cmp    $0x2a,%ecx
ja     11a1 <msg_handler+0x41>
xor    %r14d,%r14d
lea    0xe76(%rip),%rdx
movslq (%rdx,%rcx,4),%rcx
add    %rdx,%rcx
jmp    *%rcx
add    $0x3,%rbx
mov    %rbx,%rdi
call   1080 <m_chat@plt>
jmp    11ec <msg_handler+0x8c>
mov    0x2e38(%rip),%rcx
mov    (%rcx),%edi
movsbl %al,%edx
lea    0xef8(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0xffffffff,%r14d
jmp    11ec <msg_handler+0x8c>
add    $0x2,%rbx
xor    %r14d,%r14d
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1070 <strtol@plt>
mov    %eax,%edi
call   1030 <m_list_user@plt>
jmp    11ec <msg_handler+0x8c>
add    $0x5,%rbx
mov    %rbx,%rdi
call   1040 <m_login@plt>
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [20 x i8] c"unkown msg type:%c\0A\00"
define i32 @msg_handler(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
store i8* %0, i8** %3
%5 = load i8*, i8** %3
%6 = icmp ne i8* %5, null
%7 = zext i1 %6 to i32
%8 = call i32 @assert(i32 %7)
%9 = load i8*, i8** %3
%10 = getelementptr inbounds i8, i8* %9, i64 0
%11 = load i8, i8* %10
%12 = sext i8 %11 to i32
switch i32 %12, label %30 [
i32 108, label %13
i32 76, label %17
i32 81, label %23
i32 67, label %24
i32 66, label %28
i32 70, label %29
]
13: ; preds = %1
%14 = load i8*, i8** %3
%15 = getelementptr inbounds i8, i8* %14, i64 5
%16 = call i32 @m_login(i8* %15)
br label %36
17: ; preds = %1
%18 = load i8*, i8** %3
%19 = getelementptr inbounds i8, i8* %18, i64 2
%20 = call i32 @strtol(i8* %19, i32* null, i32 10)
store i32 %20, i32* %4
%21 = load i32, i32* %4
%22 = call i32 @m_list_user(i32 %21)
br label %36
23: ; preds = %1
br label %36
24: ; preds = %1
%25 = load i8*, i8** %3
%26 = getelementptr inbounds i8, i8* %25, i64 3
%27 = call i32 @m_chat(i8* %26)
br label %36
28: ; preds = %1
br label %36
29: ; preds = %1
br label %36
30: ; preds = %1
%31 = load i32, i32* @stderr
%32 = load i8*, i8** %3
%33 = getelementptr inbounds i8, i8* %32, i64 0
%34 = load i8, i8* %33
%35 = call i32 @fprintf(i32 %31, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8 signext %34)
br label %37
36: ; preds = %29, %28, %24, %23, %17, %13
store i32 0, i32* %2
br label %38
37: ; preds = %30
store i32 -1, i32* %2
br label %38
38: ; preds = %37, %36
%39 = load i32, i32* %2
ret i32 %39
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [20 x i8] c"unkown msg type:%c\0A\00"
define i32 @msg_handler(i8* %0) {
%2 = icmp ne i8* %0, null
%3 = zext i1 %2 to i32
%4 = tail call i32 @assert(i32 %3)
%5 = load i8, i8* %0
%6 = sext i8 %5 to i32
switch i32 %6, label %17 [
i32 108, label %7
i32 76, label %10
i32 81, label %20
i32 67, label %14
i32 66, label %20
i32 70, label %20
]
7: ; preds = %1
%8 = getelementptr inbounds i8, i8* %0, i64 5
%9 = tail call i32 @m_login(i8* %8)
br label %20
10: ; preds = %1
%11 = getelementptr inbounds i8, i8* %0, i64 2
%12 = tail call i32 @strtol(i8* nocapture %11, i32* null, i32 10)
%13 = tail call i32 @m_list_user(i32 %12)
br label %20
14: ; preds = %1
%15 = getelementptr inbounds i8, i8* %0, i64 3
%16 = tail call i32 @m_chat(i8* %15)
br label %20
17: ; preds = %1
%18 = load i32, i32* @stderr
%19 = tail call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8 signext %5)
br label %20
20: ; preds = %7, %10, %1, %14, %1, %1, %17
%21 = phi i32 [ -1, %17 ], [ 0, %1 ], [ 0, %1 ], [ 0, %14 ], [ 0, %1 ], [ 0, %10 ], [ 0, %7 ]
ret i32 %21
}