#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 dispatch_user_command(int, char const *, char const *, char const *,
                          char *);
char *first_word(char *, char **);
int /*<<< orphan*/ free(char *);
scalar_t__ match_commandprefix(char const *, char const **);
char *strdup(char const *);
int on_privmsg(int fd, const char *prefix, int argc, const char **argv) {
  const char *endptr;
  if (argc < 2)
    return 0;
  if (match_commandprefix(argv[2], &endptr)) {
    assert(endptr != NULL);
    const char *cmd;
    char *buf = strdup(endptr);
    char *msg;
    int ret;
    cmd = first_word(buf, &msg);
    ret = dispatch_user_command(fd, prefix, argv[1], cmd, msg);
    free(buf);
    return ret;
  }
  return 0;
}


x86 assembly (clang, -O0):
<on_privmsg>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
cmpl   $0x2,-0x14(%rbp)
jge    118c <on_privmsg+0x2c>
movl   $0x0,-0x4(%rbp)
jmp    1211 <on_privmsg+0xb1>
mov    -0x20(%rbp),%rax
mov    0x10(%rax),%rdi
lea    -0x28(%rbp),%rsi
call   1060 <match_commandprefix@plt>
cmp    $0x0,%rax
je     120a <on_privmsg+0xaa>
cmpq   $0x0,-0x28(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
mov    -0x28(%rbp),%rdi
call   1080 <strdup@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
lea    -0x40(%rbp),%rsi
call   1050 <first_word@plt>
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x20(%rbp),%rax
mov    0x8(%rax),%rdx
mov    -0x30(%rbp),%rcx
mov    -0x40(%rbp),%r8
call   1030 <dispatch_user_command@plt>
mov    %eax,-0x44(%rbp)
mov    -0x38(%rbp),%rdi
call   1040 <free@plt>
mov    -0x44(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1211 <on_privmsg+0xb1>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<on_privmsg>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
xor    %ebp,%ebp
cmp    $0x2,%edx
jl     11d7 <on_privmsg+0x77>
mov    %rcx,%rbx
mov    %rsi,%r14
mov    %edi,%r15d
mov    0x10(%rcx),%rdi
mov    %rsp,%rsi
call   1060 <match_commandprefix@plt>
test   %rax,%rax
je     11d7 <on_privmsg+0x77>
xor    %edi,%edi
cmpq   $0x0,(%rsp)
setne  %dil
call   1070 <assert@plt>
mov    (%rsp),%rdi
call   1080 <strdup@plt>
mov    %rax,%r12
lea    0x8(%rsp),%rsi
mov    %rax,%rdi
call   1050 <first_word@plt>
mov    0x8(%rbx),%rdx
mov    0x8(%rsp),%r8
mov    %r15d,%edi
mov    %r14,%rsi
mov    %rax,%rcx
call   1030 <dispatch_user_command@plt>
mov    %eax,%ebp
mov    %r12,%rdi
call   1040 <free@plt>
mov    %ebp,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @on_privmsg(i32 %0, i8* %1, i32 %2, i8** %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i8**
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca i8*
%14 = alloca i32
store i32 %0, i32* %6
store i8* %1, i8** %7
store i32 %2, i32* %8
store i8** %3, i8*** %9
%15 = load i32, i32* %8
%16 = icmp slt i32 %15, 2
br i1 %16, label %17, label %18
17: ; preds = %4
store i32 0, i32* %5
br label %45
18: ; preds = %4
%19 = load i8**, i8*** %9
%20 = getelementptr inbounds i8*, i8** %19, i64 2
%21 = load i8*, i8** %20
%22 = call i64 @match_commandprefix(i8* %21, i8** %10)
%23 = icmp ne i64 %22, 0
br i1 %23, label %24, label %44
24: ; preds = %18
%25 = load i8*, i8** %10
%26 = icmp ne i8* %25, null
%27 = zext i1 %26 to i32
%28 = call i32 @assert(i32 %27)
%29 = load i8*, i8** %10
%30 = call i8* @strdup(i8* %29)
store i8* %30, i8** %12
%31 = load i8*, i8** %12
%32 = call i8* @first_word(i8* %31, i8** %13)
store i8* %32, i8** %11
%33 = load i32, i32* %6
%34 = load i8*, i8** %7
%35 = load i8**, i8*** %9
%36 = getelementptr inbounds i8*, i8** %35, i64 1
%37 = load i8*, i8** %36
%38 = load i8*, i8** %11
%39 = load i8*, i8** %13
%40 = call i32 @dispatch_user_command(i32 %33, i8* %34, i8* %37, i8* %38, i8* %39)
store i32 %40, i32* %14
%41 = load i8*, i8** %12
%42 = call i32 @free(i8* %41)
%43 = load i32, i32* %14
store i32 %43, i32* %5
br label %45
44: ; preds = %18
store i32 0, i32* %5
br label %45
45: ; preds = %44, %24, %17
%46 = load i32, i32* %5
ret i32 %46
}

LLVM IR (-O2):
define i32 @on_privmsg(i32 %0, i8* %1, i32 %2, i8** nocapture %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = bitcast i8** %5 to i8*
%8 = icmp slt i32 %2, 2
br i1 %8, label %28, label %9
9: ; preds = %4
%10 = getelementptr inbounds i8*, i8** %3, i64 2
%11 = load i8*, i8** %10
%12 = call i64 @match_commandprefix(i8* %11, i8** %5)
%13 = icmp eq i64 %12, 0
br i1 %13, label %28, label %14
14: ; preds = %9
%15 = load i8*, i8** %5
%16 = icmp ne i8* %15, null
%17 = zext i1 %16 to i32
%18 = call i32 @assert(i32 %17)
%19 = load i8*, i8** %5
%20 = call i8* @strdup(i8* %19)
%21 = bitcast i8** %6 to i8*
%22 = call i8* @first_word(i8* %20, i8** %6)
%23 = getelementptr inbounds i8*, i8** %3, i64 1
%24 = load i8*, i8** %23
%25 = load i8*, i8** %6
%26 = call i32 @dispatch_user_command(i32 %0, i8* %1, i8* %24, i8* %22, i8* %25)
%27 = call i32 @free(i8* %20)
br label %28
28: ; preds = %9, %4, %14
%29 = phi i32 [ %26, %14 ], [ 0, %4 ], [ 0, %9 ]
ret i32 %29
}