#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*/ arg_buff;

/* Variables and functions */
scalar_t__ SIGINT;
scalar_t__ SIGQUIT;
int WEXITSTATUS(int);
scalar_t__ WIFSIGNALED(int);
scalar_t__ WTERMSIG(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ snprintf(char *, int, char *, char const *, ...);
int /*<<< orphan*/ stderr;
int system(char *);
int call_script(char const *script, char const *additional_argument) {
  int ret;
  char arg_buff[1024];
  if (additional_argument) {
    snprintf(arg_buff, sizeof(arg_buff) - 1, "%s %s", script,
             additional_argument);
  } else {
    snprintf(arg_buff, sizeof(arg_buff) - 1, "%s", script);
  }
  fprintf(stderr, "Calling script: %s\n", arg_buff);
  ret = system(arg_buff);
  if (WIFSIGNALED(ret) && (WTERMSIG(ret) == SIGINT || WTERMSIG(ret) == SIGQUIT))
    return -1;
  fprintf(stderr, "GOT RET: %d\n", WEXITSTATUS(ret));
  return WEXITSTATUS(ret);
}


x86 assembly (clang, -O0):
<call_script>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11a5 <call_script+0x45>
lea    -0x420(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    -0x18(%rbp),%r8
mov    $0x3ff,%esi
lea    0xe67(%rip),%rdx
mov    $0x0,%al
call   1040 <snprintf@plt>
jmp    11c3 <call_script+0x63>
lea    -0x420(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x3ff,%esi
lea    0xe47(%rip),%rdx
mov    $0x0,%al
call   1040 <snprintf@plt>
mov    0x2e06(%rip),%rax
mov    (%rax),%edi
lea    -0x420(%rbp),%rdx
lea    0xe2c(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
lea    -0x420(%rbp),%rdi
call   1030 <system@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%edi
call   1050 <WIFSIGNALED@plt>
cmp    $0x0,%rax
je     123e <call_script+0xde>
mov    -0x1c(%rbp),%edi
call   1070 <WTERMSIG@plt>
mov    0x2dd7(%rip),%rcx
cmp    (%rcx),%rax
je     1232 <call_script+0xd2>
mov    -0x1c(%rbp),%edi
call   1070 <WTERMSIG@plt>
mov    0x2db7(%rip),%rcx
cmp    (%rcx),%rax
jne    123e <call_script+0xde>
movl   $0xffffffff,-0x4(%rbp)
jmp    1276 <call_script+0x116>
mov    0x2d8b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x424(%rbp)
mov    -0x1c(%rbp),%edi
call   1080 <WEXITSTATUS@plt>
mov    -0x424(%rbp),%edi
mov    %eax,%edx
lea    0xdb6(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x1c(%rbp),%edi
call   1080 <WEXITSTATUS@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<call_script>:
push   %rbp
push   %r14
push   %rbx
sub    $0x400,%rsp
mov    %rdi,%rcx
test   %rsi,%rsi
je     118e <call_script+0x2e>
mov    %rsi,%r8
lea    0xe83(%rip),%rdx
mov    %rsp,%rdi
mov    $0x3ff,%esi
xor    %eax,%eax
call   1040 <snprintf@plt>
jmp    11a4 <call_script+0x44>
lea    0xe6e(%rip),%rdx
mov    %rsp,%rdi
mov    $0x3ff,%esi
xor    %eax,%eax
call   1040 <snprintf@plt>
mov    0x2e25(%rip),%r14
mov    (%r14),%edi
lea    0xe51(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    %rbx,%rdi
call   1030 <system@plt>
mov    %eax,%ebx
mov    %eax,%edi
call   1050 <WIFSIGNALED@plt>
test   %rax,%rax
je     1203 <call_script+0xa3>
mov    %ebx,%edi
call   1070 <WTERMSIG@plt>
mov    0x2e02(%rip),%rcx
mov    $0xffffffff,%ebp
cmp    (%rcx),%rax
je     1228 <call_script+0xc8>
mov    %ebx,%edi
call   1070 <WTERMSIG@plt>
mov    0x2de2(%rip),%rcx
cmp    (%rcx),%rax
je     1228 <call_script+0xc8>
mov    (%r14),%ebp
mov    %ebx,%edi
call   1080 <WEXITSTATUS@plt>
lea    0xe06(%rip),%rsi
mov    %ebp,%edi
mov    %eax,%edx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    %ebx,%edi
call   1080 <WEXITSTATUS@plt>
mov    %eax,%ebp
mov    %ebp,%eax
add    $0x400,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [6 x i8] c"%s %s\00"
@.str.1 = [3 x i8] c"%s\00"
@stderr = global i32 0
@.str.2 = [20 x i8] c"Calling script: %s\0A\00"
@SIGINT = global i64 0
@SIGQUIT = global i64 0
@.str.3 = [13 x i8] c"GOT RET: %d\0A\00"
define i32 @call_script(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca [1024 x i8]
store i8* %0, i8** %4
store i8* %1, i8** %5
%8 = load i8*, i8** %5
%9 = icmp ne i8* %8, null
br i1 %9, label %10, label %15
10: ; preds = %2
%11 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%12 = load i8*, i8** %4
%13 = load i8*, i8** %5
%14 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %11, i32 1023, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %12, i8* %13)
br label %19
15: ; preds = %2
%16 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%17 = load i8*, i8** %4
%18 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %16, i32 1023, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %17)
br label %19
19: ; preds = %15, %10
%20 = load i32, i32* @stderr
%21 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%22 = call i32 (i32, i8*, ...) @fprintf(i32 %20, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8* %21)
%23 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%24 = call i32 @system(i8* %23)
store i32 %24, i32* %6
%25 = load i32, i32* %6
%26 = call i64 @WIFSIGNALED(i32 %25)
%27 = icmp ne i64 %26, 0
br i1 %27, label %28, label %39
28: ; preds = %19
%29 = load i32, i32* %6
%30 = call i64 @WTERMSIG(i32 %29)
%31 = load i64, i64* @SIGINT
%32 = icmp eq i64 %30, %31
br i1 %32, label %38, label %33
33: ; preds = %28
%34 = load i32, i32* %6
%35 = call i64 @WTERMSIG(i32 %34)
%36 = load i64, i64* @SIGQUIT
%37 = icmp eq i64 %35, %36
br i1 %37, label %38, label %39
38: ; preds = %33, %28
store i32 -1, i32* %3
br label %46
39: ; preds = %33, %19
%40 = load i32, i32* @stderr
%41 = load i32, i32* %6
%42 = call i32 @WEXITSTATUS(i32 %41)
%43 = call i32 (i32, i8*, ...) @fprintf(i32 %40, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i32 %42)
%44 = load i32, i32* %6
%45 = call i32 @WEXITSTATUS(i32 %44)
store i32 %45, i32* %3
br label %46
46: ; preds = %39, %38
%47 = load i32, i32* %3
ret i32 %47
}

LLVM IR (-O2):
@.str = [6 x i8] c"%s %s\00"
@.str.1 = [3 x i8] c"%s\00"
@stderr = global i32 0
@.str.2 = [20 x i8] c"Calling script: %s\0A\00"
@SIGINT = global i64 0
@SIGQUIT = global i64 0
@.str.3 = [13 x i8] c"GOT RET: %d\0A\00"
define i32 @call_script(i8* %0, i8* %1) {
%3 = alloca [1024 x i8]
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%5 = icmp eq i8* %1, null
br i1 %5, label %8, label %6
6: ; preds = %2
%7 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %4, i32 1023, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %1)
br label %10
8: ; preds = %2
%9 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %4, i32 1023, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %10
10: ; preds = %8, %6
%11 = load i32, i32* @stderr
%12 = call i32 (i32, i8*, ...) @fprintf(i32 %11, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8* %4)
%13 = call i32 @system(i8* %4)
%14 = call i64 @WIFSIGNALED(i32 %13)
%15 = icmp eq i64 %14, 0
br i1 %15, label %24, label %16
16: ; preds = %10
%17 = call i64 @WTERMSIG(i32 %13)
%18 = load i64, i64* @SIGINT
%19 = icmp eq i64 %17, %18
br i1 %19, label %29, label %20
20: ; preds = %16
%21 = call i64 @WTERMSIG(i32 %13)
%22 = load i64, i64* @SIGQUIT
%23 = icmp eq i64 %21, %22
br i1 %23, label %29, label %24
24: ; preds = %20, %10
%25 = load i32, i32* @stderr
%26 = call i32 @WEXITSTATUS(i32 %13)
%27 = call i32 (i32, i8*, ...) @fprintf(i32 %25, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i32 %26)
%28 = call i32 @WEXITSTATUS(i32 %13)
br label %29
29: ; preds = %16, %20, %24
%30 = phi i32 [ %28, %24 ], [ -1, %20 ], [ -1, %16 ]
ret i32 %30
}