#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 */
char *strchr(char const *, char const);
int mode_has_arg(const char *chanmodes, const char mode, const int dir) {
  char *m = strchr(chanmodes, mode), *c1, *c2 = NULL, *c3 = NULL;
  if (m == NULL)
    return (-1);
  if ((c1 = strchr(chanmodes, ',')) != NULL)
    if ((c2 = strchr(c1 + 1, ',')) != NULL)
      c3 = strchr(c2 + 1, ',');
  if (m < c1)
    return (2);
  if (m < c2)
    return (1);
  if ((m < c3) && (dir == 1))
    return (1);
  return (0);
}


x86 assembly (clang, -O0):
<mode_has_arg>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %sil,%al
mov    %rdi,-0x10(%rbp)
mov    %al,-0x11(%rbp)
mov    %edx,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
movsbl -0x11(%rbp),%esi
call   1030 <strchr@plt>
mov    %rax,-0x20(%rbp)
movq   $0x0,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    115d <mode_has_arg+0x4d>
movl   $0xffffffff,-0x4(%rbp)
jmp    1213 <mode_has_arg+0x103>
mov    -0x10(%rbp),%rdi
mov    $0x2c,%esi
call   1030 <strchr@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
je     11b4 <mode_has_arg+0xa4>
mov    -0x28(%rbp),%rdi
add    $0x1,%rdi
mov    $0x2c,%esi
call   1030 <strchr@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
je     11af <mode_has_arg+0x9f>
mov    -0x30(%rbp),%rdi
add    $0x1,%rdi
mov    $0x2c,%esi
call   1030 <strchr@plt>
mov    %rax,-0x38(%rbp)
jmp    11b4 <mode_has_arg+0xa4>
mov    -0x20(%rbp),%rax
cmp    -0x28(%rbp),%rax
jae    11ce <mode_has_arg+0xbe>
movl   $0x2,-0x4(%rbp)
jmp    1213 <mode_has_arg+0x103>
mov    -0x20(%rbp),%rax
cmp    -0x30(%rbp),%rax
jae    11e8 <mode_has_arg+0xd8>
movl   $0x1,-0x4(%rbp)
jmp    1213 <mode_has_arg+0x103>
mov    -0x20(%rbp),%rax
cmp    -0x38(%rbp),%rax
jae    120c <mode_has_arg+0xfc>
cmpl   $0x1,-0x18(%rbp)
jne    120c <mode_has_arg+0xfc>
movl   $0x1,-0x4(%rbp)
jmp    1213 <mode_has_arg+0x103>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mode_has_arg>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%r14d
mov    %rdi,%rbp
call   1030 <strchr@plt>
test   %rax,%rax
je     1168 <mode_has_arg+0x58>
mov    %rax,%rbx
mov    %rbp,%rdi
mov    $0x2c,%esi
call   1030 <strchr@plt>
mov    %rax,%rbp
test   %rax,%rax
je     116f <mode_has_arg+0x5f>
lea    0x1(%rbp),%rdi
mov    $0x2c,%esi
call   1030 <strchr@plt>
test   %rax,%rax
je     116f <mode_has_arg+0x5f>
mov    %rax,%r15
mov    %rax,%rdi
add    $0x1,%rdi
mov    $0x2c,%esi
call   1030 <strchr@plt>
jmp    1174 <mode_has_arg+0x64>
mov    $0xffffffff,%ecx
jmp    119a <mode_has_arg+0x8a>
xor    %r15d,%r15d
xor    %eax,%eax
mov    $0x2,%ecx
cmp    %rbp,%rbx
jb     119a <mode_has_arg+0x8a>
mov    $0x1,%ecx
cmp    %r15,%rbx
jb     119a <mode_has_arg+0x8a>
cmp    %rax,%rbx
setb   %al
cmp    $0x1,%r14d
sete   %cl
and    %al,%cl
movzbl %cl,%ecx
mov    %ecx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @mode_has_arg(i8* %0, i8 signext %1, i32 %2) {
%4 = tail call i8* @strchr(i8* dereferenceable(1) %0, i8 signext %1)
%5 = icmp eq i8* %4, null
br i1 %5, label %27, label %6
6: ; preds = %3
%7 = tail call i8* @strchr(i8* dereferenceable(1) %0, i8 signext 44)
%8 = icmp eq i8* %7, null
br i1 %8, label %16, label %9
9: ; preds = %6
%10 = getelementptr inbounds i8, i8* %7, i64 1
%11 = tail call i8* @strchr(i8* %10, i8 signext 44)
%12 = icmp eq i8* %11, null
br i1 %12, label %16, label %13
13: ; preds = %9
%14 = getelementptr inbounds i8, i8* %11, i64 1
%15 = tail call i8* @strchr(i8* %14, i8 signext 44)
br label %16
16: ; preds = %9, %13, %6
%17 = phi i8* [ %11, %13 ], [ null, %9 ], [ null, %6 ]
%18 = phi i8* [ %15, %13 ], [ null, %9 ], [ null, %6 ]
%19 = icmp ult i8* %4, %7
br i1 %19, label %27, label %20
20: ; preds = %16
%21 = icmp ult i8* %4, %17
br i1 %21, label %27, label %22
22: ; preds = %20
%23 = icmp ult i8* %4, %18
%24 = icmp eq i32 %2, 1
%25 = and i1 %24, %23
%26 = zext i1 %25 to i32
br label %27
27: ; preds = %22, %20, %16, %3
%28 = phi i32 [ -1, %3 ], [ 2, %16 ], [ 1, %20 ], [ %26, %22 ]
ret i32 %28
}