#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 */
scalar_t__ calloc(int, int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
char *getenv(char *);
int /*<<< orphan*/ sprintf(char *, char *, char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcat(char *, char *);
int strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
int system(char *);
int main(int argc, char *argv[]) {
  char *cmdln;
  char *p;
  int i;
  char *root = getenv("OBSERVE_ROOT");
  int len = 0;
  if (root == NULL) {
    fprintf(stderr, "OBSERVE_ROOT undefined\n");
    return 1;
  }
  len += strlen(root);
  len += sizeof("sh.exe -c \"'%s/drivers/path.win32/capture.sh'");
  for (i = 0; i < argc; i++)
    len += strlen(argv[i]) + 3;
  cmdln = (char *)calloc(len + 1, sizeof(char));
  sprintf(cmdln, "sh.exe -c \"'%s/drivers/path.win32/capture.sh'", root);
  p = cmdln + strlen(cmdln);
  for (i = 0; i < argc; i++) {
    *p++ = ' ';
    *p++ = '\'';
    len = strlen(argv[i]);
    strncpy(p, argv[i], len);
    p += len;
    *p++ = '\'';
  }
  strcat(p, "\"");
  return system(cmdln);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe63(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    11d9 <main+0x59>
mov    0x2e21(%rip),%rax
mov    (%rax),%edi
lea    0xe45(%rip),%rsi
call   1080 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1327 <main+0x1a7>
mov    -0x30(%rbp),%rdi
call   1050 <strlen@plt>
add    -0x34(%rbp),%eax
mov    %eax,-0x34(%rbp)
movslq -0x34(%rbp),%rax
add    $0x2e,%rax
mov    %eax,-0x34(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    122e <main+0xae>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1050 <strlen@plt>
add    $0x3,%eax
add    -0x34(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11fa <main+0x7a>
mov    -0x34(%rbp),%edi
add    $0x1,%edi
mov    $0x1,%esi
call   1070 <calloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x30(%rbp),%rdx
lea    0xdd4(%rip),%rsi
call   10a0 <sprintf@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x40(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    130b <main+0x18b>
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x20(%rbp)
movb   $0x20,(%rax)
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x20(%rbp)
movb   $0x27,(%rax)
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x34(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
mov    -0x34(%rbp),%edx
call   1040 <strncpy@plt>
mov    -0x34(%rbp),%ecx
mov    -0x20(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x20(%rbp)
movb   $0x27,(%rax)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    127e <main+0xfe>
mov    -0x20(%rbp),%rdi
lea    0xd3d(%rip),%rsi
call   1090 <strcat@plt>
mov    -0x18(%rbp),%rdi
call   1060 <system@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r13
mov    %edi,%r15d
lea    0xe68(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     1263 <main+0xe3>
mov    %rax,%r12
mov    %rax,%rdi
call   1050 <strlen@plt>
mov    %eax,%ebp
add    $0x2e,%ebp
mov    %r15d,%r14d
test   %r15d,%r15d
jle    11d8 <main+0x58>
xor    %ebx,%ebx
mov    0x0(%r13,%rbx,8),%rdi
call   1050 <strlen@plt>
add    %eax,%ebp
add    $0x3,%ebp
add    $0x1,%rbx
cmp    %rbx,%r14
jne    11c0 <main+0x40>
add    $0x1,%ebp
mov    %ebp,%edi
mov    $0x1,%esi
call   1070 <calloc@plt>
mov    %rax,%rbx
lea    0xe34(%rip),%rsi
mov    %rax,%rdi
mov    %r12,%rdx
call   10a0 <sprintf@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
movslq %eax,%rbp
mov    %rbx,(%rsp)
add    %rbx,%rbp
test   %r15d,%r15d
jle    128c <main+0x10c>
xor    %r15d,%r15d
cs nopw 0x0(%rax,%rax,1)
movw   $0x2720,0x0(%rbp)
lea    0x2(%rbp),%r12
mov    0x0(%r13,%r15,8),%rdi
call   1050 <strlen@plt>
mov    %eax,%ebx
mov    0x0(%r13,%r15,8),%rsi
mov    %r12,%rdi
mov    %eax,%edx
call   1040 <strncpy@plt>
movslq %ebx,%rax
lea    (%rax,%rbp,1),%rdi
add    $0x3,%rdi
movb   $0x27,0x2(%rbp,%rax,1)
add    $0x1,%r15
mov    %rdi,%rbp
cmp    %r15,%r14
jne    1220 <main+0xa0>
jmp    128f <main+0x10f>
mov    0x2d76(%rip),%rax
mov    (%rax),%edi
lea    0xd9a(%rip),%rsi
call   1080 <fprintf@plt>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %rbp,%rdi
lea    0xdbd(%rip),%rsi
call   1090 <strcat@plt>
mov    (%rsp),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1060 <system@plt>

LLVM IR (-O0):
@.str = [13 x i8] c"OBSERVE_ROOT\00"
@stderr = global i32 0
@.str.1 = [24 x i8] c"OBSERVE_ROOT undefined\0A\00"
@.str.2 = [46 x i8] c"sh.exe -c \22'%s/drivers/path.win32/capture.sh'\00"
@.str.3 = [2 x i8] c"\22\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = call i8* @getenv(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
store i8* %11, i8** %9
store i32 0, i32* %10
%12 = load i8*, i8** %9
%13 = icmp eq i8* %12, null
br i1 %13, label %14, label %17
14: ; preds = %2
%15 = load i32, i32* @stderr
%16 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %3
br label %93
17: ; preds = %2
%18 = load i8*, i8** %9
%19 = call i32 @strlen(i8* %18)
%20 = load i32, i32* %10
%21 = add nsw i32 %20, %19
store i32 %21, i32* %10
%22 = load i32, i32* %10
%23 = sext i32 %22 to i64
%24 = add i64 %23, 46
%25 = trunc i64 %24 to i32
store i32 %25, i32* %10
store i32 0, i32* %8
br label %26
26: ; preds = %40, %17
%27 = load i32, i32* %8
%28 = load i32, i32* %4
%29 = icmp slt i32 %27, %28
br i1 %29, label %30, label %43
30: ; preds = %26
%31 = load i8**, i8*** %5
%32 = load i32, i32* %8
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8*, i8** %31, i64 %33
%35 = load i8*, i8** %34
%36 = call i32 @strlen(i8* %35)
%37 = add nsw i32 %36, 3
%38 = load i32, i32* %10
%39 = add nsw i32 %38, %37
store i32 %39, i32* %10
br label %40
40: ; preds = %30
%41 = load i32, i32* %8
%42 = add nsw i32 %41, 1
store i32 %42, i32* %8
br label %26
43: ; preds = %26
%44 = load i32, i32* %10
%45 = add nsw i32 %44, 1
%46 = call i64 @calloc(i32 %45, i32 1)
%47 = inttoptr i64 %46 to i8*
store i8* %47, i8** %6
%48 = load i8*, i8** %6
%49 = load i8*, i8** %9
%50 = call i32 @sprintf(i8* %48, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.2, i64 0, i64 0), i8* %49)
%51 = load i8*, i8** %6
%52 = load i8*, i8** %6
%53 = call i32 @strlen(i8* %52)
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds i8, i8* %51, i64 %54
store i8* %55, i8** %7
store i32 0, i32* %8
br label %56
56: ; preds = %85, %43
%57 = load i32, i32* %8
%58 = load i32, i32* %4
%59 = icmp slt i32 %57, %58
br i1 %59, label %60, label %88
60: ; preds = %56
%61 = load i8*, i8** %7
%62 = getelementptr inbounds i8, i8* %61, i32 1
store i8* %62, i8** %7
store i8 32, i8* %61
%63 = load i8*, i8** %7
%64 = getelementptr inbounds i8, i8* %63, i32 1
store i8* %64, i8** %7
store i8 39, i8* %63
%65 = load i8**, i8*** %5
%66 = load i32, i32* %8
%67 = sext i32 %66 to i64
%68 = getelementptr inbounds i8*, i8** %65, i64 %67
%69 = load i8*, i8** %68
%70 = call i32 @strlen(i8* %69)
store i32 %70, i32* %10
%71 = load i8*, i8** %7
%72 = load i8**, i8*** %5
%73 = load i32, i32* %8
%74 = sext i32 %73 to i64
%75 = getelementptr inbounds i8*, i8** %72, i64 %74
%76 = load i8*, i8** %75
%77 = load i32, i32* %10
%78 = call i32 @strncpy(i8* %71, i8* %76, i32 %77)
%79 = load i32, i32* %10
%80 = load i8*, i8** %7
%81 = sext i32 %79 to i64
%82 = getelementptr inbounds i8, i8* %80, i64 %81
store i8* %82, i8** %7
%83 = load i8*, i8** %7
%84 = getelementptr inbounds i8, i8* %83, i32 1
store i8* %84, i8** %7
store i8 39, i8* %83
br label %85
85: ; preds = %60
%86 = load i32, i32* %8
%87 = add nsw i32 %86, 1
store i32 %87, i32* %8
br label %56
88: ; preds = %56
%89 = load i8*, i8** %7
%90 = call i32 @strcat(i8* %89, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%91 = load i8*, i8** %6
%92 = call i32 @system(i8* %91)
store i32 %92, i32* %3
br label %93
93: ; preds = %88, %14
%94 = load i32, i32* %3
ret i32 %94
}

LLVM IR (-O2):
@.str = [13 x i8] c"OBSERVE_ROOT\00"
@stderr = global i32 0
@.str.1 = [24 x i8] c"OBSERVE_ROOT undefined\0A\00"
@.str.2 = [46 x i8] c"sh.exe -c \22'%s/drivers/path.win32/capture.sh'\00"
@.str.3 = [2 x i8] c"\22\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = tail call i8* @getenv(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i8* %3, null
br i1 %4, label %5, label %8
5: ; preds = %2
%6 = load i32, i32* @stderr
%7 = tail call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
br label %54
8: ; preds = %2
%9 = tail call i32 @strlen(i8* %3)
%10 = add i32 %9, 46
%11 = icmp sgt i32 %0, 0
br i1 %11, label %12, label %24
12: ; preds = %8
%13 = zext i32 %0 to i64
br label %14
14: ; preds = %12, %14
%15 = phi i64 [ 0, %12 ], [ %22, %14 ]
%16 = phi i32 [ %10, %12 ], [ %21, %14 ]
%17 = getelementptr inbounds i8*, i8** %1, i64 %15
%18 = load i8*, i8** %17
%19 = tail call i32 @strlen(i8* %18)
%20 = add i32 %16, 3
%21 = add i32 %20, %19
%22 = add nuw nsw i64 %15, 1
%23 = icmp eq i64 %22, %13
br i1 %23, label %24, label %14
24: ; preds = %14, %8
%25 = phi i32 [ %10, %8 ], [ %21, %14 ]
%26 = add nsw i32 %25, 1
%27 = tail call i64 @calloc(i32 %26, i32 1)
%28 = inttoptr i64 %27 to i8*
%29 = tail call i32 @sprintf(i8* dereferenceable(1) %28, i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @.str.2, i64 0, i64 0), i8* %3)
%30 = tail call i32 @strlen(i8* %28)
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i8, i8* %28, i64 %31
br i1 %11, label %33, label %50
33: ; preds = %24
%34 = zext i32 %0 to i64
br label %35
35: ; preds = %33, %35
%36 = phi i64 [ 0, %33 ], [ %48, %35 ]
%37 = phi i8* [ %32, %33 ], [ %47, %35 ]
%38 = getelementptr inbounds i8, i8* %37, i64 1
store i8 32, i8* %37
%39 = getelementptr inbounds i8, i8* %37, i64 2
store i8 39, i8* %38
%40 = getelementptr inbounds i8*, i8** %1, i64 %36
%41 = load i8*, i8** %40
%42 = tail call i32 @strlen(i8* %41)
%43 = load i8*, i8** %40
%44 = tail call i32 @strncpy(i8* %39, i8* %43, i32 %42)
%45 = sext i32 %42 to i64
%46 = getelementptr inbounds i8, i8* %39, i64 %45
%47 = getelementptr inbounds i8, i8* %46, i64 1
store i8 39, i8* %46
%48 = add nuw nsw i64 %36, 1
%49 = icmp eq i64 %48, %34
br i1 %49, label %50, label %35
50: ; preds = %35, %24
%51 = phi i8* [ %32, %24 ], [ %47, %35 ]
%52 = tail call i32 @strcat(i8* %51, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%53 = tail call i32 @system(i8* %28)
br label %54
54: ; preds = %50, %5
%55 = phi i32 [ 1, %5 ], [ %53, %50 ]
ret i32 %55
}