#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 */
int /*<<< orphan*/ connect_sphinx();
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
char *getenv(char *);
scalar_t__ read_environment();
scalar_t__ run_script();
int /*<<< orphan*/ setlinebuf(int /*<<< orphan*/);
int sscanf(char *, char *, int *, int *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ stdout;
char *strerror(int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  char *tmp;
  int ver = 0;
  int subver = 0;
  setlinebuf(stdin);
  setlinebuf(stdout);
  if (read_environment()) {
    fprintf(stderr, "Failed to read environment: %s\n", strerror(errno));
    exit(1);
  }
  connect_sphinx();
  tmp = getenv("agi_enhanced");
  if (tmp) {
    if (sscanf(tmp, "%d.%d", &ver, &subver) != 2)
      ver = 0;
  }
  if (ver < 1) {
    fprintf(stderr, "No enhanced AGI services available.  Use EAGI, not AGI\n");
    exit(1);
  }
  if (run_script())
    return -1;
  exit(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)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
mov    0x2e2d(%rip),%rax
mov    (%rax),%edi
call   1050 <setlinebuf@plt>
mov    0x2dff(%rip),%rax
mov    (%rax),%edi
call   1050 <setlinebuf@plt>
mov    $0x0,%al
call   1080 <read_environment@plt>
cmp    $0x0,%rax
je     1219 <main+0x89>
mov    0x2df0(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    0x2ddc(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
mov    -0x24(%rbp),%edi
mov    %rax,%rdx
lea    0xdf8(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    $0x0,%al
call   1090 <connect_sphinx@plt>
lea    0xdf9(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1268 <main+0xd8>
mov    -0x18(%rbp),%rdi
lea    0xde7(%rip),%rsi
lea    -0x1c(%rbp),%rdx
lea    -0x20(%rbp),%rcx
call   1070 <sscanf@plt>
cmp    $0x2,%eax
je     1263 <main+0xd3>
movl   $0x0,-0x1c(%rbp)
jmp    1268 <main+0xd8>
cmpl   $0x1,-0x1c(%rbp)
jge    1293 <main+0x103>
mov    0x2d5f(%rip),%rax
mov    (%rax),%edi
lea    0xdb1(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    $0x0,%al
call   1040 <run_script@plt>
cmp    $0x0,%rax
je     12af <main+0x11f>
mov    $0xffffffff,%eax
add    $0x30,%rsp
pop    %rbp
ret
xor    %edi,%edi
call   10a0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
movl   $0x0,0x8(%rsp)
movl   $0x0,0xc(%rsp)
mov    0x2e3c(%rip),%rax
mov    (%rax),%edi
call   1050 <setlinebuf@plt>
mov    0x2e0e(%rip),%rax
mov    (%rax),%edi
call   1050 <setlinebuf@plt>
xor    %eax,%eax
call   1080 <read_environment@plt>
test   %rax,%rax
jne    1221 <main+0x91>
xor    %eax,%eax
call   1090 <connect_sphinx@plt>
lea    0xe45(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     125d <main+0xcd>
lea    0xe41(%rip),%rsi
lea    0x8(%rsp),%rdx
lea    0xc(%rsp),%rcx
mov    %rax,%rdi
call   1070 <sscanf@plt>
cmp    $0x2,%eax
jne    1255 <main+0xc5>
cmpl   $0x0,0x8(%rsp)
jle    125d <main+0xcd>
xor    %eax,%eax
call   1040 <run_script@plt>
test   %rax,%rax
je     127e <main+0xee>
mov    $0xffffffff,%eax
add    $0x10,%rsp
pop    %rbx
ret
mov    0x2db0(%rip),%rax
mov    (%rax),%ebx
mov    0x2d9f(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
lea    0xdc1(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
movl   $0x0,0x8(%rsp)
mov    0x2d74(%rip),%rax
mov    (%rax),%edi
lea    0xdc6(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
xor    %edi,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@stdin = global i32 0
@stdout = global i32 0
@stderr = global i32 0
@.str = [32 x i8] c"Failed to read environment: %s\0A\00"
@errno = global i32 0
@.str.1 = [13 x i8] c"agi_enhanced\00"
@.str.2 = [6 x i8] c"%d.%d\00"
@.str.3 = [56 x i8] c"No enhanced AGI services available. Use EAGI, not AGI\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %7
store i32 0, i32* %8
%9 = load i32, i32* @stdin
%10 = call i32 @setlinebuf(i32 %9)
%11 = load i32, i32* @stdout
%12 = call i32 @setlinebuf(i32 %11)
%13 = call i64 (...) @read_environment()
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %21
15: ; preds = %2
%16 = load i32, i32* @stderr
%17 = load i32, i32* @errno
%18 = call i8* @strerror(i32 %17)
%19 = call i32 (i32, i8*, ...) @fprintf(i32 %16, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8* %18)
%20 = call i32 @exit(i32 1)
unreachable
21: ; preds = %2
%22 = call i32 (...) @connect_sphinx()
%23 = call i8* @getenv(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
store i8* %23, i8** %6
%24 = load i8*, i8** %6
%25 = icmp ne i8* %24, null
br i1 %25, label %26, label %32
26: ; preds = %21
%27 = load i8*, i8** %6
%28 = call i32 @sscanf(i8* %27, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32* %7, i32* %8)
%29 = icmp ne i32 %28, 2
br i1 %29, label %30, label %31
30: ; preds = %26
store i32 0, i32* %7
br label %31
31: ; preds = %30, %26
br label %32
32: ; preds = %31, %21
%33 = load i32, i32* %7
%34 = icmp slt i32 %33, 1
br i1 %34, label %35, label %39
35: ; preds = %32
%36 = load i32, i32* @stderr
%37 = call i32 (i32, i8*, ...) @fprintf(i32 %36, i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.3, i64 0, i64 0))
%38 = call i32 @exit(i32 1)
unreachable
39: ; preds = %32
%40 = call i64 (...) @run_script()
%41 = icmp ne i64 %40, 0
br i1 %41, label %42, label %43
42: ; preds = %39
ret i32 -1
43: ; preds = %39
%44 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@stdin = global i32 0
@stdout = global i32 0
@stderr = global i32 0
@.str = [32 x i8] c"Failed to read environment: %s\0A\00"
@errno = global i32 0
@.str.1 = [13 x i8] c"agi_enhanced\00"
@.str.2 = [6 x i8] c"%d.%d\00"
@.str.3 = [56 x i8] c"No enhanced AGI services available. Use EAGI, not AGI\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = alloca i32
%5 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%6 = bitcast i32* %4 to i8*
store i32 0, i32* %4
%7 = load i32, i32* @stdin
%8 = tail call i32 @setlinebuf(i32 %7)
%9 = load i32, i32* @stdout
%10 = tail call i32 @setlinebuf(i32 %9)
%11 = tail call i64 (...) @read_environment()
%12 = icmp eq i64 %11, 0
br i1 %12, label %19, label %13
13: ; preds = %2
%14 = load i32, i32* @stderr
%15 = load i32, i32* @errno
%16 = tail call i8* @strerror(i32 %15)
%17 = tail call i32 (i32, i8*, ...) @fprintf(i32 %14, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8* %16)
%18 = tail call i32 @exit(i32 1)
unreachable
19: ; preds = %2
%20 = tail call i32 (...) @connect_sphinx()
%21 = tail call i8* @getenv(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%22 = icmp eq i8* %21, null
br i1 %22, label %30, label %23
23: ; preds = %19
%24 = call i32 @sscanf(i8* %21, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32* %3, i32* %4)
%25 = icmp eq i32 %24, 2
br i1 %25, label %27, label %26
26: ; preds = %23
store i32 0, i32* %3
br label %30
27: ; preds = %23
%28 = load i32, i32* %3
%29 = icmp slt i32 %28, 1
br i1 %29, label %30, label %34
30: ; preds = %19, %26, %27
%31 = load i32, i32* @stderr
%32 = call i32 (i32, i8*, ...) @fprintf(i32 %31, i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.3, i64 0, i64 0))
%33 = call i32 @exit(i32 1)
unreachable
34: ; preds = %27
%35 = call i64 (...) @run_script()
%36 = icmp eq i64 %35, 0
br i1 %36, label %38, label %37
37: ; preds = %34
ret i32 -1
38: ; preds = %34
%39 = call i32 @exit(i32 0)
unreachable
}