#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 */
char *strchr(char *, char);
char *uwsgi_concat2(char *, char *);
int /*<<< orphan*/ uwsgi_exit(int);
struct uwsgi_legion *uwsgi_legion_get_by_name(char *);
int /*<<< orphan*/ uwsgi_legion_register_node(struct uwsgi_legion *, char *);
int /*<<< orphan*/ uwsgi_log(char *, ...);
void uwsgi_opt_legion_node(char *opt, char *value, void *foobar) {
  char *legion = uwsgi_concat2(value, (char *)"");
  char *space = strchr(legion, ' ');
  if (!space) {
    uwsgi_log("invalid legion-node syntax, must be <legion> <addr>\n");
    uwsgi_exit(1);
  }
  *space = 0;
  struct uwsgi_legion *ul = uwsgi_legion_get_by_name(legion);
  if (!ul) {
    uwsgi_log("unknown legion: %s\n", legion);
    uwsgi_exit(1);
  }
  uwsgi_legion_register_node(ul, space + 1);
}


x86 assembly (clang, -O0):
<uwsgi_opt_legion_node>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xeb5(%rip),%rsi
call   1080 <uwsgi_concat2@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    $0x20,%esi
call   1040 <strchr@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11bd <uwsgi_opt_legion_node+0x5d>
lea    0xe54(%rip),%rdi
mov    $0x0,%al
call   1060 <uwsgi_log@plt>
mov    $0x1,%edi
call   1070 <uwsgi_exit@plt>
mov    -0x28(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x20(%rbp),%rdi
call   1030 <uwsgi_legion_get_by_name@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    11f8 <uwsgi_opt_legion_node+0x98>
mov    -0x20(%rbp),%rsi
lea    0xe4e(%rip),%rdi
mov    $0x0,%al
call   1060 <uwsgi_log@plt>
mov    $0x1,%edi
call   1070 <uwsgi_exit@plt>
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%rsi
add    $0x1,%rsi
call   1050 <uwsgi_legion_register_node@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<uwsgi_opt_legion_node>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%rdi
lea    0xec5(%rip),%rsi
call   1080 <uwsgi_concat2@plt>
mov    %rax,%r14
mov    %rax,%rdi
mov    $0x20,%esi
call   1040 <strchr@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    11a4 <uwsgi_opt_legion_node+0x44>
lea    0xe6d(%rip),%rdi
xor    %eax,%eax
call   1060 <uwsgi_log@plt>
mov    $0x1,%edi
call   1070 <uwsgi_exit@plt>
movb   $0x0,(%rbx)
mov    %r14,%rdi
call   1030 <uwsgi_legion_get_by_name@plt>
mov    %rax,%r15
test   %rax,%rax
jne    11d2 <uwsgi_opt_legion_node+0x72>
lea    0xe77(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1060 <uwsgi_log@plt>
mov    $0x1,%edi
call   1070 <uwsgi_exit@plt>
add    $0x1,%rbx
mov    %r15,%rdi
mov    %rbx,%rsi
pop    %rbx
pop    %r14
pop    %r15
jmp    1050 <uwsgi_legion_register_node@plt>

LLVM IR (-O0):
%struct.uwsgi_legion = type { i32 }
@.str = [1 x i8] zeroinitializer
@.str.1 = [53 x i8] c"invalid legion-node syntax, must be <legion> <addr>\0A\00"
@.str.2 = [20 x i8] c"unknown legion: %s\0A\00"
define void @uwsgi_opt_legion_node(i8* %0, i8* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca %struct.uwsgi_legion*
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8* %2, i8** %6
%10 = load i8*, i8** %5
%11 = call i8* @uwsgi_concat2(i8* %10, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
store i8* %11, i8** %7
%12 = load i8*, i8** %7
%13 = call i8* @strchr(i8* %12, i8 signext 32)
store i8* %13, i8** %8
%14 = load i8*, i8** %8
%15 = icmp ne i8* %14, null
br i1 %15, label %19, label %16
16: ; preds = %3
%17 = call i32 (i8*, ...) @uwsgi_log(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.1, i64 0, i64 0))
%18 = call i32 @uwsgi_exit(i32 1)
br label %19
19: ; preds = %16, %3
%20 = load i8*, i8** %8
store i8 0, i8* %20
%21 = load i8*, i8** %7
%22 = call %struct.uwsgi_legion* @uwsgi_legion_get_by_name(i8* %21)
store %struct.uwsgi_legion* %22, %struct.uwsgi_legion** %9
%23 = load %struct.uwsgi_legion*, %struct.uwsgi_legion** %9
%24 = icmp ne %struct.uwsgi_legion* %23, null
br i1 %24, label %29, label %25
25: ; preds = %19
%26 = load i8*, i8** %7
%27 = call i32 (i8*, ...) @uwsgi_log(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8* %26)
%28 = call i32 @uwsgi_exit(i32 1)
br label %29
29: ; preds = %25, %19
%30 = load %struct.uwsgi_legion*, %struct.uwsgi_legion** %9
%31 = load i8*, i8** %8
%32 = getelementptr inbounds i8, i8* %31, i64 1
%33 = call i32 @uwsgi_legion_register_node(%struct.uwsgi_legion* %30, i8* %32)
ret void
}

LLVM IR (-O2):
%struct.uwsgi_legion = type { i32 }
@.str = [1 x i8] zeroinitializer
@.str.1 = [53 x i8] c"invalid legion-node syntax, must be <legion> <addr>\0A\00"
@.str.2 = [20 x i8] c"unknown legion: %s\0A\00"
define void @uwsgi_opt_legion_node(i8* nocapture readnone %0, i8* %1, i8* nocapture readnone %2) {
%4 = tail call i8* @uwsgi_concat2(i8* %1, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%5 = tail call i8* @strchr(i8* dereferenceable(1) %4, i8 signext 32)
%6 = icmp eq i8* %5, null
br i1 %6, label %7, label %10
7: ; preds = %3
%8 = tail call i32 (i8*, ...) @uwsgi_log(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.1, i64 0, i64 0))
%9 = tail call i32 @uwsgi_exit(i32 1)
br label %10
10: ; preds = %7, %3
store i8 0, i8* %5
%11 = tail call %struct.uwsgi_legion* @uwsgi_legion_get_by_name(i8* %4)
%12 = icmp eq %struct.uwsgi_legion* %11, null
br i1 %12, label %13, label %16
13: ; preds = %10
%14 = tail call i32 (i8*, ...) @uwsgi_log(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8* %4)
%15 = tail call i32 @uwsgi_exit(i32 1)
br label %16
16: ; preds = %13, %10
%17 = getelementptr inbounds i8, i8* %5, i64 1
%18 = tail call i32 @uwsgi_legion_register_node(%struct.uwsgi_legion* %11, i8* %17)
ret void
}