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

/* Variables and functions */
int /*<<< orphan*/ exit(int);
char *strchr(char *, char);
char *uwsgi_concat2(char *, char *);
struct uwsgi_legion *uwsgi_legion_get_by_name(char *);
int /*<<< orphan*/ uwsgi_legion_register_hook(struct uwsgi_legion *, char *,
                                              char *);
int /*<<< orphan*/ uwsgi_log(char *, char *);
void uwsgi_opt_legion_hook(char *opt, char *value, void *foobar) {
  char *event = strchr(opt, '-');
  if (!event) {
    uwsgi_log("[uwsgi-legion] invalid option name (%s), this should not happen "
              "(possible bug)\n",
              opt);
    exit(1);
  }
  char *legion = uwsgi_concat2(value, (char *)"");
  char *space = strchr(legion, ' ');
  if (!space) {
    uwsgi_log("[uwsgi-legion] invalid %s syntax, must be <legion> <action>\n",
              opt);
    exit(1);
  }
  *space = 0;
  struct uwsgi_legion *ul = uwsgi_legion_get_by_name(legion);
  if (!ul) {
    uwsgi_log("[uwsgi-legion] unknown legion: %s\n", legion);
    exit(1);
  }
  uwsgi_legion_register_hook(ul, event + 1, space + 1);
}


x86 assembly (clang, -O0):
<uwsgi_opt_legion_hook>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x2d,%esi
call   1050 <strchr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11ab <uwsgi_opt_legion_hook+0x4b>
mov    -0x8(%rbp),%rsi
lea    0xe64(%rip),%rdi
call   1060 <uwsgi_log@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rdi
lea    0xe99(%rip),%rsi
call   1070 <uwsgi_concat2@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    $0x20,%esi
call   1050 <strchr@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    11f6 <uwsgi_opt_legion_hook+0x96>
mov    -0x8(%rbp),%rsi
lea    0xe69(%rip),%rdi
call   1060 <uwsgi_log@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x30(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x28(%rbp),%rdi
call   1030 <uwsgi_legion_get_by_name@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    122f <uwsgi_opt_legion_hook+0xcf>
mov    -0x28(%rbp),%rsi
lea    0xe6d(%rip),%rdi
call   1060 <uwsgi_log@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x38(%rbp),%rdi
mov    -0x20(%rbp),%rsi
add    $0x1,%rsi
mov    -0x30(%rbp),%rdx
add    $0x1,%rdx
call   1040 <uwsgi_legion_register_hook@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<uwsgi_opt_legion_hook>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r14
mov    $0x2d,%esi
call   1050 <strchr@plt>
test   %rax,%rax
je     11d8 <uwsgi_opt_legion_hook+0x78>
mov    %rax,%r12
lea    0xec8(%rip),%rsi
mov    %rbx,%rdi
call   1070 <uwsgi_concat2@plt>
mov    %rax,%r15
mov    %rax,%rdi
mov    $0x20,%esi
call   1050 <strchr@plt>
test   %rax,%rax
je     11e1 <uwsgi_opt_legion_hook+0x81>
mov    %rax,%rbx
movb   $0x0,(%rax)
mov    %r15,%rdi
call   1030 <uwsgi_legion_get_by_name@plt>
test   %rax,%rax
je     11ed <uwsgi_opt_legion_hook+0x8d>
add    $0x1,%r12
add    $0x1,%rbx
mov    %rax,%rdi
mov    %r12,%rsi
mov    %rbx,%rdx
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1040 <uwsgi_legion_register_hook@plt>
lea    0xe21(%rip),%rdi
jmp    11e8 <uwsgi_opt_legion_hook+0x88>
lea    0xe68(%rip),%rdi
mov    %r14,%rsi
jmp    11f7 <uwsgi_opt_legion_hook+0x97>
lea    0xe99(%rip),%rdi
mov    %r15,%rsi
call   1060 <uwsgi_log@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
%struct.uwsgi_legion = type { i32 }
@.str = [80 x i8] c"[uwsgi-legion] invalid option name (%s), this should not happen (possible bug)\0A\00"
@.str.1 = [1 x i8] zeroinitializer
@.str.2 = [61 x i8] c"[uwsgi-legion] invalid %s syntax, must be <legion> <action>\0A\00"
@.str.3 = [35 x i8] c"[uwsgi-legion] unknown legion: %s\0A\00"
define void @uwsgi_opt_legion_hook(i8* %0, i8* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca %struct.uwsgi_legion*
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8* %2, i8** %6
%11 = load i8*, i8** %4
%12 = call i8* @strchr(i8* %11, i8 signext 45)
store i8* %12, i8** %7
%13 = load i8*, i8** %7
%14 = icmp ne i8* %13, null
br i1 %14, label %19, label %15
15: ; preds = %3
%16 = load i8*, i8** %4
%17 = call i32 @uwsgi_log(i8* getelementptr inbounds ([80 x i8], [80 x i8]* @.str, i64 0, i64 0), i8* %16)
%18 = call i32 @exit(i32 1)
unreachable
19: ; preds = %3
%20 = load i8*, i8** %5
%21 = call i8* @uwsgi_concat2(i8* %20, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0))
store i8* %21, i8** %8
%22 = load i8*, i8** %8
%23 = call i8* @strchr(i8* %22, i8 signext 32)
store i8* %23, i8** %9
%24 = load i8*, i8** %9
%25 = icmp ne i8* %24, null
br i1 %25, label %30, label %26
26: ; preds = %19
%27 = load i8*, i8** %4
%28 = call i32 @uwsgi_log(i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.2, i64 0, i64 0), i8* %27)
%29 = call i32 @exit(i32 1)
unreachable
30: ; preds = %19
%31 = load i8*, i8** %9
store i8 0, i8* %31
%32 = load i8*, i8** %8
%33 = call %struct.uwsgi_legion* @uwsgi_legion_get_by_name(i8* %32)
store %struct.uwsgi_legion* %33, %struct.uwsgi_legion** %10
%34 = load %struct.uwsgi_legion*, %struct.uwsgi_legion** %10
%35 = icmp ne %struct.uwsgi_legion* %34, null
br i1 %35, label %40, label %36
36: ; preds = %30
%37 = load i8*, i8** %8
%38 = call i32 @uwsgi_log(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.3, i64 0, i64 0), i8* %37)
%39 = call i32 @exit(i32 1)
unreachable
40: ; preds = %30
%41 = load %struct.uwsgi_legion*, %struct.uwsgi_legion** %10
%42 = load i8*, i8** %7
%43 = getelementptr inbounds i8, i8* %42, i64 1
%44 = load i8*, i8** %9
%45 = getelementptr inbounds i8, i8* %44, i64 1
%46 = call i32 @uwsgi_legion_register_hook(%struct.uwsgi_legion* %41, i8* %43, i8* %45)
ret void
}

LLVM IR (-O2):
%struct.uwsgi_legion = type { i32 }
@.str = [80 x i8] c"[uwsgi-legion] invalid option name (%s), this should not happen (possible bug)\0A\00"
@.str.1 = [1 x i8] zeroinitializer
@.str.2 = [61 x i8] c"[uwsgi-legion] invalid %s syntax, must be <legion> <action>\0A\00"
@.str.3 = [35 x i8] c"[uwsgi-legion] unknown legion: %s\0A\00"
define void @uwsgi_opt_legion_hook(i8* %0, i8* %1, i8* nocapture readnone %2) {
%4 = tail call i8* @strchr(i8* dereferenceable(1) %0, i8 signext 45)
%5 = icmp eq i8* %4, null
br i1 %5, label %6, label %9
6: ; preds = %3
%7 = tail call i32 @uwsgi_log(i8* getelementptr inbounds ([80 x i8], [80 x i8]* @.str, i64 0, i64 0), i8* %0)
%8 = tail call i32 @exit(i32 1)
unreachable
9: ; preds = %3
%10 = tail call i8* @uwsgi_concat2(i8* %1, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0))
%11 = tail call i8* @strchr(i8* dereferenceable(1) %10, i8 signext 32)
%12 = icmp eq i8* %11, null
br i1 %12, label %13, label %16
13: ; preds = %9
%14 = tail call i32 @uwsgi_log(i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.2, i64 0, i64 0), i8* %0)
%15 = tail call i32 @exit(i32 1)
unreachable
16: ; preds = %9
store i8 0, i8* %11
%17 = tail call %struct.uwsgi_legion* @uwsgi_legion_get_by_name(i8* %10)
%18 = icmp eq %struct.uwsgi_legion* %17, null
br i1 %18, label %19, label %22
19: ; preds = %16
%20 = tail call i32 @uwsgi_log(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.3, i64 0, i64 0), i8* %10)
%21 = tail call i32 @exit(i32 1)
unreachable
22: ; preds = %16
%23 = getelementptr inbounds i8, i8* %4, i64 1
%24 = getelementptr inbounds i8, i8* %11, i64 1
%25 = tail call i32 @uwsgi_legion_register_hook(%struct.uwsgi_legion* %17, i8* %23, i8* %24)
ret void
}