#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*/ 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);
  }
  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    0x2e3d(%rip),%rax
mov    (%rax),%edi
call   1050 <setlinebuf@plt>
mov    0x2e0f(%rip),%rax
mov    (%rax),%edi
call   1050 <setlinebuf@plt>
mov    $0x0,%al
call   1080 <read_environment@plt>
cmp    $0x0,%rax
je     1209 <main+0x89>
mov    0x2e00(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    0x2dec(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    -0x24(%rbp),%edi
mov    %rax,%rdx
lea    0xe08(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
lea    0xe10(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1251 <main+0xd1>
mov    -0x18(%rbp),%rdi
lea    0xdfe(%rip),%rsi
lea    -0x1c(%rbp),%rdx
lea    -0x20(%rbp),%rcx
call   1070 <sscanf@plt>
cmp    $0x2,%eax
je     124c <main+0xcc>
movl   $0x0,-0x1c(%rbp)
jmp    1251 <main+0xd1>
cmpl   $0x1,-0x1c(%rbp)
jge    127c <main+0xfc>
mov    0x2d76(%rip),%rax
mov    (%rax),%edi
lea    0xdc8(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    $0x0,%al
call   1040 <run_script@plt>
cmp    $0x0,%rax
je     1298 <main+0x118>
mov    $0xffffffff,%eax
add    $0x30,%rsp
pop    %rbp
ret
xor    %edi,%edi
call   1090 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
movl   $0x0,0x8(%rsp)
movl   $0x0,0xc(%rsp)
mov    0x2e4c(%rip),%rax
mov    (%rax),%edi
call   1050 <setlinebuf@plt>
mov    0x2e1e(%rip),%rax
mov    (%rax),%edi
call   1050 <setlinebuf@plt>
xor    %eax,%eax
call   1080 <read_environment@plt>
test   %rax,%rax
jne    120a <main+0x8a>
lea    0xe5c(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     1246 <main+0xc6>
lea    0xe58(%rip),%rsi
lea    0x8(%rsp),%rdx
lea    0xc(%rsp),%rcx
mov    %rax,%rdi
call   1070 <sscanf@plt>
cmp    $0x2,%eax
jne    123e <main+0xbe>
cmpl   $0x0,0x8(%rsp)
jle    1246 <main+0xc6>
xor    %eax,%eax
call   1040 <run_script@plt>
test   %rax,%rax
je     1267 <main+0xe7>
mov    $0xffffffff,%eax
add    $0x10,%rsp
pop    %rbx
ret
mov    0x2dc7(%rip),%rax
mov    (%rax),%ebx
mov    0x2db6(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
lea    0xdd8(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
movl   $0x0,0x8(%rsp)
mov    0x2d8b(%rip),%rax
mov    (%rax),%edi
lea    0xddd(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
xor    %edi,%edi
call   1090 <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 i8* @getenv(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
store i8* %22, i8** %6
%23 = load i8*, i8** %6
%24 = icmp ne i8* %23, null
br i1 %24, label %25, label %31
25: ; preds = %21
%26 = load i8*, i8** %6
%27 = call i32 @sscanf(i8* %26, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32* %7, i32* %8)
%28 = icmp ne i32 %27, 2
br i1 %28, label %29, label %30
29: ; preds = %25
store i32 0, i32* %7
br label %30
30: ; preds = %29, %25
br label %31
31: ; preds = %30, %21
%32 = load i32, i32* %7
%33 = icmp slt i32 %32, 1
br i1 %33, label %34, label %38
34: ; preds = %31
%35 = load i32, i32* @stderr
%36 = call i32 (i32, i8*, ...) @fprintf(i32 %35, i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.3, i64 0, i64 0))
%37 = call i32 @exit(i32 1)
unreachable
38: ; preds = %31
%39 = call i64 (...) @run_script()
%40 = icmp ne i64 %39, 0
br i1 %40, label %41, label %42
41: ; preds = %38
ret i32 -1
42: ; preds = %38
%43 = 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 i8* @getenv(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%21 = icmp eq i8* %20, null
br i1 %21, label %29, label %22
22: ; preds = %19
%23 = call i32 @sscanf(i8* %20, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32* %3, i32* %4)
%24 = icmp eq i32 %23, 2
br i1 %24, label %26, label %25
25: ; preds = %22
store i32 0, i32* %3
br label %29
26: ; preds = %22
%27 = load i32, i32* %3
%28 = icmp slt i32 %27, 1
br i1 %28, label %29, label %33
29: ; preds = %19, %25, %26
%30 = load i32, i32* @stderr
%31 = call i32 (i32, i8*, ...) @fprintf(i32 %30, i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.3, i64 0, i64 0))
%32 = call i32 @exit(i32 1)
unreachable
33: ; preds = %26
%34 = call i64 (...) @run_script()
%35 = icmp eq i64 %34, 0
br i1 %35, label %37, label %36
36: ; preds = %33
ret i32 -1
37: ; preds = %33
%38 = call i32 @exit(i32 0)
unreachable
}