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

/* Variables and functions */
int /*<<< orphan*/ exec_init_script(int, char **, struct objlist *, int);
int /*<<< orphan*/ exit(int);
char *get_login_shell(struct objlist *);
int /*<<< orphan*/ ngraph_exec_loginshell(char *, struct objlist *, int);
int /*<<< orphan*/ ngraph_finalize();
int /*<<< orphan*/ ngraph_free(char *);
struct objlist *ngraph_get_object(char *);
scalar_t__ ngraph_initialize(int *, char ***);
int /*<<< orphan*/ ngraph_object_del(struct objlist *, int /*<<< orphan*/);
int ngraph_object_new(struct objlist *);
int main(int argc, char **argv) {
  char *loginshell;
  struct objlist *sys, *obj;
  int id;
  if (ngraph_initialize(&argc, &argv)) {
    exit(1);
  }
  sys = ngraph_get_object("system");
  obj = ngraph_get_object("shell");
  if (obj == NULL || sys == NULL) {
    exit(1);
  }
  id = ngraph_object_new(obj);
  if (id < 0) {
    exit(1);
  }
  exec_init_script(argc, argv, obj, id);
  loginshell = get_login_shell(sys);
  if (loginshell) {
    ngraph_exec_loginshell(loginshell, obj, id);
    ngraph_free(loginshell);
  }
  ngraph_finalize();
  ngraph_object_del(sys, 0);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x8(%rbp),%rdi
lea    -0x10(%rbp),%rsi
call   1080 <ngraph_initialize@plt>
cmp    $0x0,%rax
je     11d7 <main+0x37>
mov    $0x1,%edi
call   10c0 <exit@plt>
lea    0xe22(%rip),%rdi
call   1050 <ngraph_get_object@plt>
mov    %rax,-0x20(%rbp)
lea    0xe19(%rip),%rdi
call   1050 <ngraph_get_object@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     120d <main+0x6d>
cmpq   $0x0,-0x20(%rbp)
jne    1217 <main+0x77>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    -0x28(%rbp),%rdi
call   1060 <ngraph_object_new@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jge    1237 <main+0x97>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x28(%rbp),%rdx
mov    -0x2c(%rbp),%ecx
call   1090 <exec_init_script@plt>
mov    -0x20(%rbp),%rdi
call   10a0 <get_login_shell@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     127b <main+0xdb>
mov    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x2c(%rbp),%edx
call   1040 <ngraph_exec_loginshell@plt>
mov    -0x18(%rbp),%rdi
call   10b0 <ngraph_free@plt>
mov    $0x0,%al
call   1030 <ngraph_finalize@plt>
mov    -0x20(%rbp),%rdi
xor    %esi,%esi
call   1070 <ngraph_object_del@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %edi,0xc(%rsp)
mov    %rsi,0x10(%rsp)
lea    0xc(%rsp),%rdi
lea    0x10(%rsp),%rsi
call   1080 <ngraph_initialize@plt>
test   %rax,%rax
jne    1259 <main+0xb9>
lea    0xe2e(%rip),%rdi
call   1050 <ngraph_get_object@plt>
mov    %rax,%r14
lea    0xe26(%rip),%rdi
call   1050 <ngraph_get_object@plt>
test   %rax,%rax
je     1259 <main+0xb9>
test   %r14,%r14
je     1259 <main+0xb9>
mov    %rax,%rbx
mov    %rax,%rdi
call   1060 <ngraph_object_new@plt>
test   %eax,%eax
js     1259 <main+0xb9>
mov    %eax,%r15d
mov    0xc(%rsp),%edi
mov    0x10(%rsp),%rsi
mov    %rbx,%rdx
mov    %eax,%ecx
call   1090 <exec_init_script@plt>
mov    %r14,%rdi
call   10a0 <get_login_shell@plt>
test   %rax,%rax
je     123b <main+0x9b>
mov    %rax,%rbp
mov    %rax,%rdi
mov    %rbx,%rsi
mov    %r15d,%edx
call   1040 <ngraph_exec_loginshell@plt>
mov    %rbp,%rdi
call   10b0 <ngraph_free@plt>
xor    %eax,%eax
call   1030 <ngraph_finalize@plt>
mov    %r14,%rdi
xor    %esi,%esi
call   1070 <ngraph_object_del@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0x1,%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
%struct.objlist = type { i32 }
@.str = [7 x i8] c"system\00"
@.str.1 = [6 x i8] c"shell\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca %struct.objlist*
%8 = alloca %struct.objlist*
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = call i64 @ngraph_initialize(i32* %4, i8*** %5)
%11 = icmp ne i64 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %2
%13 = call i32 @exit(i32 1)
unreachable
14: ; preds = %2
%15 = call %struct.objlist* @ngraph_get_object(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
store %struct.objlist* %15, %struct.objlist** %7
%16 = call %struct.objlist* @ngraph_get_object(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
store %struct.objlist* %16, %struct.objlist** %8
%17 = load %struct.objlist*, %struct.objlist** %8
%18 = icmp eq %struct.objlist* %17, null
br i1 %18, label %22, label %19
19: ; preds = %14
%20 = load %struct.objlist*, %struct.objlist** %7
%21 = icmp eq %struct.objlist* %20, null
br i1 %21, label %22, label %24
22: ; preds = %19, %14
%23 = call i32 @exit(i32 1)
unreachable
24: ; preds = %19
%25 = load %struct.objlist*, %struct.objlist** %8
%26 = call i32 @ngraph_object_new(%struct.objlist* %25)
store i32 %26, i32* %9
%27 = load i32, i32* %9
%28 = icmp slt i32 %27, 0
br i1 %28, label %29, label %31
29: ; preds = %24
%30 = call i32 @exit(i32 1)
unreachable
31: ; preds = %24
%32 = load i32, i32* %4
%33 = load i8**, i8*** %5
%34 = load %struct.objlist*, %struct.objlist** %8
%35 = load i32, i32* %9
%36 = call i32 @exec_init_script(i32 %32, i8** %33, %struct.objlist* %34, i32 %35)
%37 = load %struct.objlist*, %struct.objlist** %7
%38 = call i8* @get_login_shell(%struct.objlist* %37)
store i8* %38, i8** %6
%39 = load i8*, i8** %6
%40 = icmp ne i8* %39, null
br i1 %40, label %41, label %48
41: ; preds = %31
%42 = load i8*, i8** %6
%43 = load %struct.objlist*, %struct.objlist** %8
%44 = load i32, i32* %9
%45 = call i32 @ngraph_exec_loginshell(i8* %42, %struct.objlist* %43, i32 %44)
%46 = load i8*, i8** %6
%47 = call i32 @ngraph_free(i8* %46)
br label %48
48: ; preds = %41, %31
%49 = call i32 (...) @ngraph_finalize()
%50 = load %struct.objlist*, %struct.objlist** %7
%51 = call i32 @ngraph_object_del(%struct.objlist* %50, i32 0)
ret i32 0
}

LLVM IR (-O2):
%struct.objlist = type { i32 }
@.str = [7 x i8] c"system\00"
@.str.1 = [6 x i8] c"shell\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
store i32 %0, i32* %3
store i8** %1, i8*** %4
%5 = call i64 @ngraph_initialize(i32* %3, i8*** %4)
%6 = icmp eq i64 %5, 0
br i1 %6, label %9, label %7
7: ; preds = %2
%8 = call i32 @exit(i32 1)
unreachable
9: ; preds = %2
%10 = call %struct.objlist* @ngraph_get_object(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%11 = call %struct.objlist* @ngraph_get_object(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%12 = icmp eq %struct.objlist* %11, null
%13 = icmp eq %struct.objlist* %10, null
%14 = select i1 %12, i1 true, i1 %13
br i1 %14, label %15, label %17
15: ; preds = %9
%16 = call i32 @exit(i32 1)
unreachable
17: ; preds = %9
%18 = call i32 @ngraph_object_new(%struct.objlist* %11)
%19 = icmp slt i32 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %17
%21 = call i32 @exit(i32 1)
unreachable
22: ; preds = %17
%23 = load i32, i32* %3
%24 = load i8**, i8*** %4
%25 = call i32 @exec_init_script(i32 %23, i8** %24, %struct.objlist* %11, i32 %18)
%26 = call i8* @get_login_shell(%struct.objlist* %10)
%27 = icmp eq i8* %26, null
br i1 %27, label %31, label %28
28: ; preds = %22
%29 = call i32 @ngraph_exec_loginshell(i8* %26, %struct.objlist* %11, i32 %18)
%30 = call i32 @ngraph_free(i8* %26)
br label %31
31: ; preds = %28, %22
%32 = call i32 (...) @ngraph_finalize()
%33 = call i32 @ngraph_object_del(%struct.objlist* %10, i32 0)
ret i32 0
}