#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char *);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ putenv(char *);
int /*<<< orphan*/ sprintf(char *, char *, int);
char *strerror(int /*<<< orphan*/);
scalar_t__ system(char *);
int /*<<< orphan*/ unlink(char *);
int main() {
  char i_string[255];
  int i;
  FILE *f;
  i = 5;
  sprintf(i_string, "i_string=%d", i);
  if (putenv(i_string) != 0)
    printf("putenv i_string failed: %s\n", strerror(errno));
  f = fopen("scripting_example.sp", "w");
  fprintf(f, "%s\n", "pragma restriction( no_external_commands );");
  fprintf(f, "%s\n", "pragma ada_95;");
  fprintf(f, "%s\n", "procedure scripting_example is");
  fprintf(f, "%s\n", "i : integer := numerics.value( i_string );");
  fprintf(f, "%s\n", "begin");
  fprintf(f, "%s\n", "put_line( i * 2 );");
  fprintf(f, "%s\n", "end scripting_example;");
  fclose(f);
  if (system("../spar scripting_example.sp") != 0) {
    printf("Oh, no.  There was an error in the script\n");
  } else {
    unlink("scripting_example.sp");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x5,-0x114(%rbp)
lea    -0x110(%rbp),%rdi
mov    -0x114(%rbp),%edx
lea    0xe40(%rip),%rsi
call   10a0 <sprintf@plt>
lea    -0x110(%rbp),%rdi
call   1070 <putenv@plt>
cmp    $0x0,%rax
je     11fa <main+0x6a>
mov    0x2dfe(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
mov    %rax,%rsi
lea    0xe19(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xee6(%rip),%rdi
lea    0xe20(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x120(%rbp)
mov    -0x120(%rbp),%rdi
lea    0xe02(%rip),%rsi
lea    0xe01(%rip),%rdx
call   1080 <fprintf@plt>
mov    -0x120(%rbp),%rdi
lea    0xde8(%rip),%rsi
lea    0xe13(%rip),%rdx
call   1080 <fprintf@plt>
mov    -0x120(%rbp),%rdi
lea    0xdce(%rip),%rsi
lea    0xe08(%rip),%rdx
call   1080 <fprintf@plt>
mov    -0x120(%rbp),%rdi
lea    0xdb4(%rip),%rsi
lea    0xe0d(%rip),%rdx
call   1080 <fprintf@plt>
mov    -0x120(%rbp),%rdi
lea    0xd9a(%rip),%rsi
lea    0xe1e(%rip),%rdx
call   1080 <fprintf@plt>
mov    -0x120(%rbp),%rdi
lea    0xd80(%rip),%rsi
lea    0xe0a(%rip),%rdx
call   1080 <fprintf@plt>
mov    -0x120(%rbp),%rdi
lea    0xd66(%rip),%rsi
lea    0xe03(%rip),%rdx
call   1080 <fprintf@plt>
mov    -0x120(%rbp),%rdi
call   1040 <fclose@plt>
lea    0xe02(%rip),%rdi
call   1050 <system@plt>
cmp    $0x0,%rax
je     12ff <main+0x16f>
lea    0xe09(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    130b <main+0x17b>
lea    0xde1(%rip),%rdi
call   1030 <unlink@plt>
xor    %eax,%eax
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x108,%rsp
lea    0xe4f(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x5,%edx
call   10b0 <sprintf@plt>
mov    %rbx,%rdi
call   1080 <putenv@plt>
test   %rax,%rax
je     11ed <main+0x4d>
mov    0x2e0b(%rip),%rax
mov    (%rax),%edi
call   10c0 <strerror@plt>
lea    0xe29(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xef3(%rip),%rdi
lea    0xe2d(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,%rbx
lea    0xe1a(%rip),%r14
lea    0xe19(%rip),%rdx
mov    %rax,%rdi
mov    %r14,%rsi
call   1090 <fprintf@plt>
lea    0xe33(%rip),%rdx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1090 <fprintf@plt>
lea    0xe30(%rip),%rdx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1090 <fprintf@plt>
lea    0xe3d(%rip),%rdx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1090 <fprintf@plt>
lea    0xe56(%rip),%rdx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1090 <fprintf@plt>
lea    0xe4a(%rip),%rdx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1090 <fprintf@plt>
lea    0xe4b(%rip),%rdx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1090 <fprintf@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
lea    0xe48(%rip),%rdi
call   1060 <system@plt>
test   %rax,%rax
je     12af <main+0x10f>
lea    0xe54(%rip),%rdi
call   1040 <puts@plt>
jmp    12bb <main+0x11b>
lea    0xe31(%rip),%rdi
call   1030 <unlink@plt>
xor    %eax,%eax
add    $0x108,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [12 x i8] c"i_string=%d\00"
@.str.1 = [28 x i8] c"putenv i_string failed: %s\0A\00"
@errno = global i32 0
@.str.2 = [21 x i8] c"scripting_example.sp\00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [4 x i8] c"%s\0A\00"
@.str.5 = [44 x i8] c"pragma restriction( no_external_commands );\00"
@.str.6 = [15 x i8] c"pragma ada_95;\00"
@.str.7 = [31 x i8] c"procedure scripting_example is\00"
@.str.8 = [43 x i8] c"i : integer := numerics.value( i_string );\00"
@.str.9 = [6 x i8] c"begin\00"
@.str.10 = [19 x i8] c"put_line( i * 2 );\00"
@.str.11 = [23 x i8] c"end scripting_example;\00"
@.str.12 = [29 x i8] c"../spar scripting_example.sp\00"
@.str.13 = [43 x i8] c"Oh, no. There was an error in the script\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [255 x i8]
%3 = alloca i32
%4 = alloca i32*
store i32 0, i32* %1
store i32 5, i32* %3
%5 = getelementptr inbounds [255 x i8], [255 x i8]* %2, i64 0, i64 0
%6 = load i32, i32* %3
%7 = call i32 @sprintf(i8* %5, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %6)
%8 = getelementptr inbounds [255 x i8], [255 x i8]* %2, i64 0, i64 0
%9 = call i64 @putenv(i8* %8)
%10 = icmp ne i64 %9, 0
br i1 %10, label %11, label %15
11: ; preds = %0
%12 = load i32, i32* @errno
%13 = call i8* @strerror(i32 %12)
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i8* %13)
br label %15
15: ; preds = %11, %0
%16 = call i32* @fopen(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %16, i32** %4
%17 = load i32*, i32** %4
%18 = call i32 @fprintf(i32* %17, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.5, i64 0, i64 0))
%19 = load i32*, i32** %4
%20 = call i32 @fprintf(i32* %19, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0))
%21 = load i32*, i32** %4
%22 = call i32 @fprintf(i32* %21, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.7, i64 0, i64 0))
%23 = load i32*, i32** %4
%24 = call i32 @fprintf(i32* %23, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.8, i64 0, i64 0))
%25 = load i32*, i32** %4
%26 = call i32 @fprintf(i32* %25, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.9, i64 0, i64 0))
%27 = load i32*, i32** %4
%28 = call i32 @fprintf(i32* %27, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.10, i64 0, i64 0))
%29 = load i32*, i32** %4
%30 = call i32 @fprintf(i32* %29, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.11, i64 0, i64 0))
%31 = load i32*, i32** %4
%32 = call i32 @fclose(i32* %31)
%33 = call i64 @system(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.12, i64 0, i64 0))
%34 = icmp ne i64 %33, 0
br i1 %34, label %35, label %37
35: ; preds = %15
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.13, i64 0, i64 0))
br label %39
37: ; preds = %15
%38 = call i32 @unlink(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
br label %39
39: ; preds = %37, %35
ret i32 0
}

LLVM IR (-O2):
@.str = [12 x i8] c"i_string=%d\00"
@.str.1 = [28 x i8] c"putenv i_string failed: %s\0A\00"
@errno = global i32 0
@.str.2 = [21 x i8] c"scripting_example.sp\00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [4 x i8] c"%s\0A\00"
@.str.5 = [44 x i8] c"pragma restriction( no_external_commands );\00"
@.str.6 = [15 x i8] c"pragma ada_95;\00"
@.str.7 = [31 x i8] c"procedure scripting_example is\00"
@.str.8 = [43 x i8] c"i : integer := numerics.value( i_string );\00"
@.str.9 = [6 x i8] c"begin\00"
@.str.10 = [19 x i8] c"put_line( i * 2 );\00"
@.str.11 = [23 x i8] c"end scripting_example;\00"
@.str.12 = [29 x i8] c"../spar scripting_example.sp\00"
@str = [42 x i8] c"Oh, no. There was an error in the script\00"
define i32 @main() {
%1 = alloca [255 x i8]
%2 = getelementptr inbounds [255 x i8], [255 x i8]* %1, i64 0, i64 0
%3 = call i32 @sprintf(i8* %2, i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 5)
%4 = call i64 @putenv(i8* %2)
%5 = icmp eq i64 %4, 0
br i1 %5, label %10, label %6
6: ; preds = %0
%7 = load i32, i32* @errno
%8 = call i8* @strerror(i32 %7)
%9 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i8* %8)
br label %10
10: ; preds = %6, %0
%11 = call i32* @fopen(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%12 = call i32 @fprintf(i32* %11, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.5, i64 0, i64 0))
%13 = call i32 @fprintf(i32* %11, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0))
%14 = call i32 @fprintf(i32* %11, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.7, i64 0, i64 0))
%15 = call i32 @fprintf(i32* %11, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.8, i64 0, i64 0))
%16 = call i32 @fprintf(i32* %11, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.9, i64 0, i64 0))
%17 = call i32 @fprintf(i32* %11, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.10, i64 0, i64 0))
%18 = call i32 @fprintf(i32* %11, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.11, i64 0, i64 0))
%19 = call i32 @fclose(i32* %11)
%20 = call i64 @system(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.12, i64 0, i64 0))
%21 = icmp eq i64 %20, 0
br i1 %21, label %24, label %22
22: ; preds = %10
%23 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @str, i64 0, i64 0))
br label %26
24: ; preds = %10
%25 = call i32 @unlink(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
br label %26
26: ; preds = %24, %22
ret i32 0
}