#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*/ chdir(char *);
scalar_t__ getcwd(char *, int);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
scalar_t__ system(char *);
int main(int argc, char *argv[]) {
  int n, ret = 0;
  char current_dir[1024];
  char cmd[1024];
  if (getcwd(current_dir, 1024) == 0)
    return -1;
  strcpy(cmd, argv[0]);
  n = strlen(cmd);
  while (n != 0 && cmd[n] != '/' && cmd[n] != '\\')
    n--;
  cmd[n] = 0;
  chdir(cmd);
  strcpy(cmd, "scetool.exe");
  for (n = 1; n < argc; n++) {
    strcat(cmd, " ");
    strcat(cmd, argv[n]);
  }
  if (system(cmd) != 0)
    ret = -2;
  chdir(current_dir);
  return ret;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x830,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
lea    -0x420(%rbp),%rdi
mov    $0x400,%esi
call   1070 <getcwd@plt>
cmp    $0x0,%rax
jne    11a7 <main+0x47>
movl   $0xffffffff,-0x4(%rbp)
jmp    12d7 <main+0x177>
lea    -0x820(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
call   1030 <strcpy@plt>
lea    -0x820(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x14(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x14(%rbp)
mov    %al,-0x821(%rbp)
je     1210 <main+0xb0>
movslq -0x14(%rbp),%rax
movsbl -0x820(%rbp,%rax,1),%ecx
ff
xor    %eax,%eax
cmp    $0x2f,%ecx
mov    %al,-0x821(%rbp)
je     1210 <main+0xb0>
movslq -0x14(%rbp),%rax
movsbl -0x820(%rbp,%rax,1),%eax
ff
cmp    $0x5c,%eax
setne  %al
mov    %al,-0x821(%rbp)
mov    -0x821(%rbp),%al
test   $0x1,%al
jne    1223 <main+0xc3>
jmp    1231 <main+0xd1>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
jmp    11c9 <main+0x69>
movslq -0x14(%rbp),%rax
movb   $0x0,-0x820(%rbp,%rax,1)
lea    -0x820(%rbp),%rdi
call   1050 <chdir@plt>
lea    -0x820(%rbp),%rdi
lea    0xda9(%rip),%rsi
call   1030 <strcpy@plt>
movl   $0x1,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    12a8 <main+0x148>
lea    -0x820(%rbp),%rdi
lea    0xd8f(%rip),%rsi
call   1080 <strcat@plt>
lea    -0x820(%rbp),%rdi
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
call   1080 <strcat@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1263 <main+0x103>
lea    -0x820(%rbp),%rdi
call   1060 <system@plt>
cmp    $0x0,%rax
je     12c5 <main+0x165>
movl   $0xfffffffe,-0x18(%rbp)
lea    -0x420(%rbp),%rdi
call   1050 <chdir@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x830,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x800,%rsp
mov    %rsi,%r14
mov    %edi,%ebp
lea    0x400(%rsp),%rdi
mov    $0x400,%esi
call   1070 <getcwd@plt>
test   %rax,%rax
je     1245 <main+0xe5>
mov    (%r14),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1030 <strcpy@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
test   %eax,%eax
je     11c6 <main+0x66>
cltq
nopl   0x0(%rax,%rax,1)
movzbl (%rsp,%rax,1),%ecx
cmp    $0x2f,%cl
je     11c8 <main+0x68>
cmp    $0x5c,%cl
je     11c8 <main+0x68>
add    $0xffffffffffffffff,%rax
test   %eax,%eax
jne    11b0 <main+0x50>
xor    %eax,%eax
cltq
movb   $0x0,(%rsp,%rax,1)
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1050 <chdir@plt>
lea    0xe20(%rip),%rsi
mov    %rbx,%rdi
call   1030 <strcpy@plt>
cmp    $0x2,%ebp
jl     1220 <main+0xc0>
mov    %ebp,%r12d
mov    $0x1,%ebp
lea    0xe10(%rip),%r15
mov    %rsp,%rbx
nop
mov    %rbx,%rdi
mov    %r15,%rsi
call   1080 <strcat@plt>
mov    (%r14,%rbp,8),%rsi
mov    %rbx,%rdi
call   1080 <strcat@plt>
add    $0x1,%rbp
cmp    %rbp,%r12
jne    1200 <main+0xa0>
mov    %rsp,%rdi
call   1060 <system@plt>
xor    %ecx,%ecx
test   %rax,%rax
sete   %cl
lea    (%rcx,%rcx,1),%ebx
add    $0xfffffffe,%ebx
lea    0x400(%rsp),%rdi
call   1050 <chdir@plt>
jmp    124a <main+0xea>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x800,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [12 x i8] c"scetool.exe\00"
@.str.1 = [2 x i8] c" \00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca [1024 x i8]
%9 = alloca [1024 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %7
%10 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%11 = call i64 @getcwd(i8* %10, i32 1024)
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %14
13: ; preds = %2
store i32 -1, i32* %3
br label %78
14: ; preds = %2
%15 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 0
%18 = load i8*, i8** %17
%19 = call i32 @strcpy(i8* %15, i8* %18)
%20 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%21 = call i32 @strlen(i8* %20)
store i32 %21, i32* %6
br label %22
22: ; preds = %41, %14
%23 = load i32, i32* %6
%24 = icmp ne i32 %23, 0
br i1 %24, label %25, label %39
25: ; preds = %22
%26 = load i32, i32* %6
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 %27
%29 = load i8, i8* %28
%30 = sext i8 %29 to i32
%31 = icmp ne i32 %30, 47
br i1 %31, label %32, label %39
32: ; preds = %25
%33 = load i32, i32* %6
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 %34
%36 = load i8, i8* %35
%37 = sext i8 %36 to i32
%38 = icmp ne i32 %37, 92
br label %39
39: ; preds = %32, %25, %22
%40 = phi i1 [ false, %25 ], [ false, %22 ], [ %38, %32 ]
br i1 %40, label %41, label %44
41: ; preds = %39
%42 = load i32, i32* %6
%43 = add nsw i32 %42, -1
store i32 %43, i32* %6
br label %22
44: ; preds = %39
%45 = load i32, i32* %6
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 %46
store i8 0, i8* %47
%48 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%49 = call i32 @chdir(i8* %48)
%50 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%51 = call i32 @strcpy(i8* %50, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %6
br label %52
52: ; preds = %66, %44
%53 = load i32, i32* %6
%54 = load i32, i32* %4
%55 = icmp slt i32 %53, %54
br i1 %55, label %56, label %69
56: ; preds = %52
%57 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%58 = call i32 @strcat(i8* %57, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%59 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%60 = load i8**, i8*** %5
%61 = load i32, i32* %6
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds i8*, i8** %60, i64 %62
%64 = load i8*, i8** %63
%65 = call i32 @strcat(i8* %59, i8* %64)
br label %66
66: ; preds = %56
%67 = load i32, i32* %6
%68 = add nsw i32 %67, 1
store i32 %68, i32* %6
br label %52
69: ; preds = %52
%70 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%71 = call i64 @system(i8* %70)
%72 = icmp ne i64 %71, 0
br i1 %72, label %73, label %74
73: ; preds = %69
store i32 -2, i32* %7
br label %74
74: ; preds = %73, %69
%75 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%76 = call i32 @chdir(i8* %75)
%77 = load i32, i32* %7
store i32 %77, i32* %3
br label %78
78: ; preds = %74, %13
%79 = load i32, i32* %3
ret i32 %79
}

LLVM IR (-O2):
@.str = [12 x i8] c"scetool.exe\00"
@.str.1 = [2 x i8] c" \00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [1024 x i8]
%4 = alloca [1024 x i8]
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%7 = call i64 @getcwd(i8* %5, i32 1024)
%8 = icmp eq i64 %7, 0
br i1 %8, label %47, label %9
9: ; preds = %2
%10 = load i8*, i8** %1
%11 = call i32 @strcpy(i8* %6, i8* %10)
%12 = call i32 @strlen(i8* %6)
%13 = icmp eq i32 %12, 0
br i1 %13, label %24, label %14
14: ; preds = %9
%15 = sext i32 %12 to i64
br label %16
16: ; preds = %14, %20
%17 = phi i64 [ %15, %14 ], [ %21, %20 ]
%18 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 %17
%19 = load i8, i8* %18
switch i8 %19, label %20 [
i8 47, label %24
i8 92, label %24
]
20: ; preds = %16
%21 = add nsw i64 %17, -1
%22 = trunc i64 %21 to i32
%23 = icmp eq i32 %22, 0
br i1 %23, label %24, label %16
24: ; preds = %20, %16, %16, %9
%25 = phi i64 [ 0, %9 ], [ %17, %16 ], [ %17, %16 ], [ 0, %20 ]
%26 = shl i64 %25, 32
%27 = ashr exact i64 %26, 32
%28 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 %27
store i8 0, i8* %28
%29 = call i32 @chdir(i8* %6)
%30 = call i32 @strcpy(i8* %6, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%31 = icmp sgt i32 %0, 1
br i1 %31, label %32, label %42
32: ; preds = %24
%33 = zext i32 %0 to i64
br label %34
34: ; preds = %32, %34
%35 = phi i64 [ 1, %32 ], [ %40, %34 ]
%36 = call i32 @strcat(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%37 = getelementptr inbounds i8*, i8** %1, i64 %35
%38 = load i8*, i8** %37
%39 = call i32 @strcat(i8* %6, i8* %38)
%40 = add nuw nsw i64 %35, 1
%41 = icmp eq i64 %40, %33
br i1 %41, label %42, label %34
42: ; preds = %34, %24
%43 = call i64 @system(i8* %6)
%44 = icmp eq i64 %43, 0
%45 = select i1 %44, i32 0, i32 -2
%46 = call i32 @chdir(i8* %5)
br label %47
47: ; preds = %2, %42
%48 = phi i32 [ %45, %42 ], [ -1, %2 ]
ret i32 %48
}