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

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
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;
  char path[1035];
  char comPath[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);
  }
  pclose(fp);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x840,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe60(%rip),%rdi
lea    0xe70(%rip),%rsi
call   1080 <popen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11d3 <main+0x53>
lea    0xe57(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
jmp    11d8 <main+0x58>
lea    -0x430(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x40a,%esi
call   1070 <fgets@plt>
cmp    $0x0,%rax
je     126b <main+0xeb>
lea    -0x430(%rbp),%rsi
lea    0xe96(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x430(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x834(%rbp)
mov    -0x834(%rbp),%esi
lea    0xe05(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x830(%rbp),%rdi
lea    0xdfc(%rip),%rsi
call   1090 <sprintf@plt>
lea    -0x830(%rbp),%rdi
call   1040 <system@plt>
lea    -0x830(%rbp),%rsi
lea    0xe3a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    11d8 <main+0x58>
mov    -0x18(%rbp),%rdi
call   1060 <pclose@plt>
xor    %eax,%eax
add    $0x840,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x818,%rsp
lea    0xe68(%rip),%rdi
lea    0xe78(%rip),%rsi
call   1090 <popen@plt>
test   %rax,%rax
je     12a2 <main+0x122>
mov    %rax,%r15
lea    0x400(%rsp),%rdi
mov    $0x40a,%esi
mov    %rax,%rdx
call   1080 <fgets@plt>
test   %rax,%rax
je     1286 <main+0x106>
lea    0xeaf(%rip),%r14
lea    0x400(%rsp),%rbx
lea    0xe35(%rip),%r12
mov    %rsp,%r13
lea    0xe94(%rip),%rbp
xchg   %ax,%ax
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %r12,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
movups 0xe0d(%rip),%xmm0
movaps %xmm0,(%rsp)
movups 0xe12(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movups 0xe16(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movups 0xe1a(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
movups 0xe1e(%rip),%xmm0
movaps %xmm0,0x40(%rsp)
movups 0xe1f(%rip),%xmm0
movups %xmm0,0x4d(%rsp)
mov    %r13,%rdi
call   1050 <system@plt>
mov    %rbp,%rdi
mov    %r13,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %rbx,%rdi
mov    $0x40a,%esi
mov    %r15,%rdx
call   1080 <fgets@plt>
test   %rax,%rax
jne    11f0 <main+0x70>
mov    %r15,%rdi
call   1070 <pclose@plt>
xor    %eax,%eax
add    $0x818,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xdde(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   10a0 <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"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca [1035 x i8]
%8 = alloca [1024 x i8]
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = 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* %10, i32** %6
%11 = load i32*, i32** %6
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %16
13: ; preds = %2
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
%15 = call i32 @exit(i32 1)
unreachable
16: ; preds = %2
br label %17
17: ; preds = %22, %16
%18 = getelementptr inbounds [1035 x i8], [1035 x i8]* %7, i64 0, i64 0
%19 = load i32*, i32** %6
%20 = call i32* @fgets(i8* %18, i32 1034, i32* %19)
%21 = icmp ne i32* %20, null
br i1 %21, label %22, label %35
22: ; preds = %17
%23 = getelementptr inbounds [1035 x i8], [1035 x i8]* %7, i64 0, i64 0
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %23)
%25 = getelementptr inbounds [1035 x i8], [1035 x i8]* %7, i64 0, i64 0
%26 = call i32 @strlen(i8* %25)
store i32 %26, i32* %9
%27 = load i32, i32* %9
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i32 %27)
%29 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%30 = call i32 @sprintf(i8* %29, i8* getelementptr inbounds ([93 x i8], [93 x i8]* @.str.5, i64 0, i64 0))
%31 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%32 = call i32 @system(i8* %31)
%33 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0), i8* %33)
br label %17
35: ; preds = %17
%36 = load i32*, i32** %6
%37 = call i32 @pclose(i32* %36)
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 = [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 = getelementptr inbounds [1035 x i8], [1035 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%7 = 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))
%8 = icmp eq i32* %7, null
br i1 %8, label %12, label %9
9: ; preds = %2
%10 = call i32* @fgets(i8* %5, i32 1034, i32* %7)
%11 = icmp eq i32* %10, null
br i1 %11, label %23, label %15
12: ; preds = %2
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str, i64 0, i64 0))
%14 = tail call i32 @exit(i32 1)
unreachable
15: ; preds = %9, %15
%16 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %5)
%17 = call i32 @strlen(i8* %5)
%18 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i32 %17)
%19 = call i32 @system(i8* %6)
%20 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0), i8* %6)
%21 = call i32* @fgets(i8* %5, i32 1034, i32* %7)
%22 = icmp eq i32* %21, null
br i1 %22, label %23, label %15
23: ; preds = %15, %9
%24 = call i32 @pclose(i32* %7)
ret i32 0
}