#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 */
int AUDIT_ARCH_I386;
int AUDIT_ARCH_X86_64;
int /*<<< orphan*/ execv(char *, char **);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int, int);
scalar_t__ install_filter(int /*<<< orphan*/, int /*<<< orphan*/,
                          int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strtol(char *, int /*<<< orphan*/ *, int /*<<< orphan*/);
int main(int argc, char **argv) {
  if (argc < 5) {
    fprintf(stderr,
            "Usage:\n"
            "dropper <syscall_nr> <arch> <errno> <prog> [<args>]\n"
            "Hint:	AUDIT_ARCH_I386: 0x%X\n"
            "	AUDIT_ARCH_X86_64: 0x%X\n"
            "\n",
            AUDIT_ARCH_I386, AUDIT_ARCH_X86_64);
    return 1;
  }
  if (install_filter(strtol(argv[1], NULL, 0), strtol(argv[2], NULL, 0),
                     strtol(argv[3], NULL, 0)))
    return 1;
  execv(argv[4], &argv[4]);
  printf("Failed to execv\n");
  return 255;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x5,-0x8(%rbp)
jge    11a3 <main+0x53>
mov    0x2e61(%rip),%rax
mov    (%rax),%edi
mov    0x2e50(%rip),%rax
mov    (%rax),%edx
mov    0x2e5f(%rip),%rax
mov    (%rax),%ecx
lea    0xe6e(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    122d <main+0xdd>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1060 <strtol@plt>
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1060 <strtol@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1060 <strtol@plt>
mov    -0x18(%rbp),%edi
mov    -0x14(%rbp),%esi
mov    %eax,%edx
call   1040 <install_filter@plt>
cmp    $0x0,%rax
je     1205 <main+0xb5>
movl   $0x1,-0x4(%rbp)
jmp    122d <main+0xdd>
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rdi
mov    -0x10(%rbp),%rsi
add    $0x20,%rsi
call   1070 <execv@plt>
lea    0xe51(%rip),%rdi
call   1030 <printf@plt>
movl   $0xff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
cmp    $0x4,%edi
jg     1187 <main+0x37>
mov    0x2e78(%rip),%rax
mov    (%rax),%edi
mov    0x2e67(%rip),%rax
mov    (%rax),%edx
mov    0x2e76(%rip),%rax
mov    (%rax),%ecx
lea    0xe85(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%eax
jmp    11f0 <main+0xa0>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1060 <strtol@plt>
mov    %eax,%r14d
mov    0x10(%rbx),%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1060 <strtol@plt>
mov    %eax,%ebp
mov    0x18(%rbx),%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1060 <strtol@plt>
mov    %r14d,%edi
mov    %ebp,%esi
mov    %eax,%edx
call   1040 <install_filter@plt>
mov    %rax,%rcx
mov    $0x1,%eax
test   %rcx,%rcx
jne    11f0 <main+0xa0>
mov    0x20(%rbx),%rdi
add    $0x20,%rbx
mov    %rbx,%rsi
call   1070 <execv@plt>
lea    0xe8c(%rip),%rdi
call   1030 <puts@plt>
mov    $0xff,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [114 x i8] c"Usage:\0Adropper <syscall_nr> <arch> <errno> <prog> [<args>]\0AHint:\09AUDIT_ARCH_I386: 0x%X\0A\09AUDIT_ARCH_X86_64: 0x%X\0A\0A\00"
@AUDIT_ARCH_I386 = global i32 0
@AUDIT_ARCH_X86_64 = global i32 0
@.str.1 = [17 x i8] c"Failed to execv\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%6 = load i32, i32* %4
%7 = icmp slt i32 %6, 5
br i1 %7, label %8, label %13
8: ; preds = %2
%9 = load i32, i32* @stderr
%10 = load i32, i32* @AUDIT_ARCH_I386
%11 = load i32, i32* @AUDIT_ARCH_X86_64
%12 = call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([114 x i8], [114 x i8]* @.str, i64 0, i64 0), i32 %10, i32 %11)
store i32 1, i32* %3
br label %37
13: ; preds = %2
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 1
%16 = load i8*, i8** %15
%17 = call i32 @strtol(i8* %16, i32* null, i32 0)
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 2
%20 = load i8*, i8** %19
%21 = call i32 @strtol(i8* %20, i32* null, i32 0)
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 3
%24 = load i8*, i8** %23
%25 = call i32 @strtol(i8* %24, i32* null, i32 0)
%26 = call i64 @install_filter(i32 %17, i32 %21, i32 %25)
%27 = icmp ne i64 %26, 0
br i1 %27, label %28, label %29
28: ; preds = %13
store i32 1, i32* %3
br label %37
29: ; preds = %13
%30 = load i8**, i8*** %5
%31 = getelementptr inbounds i8*, i8** %30, i64 4
%32 = load i8*, i8** %31
%33 = load i8**, i8*** %5
%34 = getelementptr inbounds i8*, i8** %33, i64 4
%35 = call i32 @execv(i8* %32, i8** %34)
%36 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
store i32 255, i32* %3
br label %37
37: ; preds = %29, %28, %8
%38 = load i32, i32* %3
ret i32 %38
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [114 x i8] c"Usage:\0Adropper <syscall_nr> <arch> <errno> <prog> [<args>]\0AHint:\09AUDIT_ARCH_I386: 0x%X\0A\09AUDIT_ARCH_X86_64: 0x%X\0A\0A\00"
@AUDIT_ARCH_I386 = global i32 0
@AUDIT_ARCH_X86_64 = global i32 0
@str = [16 x i8] c"Failed to execv\00"
define i32 @main(i32 %0, i8** %1) {
%3 = icmp slt i32 %0, 5
br i1 %3, label %4, label %9
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = load i32, i32* @AUDIT_ARCH_I386
%7 = load i32, i32* @AUDIT_ARCH_X86_64
%8 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([114 x i8], [114 x i8]* @.str, i64 0, i64 0), i32 %6, i32 %7)
br label %26
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = tail call i32 @strtol(i8* nocapture %11, i32* null, i32 0)
%13 = getelementptr inbounds i8*, i8** %1, i64 2
%14 = load i8*, i8** %13
%15 = tail call i32 @strtol(i8* nocapture %14, i32* null, i32 0)
%16 = getelementptr inbounds i8*, i8** %1, i64 3
%17 = load i8*, i8** %16
%18 = tail call i32 @strtol(i8* nocapture %17, i32* null, i32 0)
%19 = tail call i64 @install_filter(i32 %12, i32 %15, i32 %18)
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %26
21: ; preds = %9
%22 = getelementptr inbounds i8*, i8** %1, i64 4
%23 = load i8*, i8** %22
%24 = tail call i32 @execv(i8* %23, i8** %22)
%25 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str, i64 0, i64 0))
br label %26
26: ; preds = %9, %21, %4
%27 = phi i32 [ 1, %4 ], [ 255, %21 ], [ 1, %9 ]
ret i32 %27
}