#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 */
struct map_session_data {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ intif_GMmessage(char *, scalar_t__, int);
int /*<<< orphan*/ sscanf(char const *, char *, char *);
scalar_t__ strlen(char *);
int atcommand_kami(const int fd, struct map_session_data *sd,
                   const char *command, const char *message) {
  char output[200];
  if (!message || !*message)
    return -1;
  sscanf(message, "%199[^\n]", output);
  intif_GMmessage(output, strlen(output) + 1,
                  (*(command + 5) == 'b') ? 0x10 : 0);
  return 0;
}


x86 assembly (clang, -O0):
<atcommand_kami>:
push   %rbp
mov    %rsp,%rbp
sub    $0x100,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1162 <atcommand_kami+0x32>
mov    -0x20(%rbp),%rax
cmpb   $0x0,(%rax)
jne    116e <atcommand_kami+0x3e>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ce <atcommand_kami+0x9e>
mov    -0x20(%rbp),%rdi
lea    -0xf0(%rbp),%rdx
lea    0xe80(%rip),%rsi
call   1050 <sscanf@plt>
lea    -0xf0(%rbp),%rax
mov    %rax,-0xf8(%rbp)
lea    -0xf0(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0xf8(%rbp),%rdi
mov    %rax,%rsi
add    $0x1,%rsi
mov    -0x18(%rbp),%rax
movsbl 0x5(%rax),%ecx
xor    %edx,%edx
mov    $0x10,%eax
cmp    $0x62,%ecx
cmove  %eax,%edx
call   1040 <intif_GMmessage@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x100,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<atcommand_kami>:
push   %r14
push   %rbx
sub    $0xc8,%rsp
mov    $0xffffffff,%eax
test   %rcx,%rcx
je     1183 <atcommand_kami+0x53>
cmpb   $0x0,(%rcx)
je     1183 <atcommand_kami+0x53>
mov    %rdx,%rbx
lea    0xead(%rip),%rsi
mov    %rsp,%r14
mov    %rcx,%rdi
mov    %r14,%rdx
call   1050 <sscanf@plt>
mov    %r14,%rdi
call   1030 <strlen@plt>
lea    0x1(%rax),%rsi
xor    %edx,%edx
cmpb   $0x62,0x5(%rbx)
sete   %dl
shl    $0x4,%edx
mov    %r14,%rdi
call   1040 <intif_GMmessage@plt>
xor    %eax,%eax
add    $0xc8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.map_session_data = type { i32 }
@.str = [9 x i8] c"%199[^\0A]\00"
define i32 @atcommand_kami(i32 %0, %struct.map_session_data* %1, i8* %2, i8* %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca %struct.map_session_data*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca [200 x i8]
store i32 %0, i32* %6
store %struct.map_session_data* %1, %struct.map_session_data** %7
store i8* %2, i8** %8
store i8* %3, i8** %9
%11 = load i8*, i8** %9
%12 = icmp ne i8* %11, null
br i1 %12, label %13, label %17
13: ; preds = %4
%14 = load i8*, i8** %9
%15 = load i8, i8* %14
%16 = icmp ne i8 %15, 0
br i1 %16, label %18, label %17
17: ; preds = %13, %4
store i32 -1, i32* %5
br label %34
18: ; preds = %13
%19 = load i8*, i8** %9
%20 = getelementptr inbounds [200 x i8], [200 x i8]* %10, i64 0, i64 0
%21 = call i32 @sscanf(i8* %19, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* %20)
%22 = getelementptr inbounds [200 x i8], [200 x i8]* %10, i64 0, i64 0
%23 = getelementptr inbounds [200 x i8], [200 x i8]* %10, i64 0, i64 0
%24 = call i64 @strlen(i8* %23)
%25 = add nsw i64 %24, 1
%26 = load i8*, i8** %8
%27 = getelementptr inbounds i8, i8* %26, i64 5
%28 = load i8, i8* %27
%29 = sext i8 %28 to i32
%30 = icmp eq i32 %29, 98
%31 = zext i1 %30 to i64
%32 = select i1 %30, i32 16, i32 0
%33 = call i32 @intif_GMmessage(i8* %22, i64 %25, i32 %32)
store i32 0, i32* %5
br label %34
34: ; preds = %18, %17
%35 = load i32, i32* %5
ret i32 %35
}

LLVM IR (-O2):
%struct.map_session_data = type { i32 }
@.str = [9 x i8] c"%199[^\0A]\00"
define i32 @atcommand_kami(i32 %0, %struct.map_session_data* nocapture readnone %1, i8* nocapture %2, i8* %3) {
%5 = alloca [200 x i8]
%6 = getelementptr inbounds [200 x i8], [200 x i8]* %5, i64 0, i64 0
%7 = icmp eq i8* %3, null
br i1 %7, label %20, label %8
8: ; preds = %4
%9 = load i8, i8* %3
%10 = icmp eq i8 %9, 0
br i1 %10, label %20, label %11
11: ; preds = %8
%12 = call i32 @sscanf(i8* %3, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* %6)
%13 = call i64 @strlen(i8* %6)
%14 = add nsw i64 %13, 1
%15 = getelementptr inbounds i8, i8* %2, i64 5
%16 = load i8, i8* %15
%17 = icmp eq i8 %16, 98
%18 = select i1 %17, i32 16, i32 0
%19 = call i32 @intif_GMmessage(i8* %6, i64 %14, i32 %18)
br label %20
20: ; preds = %4, %8, %11
%21 = phi i32 [ 0, %11 ], [ -1, %8 ], [ -1, %4 ]
ret i32 %21
}