#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*/ printf(char *, char *);
int /*<<< orphan*/ sprintf(char *, char *, char *);
int strlen(char *);
int /*<<< orphan*/ system(char *);
void run_script(char *file) {
  if (file[strlen(file) - 1] == '~')
    return;
  else
    printf("running script file %s\n", file);
  char str[256 + 8];
  sprintf(str,
          "/bin/bash"
          " %s",
          file);
  system(str);
}


x86 assembly (clang, -O0):
<run_script>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x118(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x118(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x7e,%eax
jne    1184 <run_script+0x44>
jmp    11b7 <run_script+0x77>
mov    -0x8(%rbp),%rsi
lea    0xe71(%rip),%rdi
call   1050 <printf@plt>
lea    -0x110(%rbp),%rdi
mov    -0x8(%rbp),%rdx
lea    0xe72(%rip),%rsi
call   1060 <sprintf@plt>
lea    -0x110(%rbp),%rdi
call   1040 <system@plt>
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<run_script>:
push   %r14
push   %rbx
sub    $0x108,%rsp
mov    %rdi,%rbx
call   1030 <strlen@plt>
cltq
cmpb   $0x7e,-0x1(%rax,%rbx,1)
je     1187 <run_script+0x47>
lea    0xe9e(%rip),%rdi
mov    %rbx,%rsi
call   1050 <printf@plt>
lea    0xea7(%rip),%rsi
mov    %rsp,%r14
mov    %r14,%rdi
mov    %rbx,%rdx
call   1060 <sprintf@plt>
mov    %r14,%rdi
call   1040 <system@plt>
add    $0x108,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [24 x i8] c"running script file %s\0A\00"
@.str.1 = [13 x i8] c"/bin/bash %s\00"
define void @run_script(i8* %0) {
%2 = alloca i8*
%3 = alloca [264 x i8]
store i8* %0, i8** %2
%4 = load i8*, i8** %2
%5 = load i8*, i8** %2
%6 = call i32 @strlen(i8* %5)
%7 = sub nsw i32 %6, 1
%8 = sext i32 %7 to i64
%9 = getelementptr inbounds i8, i8* %4, i64 %8
%10 = load i8, i8* %9
%11 = sext i8 %10 to i32
%12 = icmp eq i32 %11, 126
br i1 %12, label %13, label %14
13: ; preds = %1
br label %23
14: ; preds = %1
%15 = load i8*, i8** %2
%16 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %15)
br label %17
17: ; preds = %14
%18 = getelementptr inbounds [264 x i8], [264 x i8]* %3, i64 0, i64 0
%19 = load i8*, i8** %2
%20 = call i32 @sprintf(i8* %18, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* %19)
%21 = getelementptr inbounds [264 x i8], [264 x i8]* %3, i64 0, i64 0
%22 = call i32 @system(i8* %21)
br label %23
23: ; preds = %17, %13
ret void
}

LLVM IR (-O2):
@.str = [24 x i8] c"running script file %s\0A\00"
@.str.1 = [13 x i8] c"/bin/bash %s\00"
define void @run_script(i8* %0) {
%2 = alloca [264 x i8]
%3 = tail call i32 @strlen(i8* %0)
%4 = add nsw i32 %3, -1
%5 = sext i32 %4 to i64
%6 = getelementptr inbounds i8, i8* %0, i64 %5
%7 = load i8, i8* %6
%8 = icmp eq i8 %7, 126
br i1 %8, label %14, label %9
9: ; preds = %1
%10 = tail call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %0)
%11 = getelementptr inbounds [264 x i8], [264 x i8]* %2, i64 0, i64 0
%12 = call i32 @sprintf(i8* %11, i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%13 = call i32 @system(i8* %11)
br label %14
14: ; preds = %1, %9
ret void
}