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

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ skynet_context_dispatchall(struct skynet_context *);
struct skynet_context *skynet_context_new(char *, char *);
int /*<<< orphan*/ skynet_error(int /*<<< orphan*/ *, char *, char const *);
int /*<<< orphan*/ sscanf(char const *, char *, char *, char *);
int strlen(char const *);
void bootstrap(struct skynet_context *logger, const char *cmdline) {
  int sz = strlen(cmdline);
  char name[sz + 1];
  char args[sz + 1];
  sscanf(cmdline, "%s %s", name, args);
  struct skynet_context *ctx = skynet_context_new(name, args);
  if (ctx == NULL) {
    skynet_error(NULL, "Bootstrap error : %s\n", cmdline);
    skynet_context_dispatchall(logger);
    exit(1);
  }
}


x86 assembly (clang, -O0):
<bootstrap>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdx
sub    %rcx,%rdx
mov    %rdx,-0x48(%rbp)
mov    %rdx,%rsp
mov    %rax,-0x28(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %rax,%rsi
add    $0xf,%rsi
and    $0xfffffffffffffff0,%rsi
mov    %rsp,%rcx
sub    %rsi,%rcx
mov    %rcx,-0x40(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe2e(%rip),%rsi
call   1070 <sscanf@plt>
mov    -0x48(%rbp),%rdi
mov    -0x40(%rbp),%rsi
call   1060 <skynet_context_new@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    121a <bootstrap+0xba>
mov    -0x10(%rbp),%rdx
xor    %eax,%eax
mov    %eax,%edi
lea    0xe04(%rip),%rsi
call   1040 <skynet_error@plt>
mov    -0x8(%rbp),%rdi
call   1050 <skynet_context_dispatchall@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bootstrap>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r15
mov    %rdi,%r14
mov    %rsi,%rdi
call   1030 <strlen@plt>
add    $0x1,%eax
mov    %rsp,%r12
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r12
mov    %r12,%rsp
mov    %rsp,%rbx
sub    %rax,%rbx
mov    %rbx,%rsp
lea    0xe63(%rip),%rsi
mov    %r15,%rdi
mov    %r12,%rdx
mov    %rbx,%rcx
call   1070 <sscanf@plt>
mov    %r12,%rdi
mov    %rbx,%rsi
call   1060 <skynet_context_new@plt>
test   %rax,%rax
je     11c8 <bootstrap+0x68>
lea    -0x20(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe37(%rip),%rsi
xor    %edi,%edi
mov    %r15,%rdx
call   1040 <skynet_error@plt>
mov    %r14,%rdi
call   1050 <skynet_context_dispatchall@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
%struct.skynet_context = type { i32 }
@.str = [6 x i8] c"%s %s\00"
@.str.1 = [22 x i8] c"Bootstrap error : %s\0A\00"
define void @bootstrap(%struct.skynet_context* %0, i8* %1) {
%3 = alloca %struct.skynet_context*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i64
%9 = alloca %struct.skynet_context*
store %struct.skynet_context* %0, %struct.skynet_context** %3
store i8* %1, i8** %4
%10 = load i8*, i8** %4
%11 = call i32 @strlen(i8* %10)
store i32 %11, i32* %5
%12 = load i32, i32* %5
%13 = add nsw i32 %12, 1
%14 = zext i32 %13 to i64
%15 = call i8* @llvm.stacksave()
store i8* %15, i8** %6
%16 = alloca i8, i64 %14
store i64 %14, i64* %7
%17 = load i32, i32* %5
%18 = add nsw i32 %17, 1
%19 = zext i32 %18 to i64
%20 = alloca i8, i64 %19
store i64 %19, i64* %8
%21 = load i8*, i8** %4
%22 = call i32 @sscanf(i8* %21, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %16, i8* %20)
%23 = call %struct.skynet_context* @skynet_context_new(i8* %16, i8* %20)
store %struct.skynet_context* %23, %struct.skynet_context** %9
%24 = load %struct.skynet_context*, %struct.skynet_context** %9
%25 = icmp eq %struct.skynet_context* %24, null
br i1 %25, label %26, label %32
26: ; preds = %2
%27 = load i8*, i8** %4
%28 = call i32 @skynet_error(i32* null, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8* %27)
%29 = load %struct.skynet_context*, %struct.skynet_context** %3
%30 = call i32 @skynet_context_dispatchall(%struct.skynet_context* %29)
%31 = call i32 @exit(i32 1)
unreachable
32: ; preds = %2
%33 = load i8*, i8** %6
ret void
}

LLVM IR (-O2):
%struct.skynet_context = type { i32 }
@.str = [6 x i8] c"%s %s\00"
@.str.1 = [22 x i8] c"Bootstrap error : %s\0A\00"
define void @bootstrap(%struct.skynet_context* %0, i8* %1) {
%3 = tail call i32 @strlen(i8* %1)
%4 = add nsw i32 %3, 1
%5 = zext i32 %4 to i64
%6 = alloca i8, i64 %5
%7 = alloca i8, i64 %5
%8 = call i32 @sscanf(i8* %1, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %6, i8* %7)
%9 = call %struct.skynet_context* @skynet_context_new(i8* %6, i8* %7)
%10 = icmp eq %struct.skynet_context* %9, null
br i1 %10, label %11, label %15
11: ; preds = %2
%12 = call i32 @skynet_error(i32* null, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8* %1)
%13 = call i32 @skynet_context_dispatchall(%struct.skynet_context* %0)
%14 = call i32 @exit(i32 1)
unreachable
15: ; preds = %2
ret void
}