#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*/ add_channel(char *);
int handle_priv(char *, char *, char *, int const);
scalar_t__ is_channel(char *);
int snprintf(char *, int const, char *, char *, char *);
char *strchr(char *, char);
int handle_join(char *params, char *mesg, const int mesg_len) {
  if (!*params++)
    return 0;
  char *msgorkey = strchr(params, ' ');
  if (msgorkey)
    *(msgorkey++) = '\0';
  else
    msgorkey = "";
  if (is_channel(params))
    return snprintf(mesg, mesg_len, "JOIN %s %s\r\n", params, msgorkey);
  else if (!msgorkey)
    return 0;
  else
    add_channel(params);
  return handle_priv(params, msgorkey, mesg, mesg_len);
}


x86 assembly (clang, -O0):
<handle_join>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
cmpb   $0x0,(%rax)
jne    1187 <handle_join+0x37>
movl   $0x0,-0x4(%rbp)
jmp    1238 <handle_join+0xe8>
mov    -0x10(%rbp),%rdi
mov    $0x20,%esi
call   1040 <strchr@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     11bb <handle_join+0x6b>
mov    -0x28(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x28(%rbp)
movb   $0x0,(%rax)
jmp    11c6 <handle_join+0x76>
lea    0xe4a(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <is_channel@plt>
cmp    $0x0,%rax
je     11fc <handle_join+0xac>
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    -0x10(%rbp),%rcx
mov    -0x28(%rbp),%r8
lea    0xe11(%rip),%rdx
call   1050 <snprintf@plt>
mov    %eax,-0x4(%rbp)
jmp    1238 <handle_join+0xe8>
cmpq   $0x0,-0x28(%rbp)
jne    1213 <handle_join+0xc3>
movl   $0x0,-0x4(%rbp)
jmp    1238 <handle_join+0xe8>
mov    -0x10(%rbp),%rdi
call   1060 <add_channel@plt>
jmp    1221 <handle_join+0xd1>
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x1c(%rbp),%ecx
call   1070 <handle_priv@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<handle_join>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
cmpb   $0x0,(%rdi)
je     1187 <handle_join+0x37>
mov    %edx,%r14d
mov    %rsi,%r15
mov    %rdi,%rbx
add    $0x1,%rbx
mov    %rbx,%rdi
mov    $0x20,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     1194 <handle_join+0x44>
mov    %rax,%rbp
add    $0x1,%rbp
movb   $0x0,(%rax)
jmp    119b <handle_join+0x4b>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe71(%rip),%rbp
mov    %rbx,%rdi
call   1030 <is_channel@plt>
test   %rax,%rax
je     11ca <handle_join+0x7a>
lea    0xe51(%rip),%rdx
mov    %r15,%rdi
mov    %r14d,%esi
mov    %rbx,%rcx
mov    %rbp,%r8
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <snprintf@plt>
mov    %rbx,%rdi
call   1060 <add_channel@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    %r15,%rdx
mov    %r14d,%ecx
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1070 <handle_priv@plt>

LLVM IR (-O0):
@.str = [1 x i8] zeroinitializer
@.str.1 = [13 x i8] c"JOIN %s %s\0D\0A\00"
define i32 @handle_join(i8* %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
%9 = load i8*, i8** %5
%10 = getelementptr inbounds i8, i8* %9, i32 1
store i8* %10, i8** %5
%11 = load i8, i8* %9
%12 = icmp ne i8 %11, 0
br i1 %12, label %14, label %13
13: ; preds = %3
store i32 0, i32* %4
br label %47
14: ; preds = %3
%15 = load i8*, i8** %5
%16 = call i8* @strchr(i8* %15, i8 signext 32)
store i8* %16, i8** %8
%17 = load i8*, i8** %8
%18 = icmp ne i8* %17, null
br i1 %18, label %19, label %22
19: ; preds = %14
%20 = load i8*, i8** %8
%21 = getelementptr inbounds i8, i8* %20, i32 1
store i8* %21, i8** %8
store i8 0, i8* %20
br label %23
22: ; preds = %14
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8** %8
br label %23
23: ; preds = %22, %19
%24 = load i8*, i8** %5
%25 = call i64 @is_channel(i8* %24)
%26 = icmp ne i64 %25, 0
br i1 %26, label %27, label %33
27: ; preds = %23
%28 = load i8*, i8** %6
%29 = load i32, i32* %7
%30 = load i8*, i8** %5
%31 = load i8*, i8** %8
%32 = call i32 @snprintf(i8* %28, i32 %29, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* %30, i8* %31)
store i32 %32, i32* %4
br label %47
33: ; preds = %23
%34 = load i8*, i8** %8
%35 = icmp ne i8* %34, null
br i1 %35, label %37, label %36
36: ; preds = %33
store i32 0, i32* %4
br label %47
37: ; preds = %33
%38 = load i8*, i8** %5
%39 = call i32 @add_channel(i8* %38)
br label %40
40: ; preds = %37
br label %41
41: ; preds = %40
%42 = load i8*, i8** %5
%43 = load i8*, i8** %8
%44 = load i8*, i8** %6
%45 = load i32, i32* %7
%46 = call i32 @handle_priv(i8* %42, i8* %43, i8* %44, i32 %45)
store i32 %46, i32* %4
br label %47
47: ; preds = %41, %36, %27, %13
%48 = load i32, i32* %4
ret i32 %48
}

LLVM IR (-O2):
@.str = [1 x i8] zeroinitializer
@.str.1 = [13 x i8] c"JOIN %s %s\0D\0A\00"
define i32 @handle_join(i8* %0, i8* %1, i32 %2) {
%4 = getelementptr inbounds i8, i8* %0, i64 1
%5 = load i8, i8* %0
%6 = icmp eq i8 %5, 0
br i1 %6, label %21, label %7
7: ; preds = %3
%8 = tail call i8* @strchr(i8* %4, i8 signext 32)
%9 = icmp eq i8* %8, null
br i1 %9, label %12, label %10
10: ; preds = %7
%11 = getelementptr inbounds i8, i8* %8, i64 1
store i8 0, i8* %8
br label %12
12: ; preds = %7, %10
%13 = phi i8* [ %11, %10 ], [ getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), %7 ]
%14 = tail call i64 @is_channel(i8* %4)
%15 = icmp eq i64 %14, 0
br i1 %15, label %18, label %16
16: ; preds = %12
%17 = tail call i32 @snprintf(i8* %1, i32 %2, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* %4, i8* %13)
br label %21
18: ; preds = %12
%19 = tail call i32 @add_channel(i8* %4)
%20 = tail call i32 @handle_priv(i8* %4, i8* %13, i8* %1, i32 %2)
br label %21
21: ; preds = %16, %18, %3
%22 = phi i32 [ 0, %3 ], [ %17, %16 ], [ %20, %18 ]
ret i32 %22
}