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

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ pclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *popen(char *, char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sprintf(char *, char *);
int strlen(char *);
int /*<<< orphan*/ system(char *);
int main(int argc, char *argv[]) {
  FILE *fp, *tfp;
  char path[1035];
  char comPath[1024];
  char tempcomPath[1024];
  int nLen;
  fp = popen("/bin/ls ../Authorized/", "r");
  if (fp == NULL) {
    printf("Failed to run command\n");
    exit(1);
  }
  while (fgets(path, sizeof(path) - 1, fp) != NULL) {
    printf("%s", path);
    nLen = strlen(path);
    printf("Length : %d", nLen);
    sprintf(comPath, "br -algorithm FaceRecognition -compare "
                     "../uploads/myImage.png ../Authorized/U1/ > OUTPUT.txt");
    system(comPath);
    printf("/n%s", comPath);
    tfp = fopen("OUTPUT.txt", "r");
    while (fgets(tempcomPath, sizeof(tempcomPath) - 1, tfp) != NULL) {
      printf("OUTFILE DATA: %s", tempcomPath);
    }
  }
  pclose(fp);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe50(%rip),%rdi
lea    0xe60(%rip),%rsi
call   1080 <popen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11e3 <main+0x53>
lea    0xe47(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
jmp    11e8 <main+0x58>
lea    -0x430(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x40a,%esi
call   1070 <fgets@plt>
cmp    $0x0,%rax
je     12cb <main+0x13b>
lea    -0x430(%rbp),%rsi
lea    0xe97(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x430(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0xc34(%rbp)
mov    -0xc34(%rbp),%esi
lea    0xdf5(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x830(%rbp),%rdi
lea    0xdec(%rip),%rsi
call   10a0 <sprintf@plt>
lea    -0x830(%rbp),%rdi
call   1040 <system@plt>
lea    -0x830(%rbp),%rsi
lea    0xe2a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe11(%rip),%rdi
lea    0xd93(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x20(%rbp)
lea    -0xc30(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    $0x3ff,%esi
call   1070 <fgets@plt>
cmp    $0x0,%rax
je     12c6 <main+0x136>
lea    -0xc30(%rbp),%rsi
lea    0xde4(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    128d <main+0xfd>
jmp    11e8 <main+0x58>
mov    -0x18(%rbp),%rdi
call   1060 <pclose@plt>
xor    %eax,%eax
add    $0xc40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xc18,%rsp
lea    0xe58(%rip),%rdi
lea    0xe68(%rip),%rsi
call   1090 <popen@plt>
test   %rax,%rax
je     1314 <main+0x184>
mov    %rax,%r15
lea    0x400(%rsp),%rdi
mov    $0x40a,%esi
mov    %rax,%rdx
call   1080 <fgets@plt>
test   %rax,%rax
je     12f8 <main+0x168>
lea    0x400(%rsp),%rbx
mov    %rsp,%r13
lea    0x810(%rsp),%rbp
lea    0xe8f(%rip),%r14
jmp    1219 <main+0x89>
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    $0x40a,%esi
mov    %r15,%rdx
call   1080 <fgets@plt>
test   %rax,%rax
je     12f8 <main+0x168>
lea    0xe75(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
lea    0xde0(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
movups 0xddc(%rip),%xmm0
movaps %xmm0,(%rsp)
movups 0xde1(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movups 0xde5(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movups 0xde9(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
movups 0xded(%rip),%xmm0
movaps %xmm0,0x40(%rsp)
movups 0xdee(%rip),%xmm0
movups %xmm0,0x4d(%rsp)
mov    %r13,%rdi
call   1050 <system@plt>
lea    0xdea(%rip),%rdi
mov    %r13,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xdce(%rip),%rdi
lea    0xd67(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,%r12
mov    %rbp,%rdi
mov    $0x3ff,%esi
mov    %rax,%rdx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
call   1080 <fgets@plt>
test   %rax,%rax
je     1200 <main+0x70>
mov    %r14,%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %rbp,%rdi
mov    $0x3ff,%esi
mov    %r12,%rdx
jmp    12d0 <main+0x140>
mov    %r15,%rdi
call   1070 <pclose@plt>
xor    %eax,%eax
add    $0xc18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd7d(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@.str = [23 x i8] c"/bin/ls ../Authorized/\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [23 x i8] c"Failed to run command\0A\00"
@.str.3 = [3 x i8] c"%s\00"
@.str.4 = [12 x i8] c"Length : %d\00"
@.str.5 = [93 x i8] c"br -algorithm FaceRecognition -compare ../uploads/myImage.png ../Authorized/U1/ > OUTPUT.txt\00"
@.str.6 = [5 x i8] c"/n%s\00"
@.str.7 = [11 x i8] c"OUTPUT.txt\00"
@.str.8 = [17 x i8] c"OUTFILE DATA: %s\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 [1035 x i8]
%9 = alloca [1024 x i8]
%10 = alloca [1024 x i8]
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = call i32* @popen(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %12, i32** %6
%13 = load i32*, i32** %6
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %18
15: ; preds = %2
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
%17 = call i32 @exit(i32 1)
unreachable
18: ; preds = %2
br label %19
19: ; preds = %46, %18
%20 = getelementptr inbounds [1035 x i8], [1035 x i8]* %8, i64 0, i64 0
%21 = load i32*, i32** %6
%22 = call i32* @fgets(i8* %20, i32 1034, i32* %21)
%23 = icmp ne i32* %22, null
br i1 %23, label %24, label %47
24: ; preds = %19
%25 = getelementptr inbounds [1035 x i8], [1035 x i8]* %8, i64 0, i64 0
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %25)
%27 = getelementptr inbounds [1035 x i8], [1035 x i8]* %8, i64 0, i64 0
%28 = call i32 @strlen(i8* %27)
store i32 %28, i32* %11
%29 = load i32, i32* %11
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i32 %29)
%31 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%32 = call i32 @sprintf(i8* %31, i8* getelementptr inbounds ([93 x i8], [93 x i8]* @.str.5, i64 0, i64 0))
%33 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%34 = call i32 @system(i8* %33)
%35 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0), i8* %35)
%37 = call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %37, i32** %7
br label %38
38: ; preds = %43, %24
%39 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%40 = load i32*, i32** %7
%41 = call i32* @fgets(i8* %39, i32 1023, i32* %40)
%42 = icmp ne i32* %41, null
br i1 %42, label %43, label %46
43: ; preds = %38
%44 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.8, i64 0, i64 0), i8* %44)
br label %38
46: ; preds = %38
br label %19
47: ; preds = %19
%48 = load i32*, i32** %6
%49 = call i32 @pclose(i32* %48)
ret i32 0
}

LLVM IR (-O2):
@.str = [23 x i8] c"/bin/ls ../Authorized/\00"
@.str.1 = [2 x i8] c"r\00"
@.str.3 = [3 x i8] c"%s\00"
@.str.4 = [12 x i8] c"Length : %d\00"
@.str.5 = [93 x i8] c"br -algorithm FaceRecognition -compare ../uploads/myImage.png ../Authorized/U1/ > OUTPUT.txt\00"
@.str.6 = [5 x i8] c"/n%s\00"
@.str.7 = [11 x i8] c"OUTPUT.txt\00"
@.str.8 = [17 x i8] c"OUTFILE DATA: %s\00"
@str = [22 x i8] c"Failed to run command\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [1035 x i8]
%4 = alloca [1024 x i8]
%5 = alloca [1024 x i8]
%6 = getelementptr inbounds [1035 x i8], [1035 x i8]* %3, i64 0, i64 0
%7 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%8 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%9 = tail call i32* @popen(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%10 = icmp eq i32* %9, null
br i1 %10, label %14, label %11
11: ; preds = %2
%12 = call i32* @fgets(i8* %6, i32 1034, i32* %9)
%13 = icmp eq i32* %12, null
br i1 %13, label %33, label %20
14: ; preds = %2
%15 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str, i64 0, i64 0))
%16 = tail call i32 @exit(i32 1)
unreachable
17: ; preds = %29, %20
%18 = call i32* @fgets(i8* %6, i32 1034, i32* %9)
%19 = icmp eq i32* %18, null
br i1 %19, label %33, label %20
20: ; preds = %11, %17
%21 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %6)
%22 = call i32 @strlen(i8* %6)
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i32 %22)
%24 = call i32 @system(i8* %7)
%25 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0), i8* %7)
%26 = call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%27 = call i32* @fgets(i8* %8, i32 1023, i32* %26)
%28 = icmp eq i32* %27, null
br i1 %28, label %17, label %29
29: ; preds = %20, %29
%30 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.8, i64 0, i64 0), i8* %8)
%31 = call i32* @fgets(i8* %8, i32 1023, i32* %26)
%32 = icmp eq i32* %31, null
br i1 %32, label %17, label %29
33: ; preds = %17, %11
%34 = call i32 @pclose(i32* %9)
ret i32 0
}