#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*/ system(char *);
int main(int argc, char *argv[]) {
  FILE *fp;
  char path[1035];
  fp = popen("/bin/ls /etc/", "r");
  system("br -algorithm FaceRecognition -compare ../Authorized/U1/C2.png "
         "../Authorized/U1/ {[a]} > result.txt");
  if (fp == NULL) {
    printf("Failed to run command\n");
    exit(1);
  }
  while (fgets(path, sizeof(path) - 1, fp) != NULL) {
  }
  pclose(fp);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe80(%rip),%rdi
lea    0xe87(%rip),%rsi
call   1070 <popen@plt>
mov    %rax,-0x18(%rbp)
lea    0xe79(%rip),%rdi
call   1030 <system@plt>
cmpq   $0x0,-0x18(%rbp)
jne    11bd <main+0x5d>
lea    0xec6(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
jmp    11c2 <main+0x62>
lea    -0x430(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x40a,%esi
call   1060 <fgets@plt>
cmp    $0x0,%rax
je     11e6 <main+0x86>
jmp    11c2 <main+0x62>
mov    -0x18(%rbp),%rdi
call   1050 <pclose@plt>
xor    %eax,%eax
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x418,%rsp
lea    0xe8f(%rip),%rdi
lea    0xe96(%rip),%rsi
call   1070 <popen@plt>
mov    %rax,%rbx
lea    0xe89(%rip),%rdi
call   1040 <system@plt>
test   %rbx,%rbx
je     11ca <main+0x6a>
mov    %rsp,%r14
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r14,%rdi
mov    $0x40a,%esi
mov    %rbx,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
jne    11a0 <main+0x40>
mov    %rbx,%rdi
call   1050 <pclose@plt>
xor    %eax,%eax
add    $0x418,%rsp
pop    %rbx
pop    %r14
ret
lea    0xea3(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [14 x i8] c"/bin/ls /etc/\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [100 x i8] c"br -algorithm FaceRecognition -compare ../Authorized/U1/C2.png ../Authorized/U1/ {[a]} > result.txt\00"
@.str.3 = [23 x i8] c"Failed to run command\0A\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]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = call i32* @popen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %8, i32** %6
%9 = call i32 @system(i8* getelementptr inbounds ([100 x i8], [100 x i8]* @.str.2, i64 0, i64 0))
%10 = load i32*, i32** %6
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %15
12: ; preds = %2
%13 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0))
%14 = call i32 @exit(i32 1)
unreachable
15: ; preds = %2
br label %16
16: ; preds = %21, %15
%17 = getelementptr inbounds [1035 x i8], [1035 x i8]* %7, i64 0, i64 0
%18 = load i32*, i32** %6
%19 = call i32* @fgets(i8* %17, i32 1034, i32* %18)
%20 = icmp ne i32* %19, null
br i1 %20, label %21, label %22
21: ; preds = %16
br label %16
22: ; preds = %16
%23 = load i32*, i32** %6
%24 = call i32 @pclose(i32* %23)
ret i32 0
}

LLVM IR (-O2):
@.str = [14 x i8] c"/bin/ls /etc/\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [100 x i8] c"br -algorithm FaceRecognition -compare ../Authorized/U1/C2.png ../Authorized/U1/ {[a]} > result.txt\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 = getelementptr inbounds [1035 x i8], [1035 x i8]* %3, i64 0, i64 0
%5 = tail call i32* @popen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%6 = tail call i32 @system(i8* getelementptr inbounds ([100 x i8], [100 x i8]* @.str.2, i64 0, i64 0))
%7 = icmp eq i32* %5, null
br i1 %7, label %8, label %11
8: ; preds = %2
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str, i64 0, i64 0))
%10 = tail call i32 @exit(i32 1)
unreachable
11: ; preds = %2, %11
%12 = call i32* @fgets(i8* %4, i32 1034, i32* %5)
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %11
14: ; preds = %11
%15 = call i32 @pclose(i32* %5)
ret i32 0
}