#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*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ R_OK;
scalar_t__ access(char *, int /*<<< orphan*/);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ *popen(char *, char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ sprintf(char *, char *, char *, char *);
scalar_t__ strstr(char *, char *);
int /*<<< orphan*/ system(char *);
int main(int argc, char *argv[]) {
  char buffer[256];
  char newline[256];
  FILE *fp;
  if (access("/tmp/data.tmp", R_OK) == 0) {
    printf("[+] The file:%s is exist\n", "/tmp/data.tmp");
    sprintf(buffer, "%s %s", "/usr/bin/file", "/tmp/data.tmp");
    fp = popen(buffer, "r");
    fgets(newline, 256, fp);
    fclose(fp);
    sleep(3);
    if (strstr(newline, "ELF") > 0) {
      printf("[+] The file is ELF format\n");
      fp = fopen("/tmp/data.tmp", "r");
      if (fp == NULL) {
        printf("[-] Error: unable to open the file\n");
        exit(0);
      }
      fgets(newline, 256, fp);
      fclose(fp);
      printf("[+] read ok\n");
      system(newline);
    } else {
      printf("[-] The file is not ELF\n");
    }
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x220,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e10(%rip),%rax
mov    (%rax),%esi
lea    0xe27(%rip),%rdi
call   1070 <access@plt>
cmp    $0x0,%rax
jne    1324 <main+0x174>
lea    0xe1f(%rip),%rdi
lea    0xe0a(%rip),%rsi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x110(%rbp),%rdi
lea    0xe1d(%rip),%rsi
lea    0xe1c(%rip),%rdx
lea    0xde7(%rip),%rcx
call   10a0 <sprintf@plt>
lea    -0x110(%rbp),%rdi
lea    0xe10(%rip),%rsi
call   1080 <popen@plt>
mov    %rax,-0x218(%rbp)
lea    -0x210(%rbp),%rdi
mov    -0x218(%rbp),%rdx
mov    $0x100,%esi
call   1060 <fgets@plt>
mov    -0x218(%rbp),%rdi
call   1030 <fclose@plt>
mov    $0x3,%edi
call   10c0 <sleep@plt>
lea    -0x210(%rbp),%rdi
lea    0xdca(%rip),%rsi
call   10d0 <strstr@plt>
cmp    $0x0,%rax
jle    1311 <main+0x161>
lea    0xdb8(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xd68(%rip),%rdi
lea    0xd9d(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x218(%rbp)
cmpq   $0x0,-0x218(%rbp)
jne    12ce <main+0x11e>
lea    0xd9e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
xor    %edi,%edi
call   10b0 <exit@plt>
lea    -0x210(%rbp),%rdi
mov    -0x218(%rbp),%rdx
mov    $0x100,%esi
call   1060 <fgets@plt>
mov    -0x218(%rbp),%rdi
call   1030 <fclose@plt>
lea    0xd89(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x210(%rbp),%rdi
call   1040 <system@plt>
jmp    131f <main+0x16f>
lea    0xd77(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1324 <main+0x174>
mov    -0x4(%rbp),%eax
add    $0x220,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x208,%rsp
mov    0x2e0f(%rip),%rax
mov    (%rax),%esi
lea    0xe26(%rip),%rdi
call   1080 <access@plt>
test   %rax,%rax
jne    12d0 <main+0x110>
lea    0xe1f(%rip),%rdi
lea    0xe0a(%rip),%r14
mov    %r14,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe21(%rip),%rsi
lea    0xe20(%rip),%rdx
lea    0x100(%rsp),%rbx
mov    %rbx,%rdi
mov    %r14,%rcx
call   10b0 <sprintf@plt>
lea    0xe14(%rip),%rsi
mov    %rbx,%rdi
call   1090 <popen@plt>
mov    %rax,%rbx
mov    %rsp,%r14
mov    %r14,%rdi
mov    $0x100,%esi
mov    %rax,%rdx
call   1070 <fgets@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    $0x3,%edi
call   10d0 <sleep@plt>
lea    0xdf3(%rip),%rsi
mov    %r14,%rdi
call   10e0 <strstr@plt>
test   %rax,%rax
jle    12c4 <main+0x104>
lea    0xde3(%rip),%rdi
call   1030 <puts@plt>
lea    0xd81(%rip),%rdi
lea    0xdb6(%rip),%rsi
call   10a0 <fopen@plt>
test   %rax,%rax
je     12dd <main+0x11d>
mov    %rax,%rbx
mov    %rsp,%r14
mov    %r14,%rdi
mov    $0x100,%esi
mov    %rax,%rdx
call   1070 <fgets@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
lea    0xdbc(%rip),%rdi
call   1030 <puts@plt>
mov    %r14,%rdi
call   1050 <system@plt>
jmp    12d0 <main+0x110>
lea    0xd73(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x208,%rsp
pop    %rbx
pop    %r14
ret
lea    0xd99(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
@.str = [14 x i8] c"/tmp/data.tmp\00"
@R_OK = global i32 0
@.str.1 = [26 x i8] c"[+] The file:%s is exist\0A\00"
@.str.2 = [6 x i8] c"%s %s\00"
@.str.3 = [14 x i8] c"/usr/bin/file\00"
@.str.4 = [2 x i8] c"r\00"
@.str.5 = [4 x i8] c"ELF\00"
@.str.6 = [28 x i8] c"[+] The file is ELF format\0A\00"
@.str.7 = [36 x i8] c"[-] Error: unable to open the file\0A\00"
@.str.8 = [13 x i8] c"[+] read ok\0A\00"
@.str.9 = [25 x i8] c"[-] The file is not ELF\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [256 x i8]
%7 = alloca [256 x i8]
%8 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* @R_OK
%10 = call i64 @access(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %9)
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %47
12: ; preds = %2
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%14 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%15 = call i32 @sprintf(i8* %14, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%16 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%17 = call i32* @popen(i8* %16, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32* %17, i32** %8
%18 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%19 = load i32*, i32** %8
%20 = call i32 @fgets(i8* %18, i32 256, i32* %19)
%21 = load i32*, i32** %8
%22 = call i32 @fclose(i32* %21)
%23 = call i32 @sleep(i32 3)
%24 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%25 = call i64 @strstr(i8* %24, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0))
%26 = icmp sgt i64 %25, 0
br i1 %26, label %27, label %44
27: ; preds = %12
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.6, i64 0, i64 0))
%29 = call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32* %29, i32** %8
%30 = load i32*, i32** %8
%31 = icmp eq i32* %30, null
br i1 %31, label %32, label %35
32: ; preds = %27
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.7, i64 0, i64 0))
%34 = call i32 @exit(i32 0)
unreachable
35: ; preds = %27
%36 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%37 = load i32*, i32** %8
%38 = call i32 @fgets(i8* %36, i32 256, i32* %37)
%39 = load i32*, i32** %8
%40 = call i32 @fclose(i32* %39)
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.8, i64 0, i64 0))
%42 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%43 = call i32 @system(i8* %42)
br label %46
44: ; preds = %12
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.9, i64 0, i64 0))
br label %46
46: ; preds = %44, %35
br label %47
47: ; preds = %46, %2
%48 = load i32, i32* %3
ret i32 %48
}

LLVM IR (-O2):
@.str = [14 x i8] c"/tmp/data.tmp\00"
@R_OK = global i32 0
@.str.1 = [26 x i8] c"[+] The file:%s is exist\0A\00"
@.str.2 = [6 x i8] c"%s %s\00"
@.str.3 = [14 x i8] c"/usr/bin/file\00"
@.str.4 = [2 x i8] c"r\00"
@.str.5 = [4 x i8] c"ELF\00"
@str = [24 x i8] c"[-] The file is not ELF\00"
@str.10 = [27 x i8] c"[+] The file is ELF format\00"
@str.11 = [12 x i8] c"[+] read ok\00"
@str.12 = [35 x i8] c"[-] Error: unable to open the file\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [256 x i8]
%4 = alloca [256 x i8]
%5 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%7 = load i32, i32* @R_OK
%8 = tail call i64 @access(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %7)
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %33
10: ; preds = %2
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%12 = call i32 @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%13 = call i32* @popen(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%14 = call i32 @fgets(i8* %6, i32 256, i32* %13)
%15 = call i32 @fclose(i32* %13)
%16 = call i32 @sleep(i32 3)
%17 = call i64 @strstr(i8* %6, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0))
%18 = icmp sgt i64 %17, 0
br i1 %18, label %19, label %31
19: ; preds = %10
%20 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str.10, i64 0, i64 0))
%21 = call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%22 = icmp eq i32* %21, null
br i1 %22, label %23, label %26
23: ; preds = %19
%24 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @str.12, i64 0, i64 0))
%25 = call i32 @exit(i32 0)
unreachable
26: ; preds = %19
%27 = call i32 @fgets(i8* %6, i32 256, i32* %21)
%28 = call i32 @fclose(i32* %21)
%29 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str.11, i64 0, i64 0))
%30 = call i32 @system(i8* %6)
br label %33
31: ; preds = %10
%32 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str, i64 0, i64 0))
br label %33
33: ; preds = %26, %31, %2
ret i32 0
}