#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 t_irc_server {
  int dummy;
};

/* Variables and functions */
char *irc_server_get_chanmodes(struct t_irc_server *);
scalar_t__ irc_server_get_prefix_mode_index(struct t_irc_server *, char);
char *strchr(char const *, char);
char irc_mode_get_chanmode_type(struct t_irc_server *server, char chanmode) {
  char chanmode_type, *pos;
  const char *chanmodes, *ptr_chanmodes;
  if (irc_server_get_prefix_mode_index(server, chanmode) >= 0)
    return 'B';
  chanmodes = irc_server_get_chanmodes(server);
  pos = strchr(chanmodes, chanmode);
  if (pos) {
    chanmode_type = 'A';
    for (ptr_chanmodes = chanmodes; ptr_chanmodes < pos; ptr_chanmodes++) {
      if (ptr_chanmodes[0] == ',') {
        if (chanmode_type == 'D')
          break;
        chanmode_type++;
      }
    }
    return chanmode_type;
  }
  return 'D';
}


x86 assembly (clang, -O0):
<irc_mode_get_chanmode_type>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %sil,%al
mov    %rdi,-0x10(%rbp)
mov    %al,-0x11(%rbp)
mov    -0x10(%rbp),%rdi
movsbl -0x11(%rbp),%esi
call   1040 <irc_server_get_prefix_mode_index@plt>
cmp    $0x0,%rax
jl     1162 <irc_mode_get_chanmode_type+0x32>
movb   $0x42,-0x1(%rbp)
jmp    11f4 <irc_mode_get_chanmode_type+0xc4>
mov    -0x10(%rbp),%rdi
call   1050 <irc_server_get_chanmodes@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
movsbl -0x11(%rbp),%esi
call   1030 <strchr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11f0 <irc_mode_get_chanmode_type+0xc0>
movb   $0x41,-0x12(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
cmp    -0x20(%rbp),%rax
jae    11e5 <irc_mode_get_chanmode_type+0xb5>
mov    -0x30(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2c,%eax
jne    11cf <irc_mode_get_chanmode_type+0x9f>
movsbl -0x12(%rbp),%eax
cmp    $0x44,%eax
jne    11c7 <irc_mode_get_chanmode_type+0x97>
jmp    11e5 <irc_mode_get_chanmode_type+0xb5>
mov    -0x12(%rbp),%al
add    $0x1,%al
mov    %al,-0x12(%rbp)
jmp    11d4 <irc_mode_get_chanmode_type+0xa4>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    1197 <irc_mode_get_chanmode_type+0x67>
mov    -0x12(%rbp),%al
mov    %al,-0x1(%rbp)
jmp    11f4 <irc_mode_get_chanmode_type+0xc4>
movb   $0x44,-0x1(%rbp)
movsbl -0x1(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<irc_mode_get_chanmode_type>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%rbx
call   1040 <irc_server_get_prefix_mode_index@plt>
mov    %rax,%rcx
mov    $0x42,%al
test   %rcx,%rcx
jns    1199 <irc_mode_get_chanmode_type+0x69>
mov    %rbx,%rdi
call   1050 <irc_server_get_chanmodes@plt>
mov    %rax,%rbx
movsbl %bpl,%esi
mov    %rax,%rdi
call   1030 <strchr@plt>
test   %rax,%rax
je     1197 <irc_mode_get_chanmode_type+0x67>
mov    %rax,%rcx
mov    $0x41,%al
cmp    %rcx,%rbx
jae    1199 <irc_mode_get_chanmode_type+0x69>
sub    %rbx,%rcx
mov    $0x41,%al
xor    %edx,%edx
jmp    1189 <irc_mode_get_chanmode_type+0x59>
cs nopw 0x0(%rax,%rax,1)
add    $0x1,%rdx
cmp    %rdx,%rcx
je     1199 <irc_mode_get_chanmode_type+0x69>
cmpb   $0x2c,(%rbx,%rdx,1)
jne    1180 <irc_mode_get_chanmode_type+0x50>
cmp    $0x44,%al
je     1197 <irc_mode_get_chanmode_type+0x67>
add    $0x1,%al
jmp    1180 <irc_mode_get_chanmode_type+0x50>
mov    $0x44,%al
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.t_irc_server = type { i32 }
define signext i8 @irc_mode_get_chanmode_type(%struct.t_irc_server* %0, i8 signext %1) {
%3 = alloca i8
%4 = alloca %struct.t_irc_server*
%5 = alloca i8
%6 = alloca i8
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
store %struct.t_irc_server* %0, %struct.t_irc_server** %4
store i8 %1, i8* %5
%10 = load %struct.t_irc_server*, %struct.t_irc_server** %4
%11 = load i8, i8* %5
%12 = call i64 @irc_server_get_prefix_mode_index(%struct.t_irc_server* %10, i8 signext %11)
%13 = icmp sge i64 %12, 0
br i1 %13, label %14, label %15
14: ; preds = %2
store i8 66, i8* %3
br label %50
15: ; preds = %2
%16 = load %struct.t_irc_server*, %struct.t_irc_server** %4
%17 = call i8* @irc_server_get_chanmodes(%struct.t_irc_server* %16)
store i8* %17, i8** %8
%18 = load i8*, i8** %8
%19 = load i8, i8* %5
%20 = call i8* @strchr(i8* %18, i8 signext %19)
store i8* %20, i8** %7
%21 = load i8*, i8** %7
%22 = icmp ne i8* %21, null
br i1 %22, label %23, label %49
23: ; preds = %15
store i8 65, i8* %6
%24 = load i8*, i8** %8
store i8* %24, i8** %9
br label %25
25: ; preds = %44, %23
%26 = load i8*, i8** %9
%27 = load i8*, i8** %7
%28 = icmp ult i8* %26, %27
br i1 %28, label %29, label %47
29: ; preds = %25
%30 = load i8*, i8** %9
%31 = getelementptr inbounds i8, i8* %30, i64 0
%32 = load i8, i8* %31
%33 = sext i8 %32 to i32
%34 = icmp eq i32 %33, 44
br i1 %34, label %35, label %43
35: ; preds = %29
%36 = load i8, i8* %6
%37 = sext i8 %36 to i32
%38 = icmp eq i32 %37, 68
br i1 %38, label %39, label %40
39: ; preds = %35
br label %47
40: ; preds = %35
%41 = load i8, i8* %6
%42 = add i8 %41, 1
store i8 %42, i8* %6
br label %43
43: ; preds = %40, %29
br label %44
44: ; preds = %43
%45 = load i8*, i8** %9
%46 = getelementptr inbounds i8, i8* %45, i32 1
store i8* %46, i8** %9
br label %25
47: ; preds = %39, %25
%48 = load i8, i8* %6
store i8 %48, i8* %3
br label %50
49: ; preds = %15
store i8 68, i8* %3
br label %50
50: ; preds = %49, %47, %14
%51 = load i8, i8* %3
ret i8 %51
}

LLVM IR (-O2):
%struct.t_irc_server = type { i32 }
define signext i8 @irc_mode_get_chanmode_type(%struct.t_irc_server* %0, i8 signext %1) {
%3 = tail call i64 @irc_server_get_prefix_mode_index(%struct.t_irc_server* %0, i8 signext %1)
%4 = icmp sgt i64 %3, -1
br i1 %4, label %29, label %5
5: ; preds = %2
%6 = tail call i8* @irc_server_get_chanmodes(%struct.t_irc_server* %0)
%7 = ptrtoint i8* %6 to i64
%8 = tail call i8* @strchr(i8* dereferenceable(1) %6, i8 signext %1)
%9 = ptrtoint i8* %8 to i64
%10 = icmp eq i8* %8, null
br i1 %10, label %29, label %11
11: ; preds = %5
%12 = icmp ult i8* %6, %8
br i1 %12, label %13, label %29
13: ; preds = %11
%14 = sub i64 %9, %7
%15 = getelementptr i8, i8* %6, i64 %14
br label %16
16: ; preds = %13, %25
%17 = phi i8* [ %27, %25 ], [ %6, %13 ]
%18 = phi i8 [ %26, %25 ], [ 65, %13 ]
%19 = load i8, i8* %17
%20 = icmp eq i8 %19, 44
br i1 %20, label %21, label %25
21: ; preds = %16
%22 = icmp eq i8 %18, 68
br i1 %22, label %29, label %23
23: ; preds = %21
%24 = add i8 %18, 1
br label %25
25: ; preds = %16, %23
%26 = phi i8 [ %24, %23 ], [ %18, %16 ]
%27 = getelementptr inbounds i8, i8* %17, i64 1
%28 = icmp eq i8* %27, %15
br i1 %28, label %29, label %16
29: ; preds = %21, %25, %11, %5, %2
%30 = phi i8 [ 66, %2 ], [ 68, %5 ], [ 65, %11 ], [ 68, %21 ], [ %26, %25 ]
ret i8 %30
}