#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 /*<<< orphan*/ exit(int);
int /*<<< orphan*/ printf(char *, ...);
void usage(char *err) {
  printf(
      "    Shellcode testing program\n    Usage:\n        shtest {-f file | "
      "$'\\xeb\\xfe' | '\\xb8\\x39\\x05\\x00\\x00\\xc3'}\n    Usage example:\n "
      "       $ shtest $'\\xeb\\xfe'                 # raw shellcode\n        "
      "$ shtest '\\xb8\\x39\\x05\\x00\\x00\\xc3'  # escaped shellcode\n        "
      "$ shtest -f test.sc                  # shellcode from file\n        $ "
      "shtest -f <(python gen_payload.py) # test generated payload\n        $ "
      "shtest -s 5 -f test.sc             # create socket at fd=5 (STDIN <- "
      "SOCKET -> STDOUT)\n            # Allows to test staged shellcodes       "
      "     # Flow is redirected like this: STDIN -> SOCKET -> STDOUT    "
      "Compiling:\n        gcc -Wall shtest.c -o shtest\n    Author: hellman "
      "(hellman1908@gmail.com)\n");
  if (err)
    printf("\nerr: %s\n", err);
  exit(1);
}


x86 assembly (clang, -O0):
<usage>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
lea    0xecd(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpq   $0x0,-0x8(%rbp)
je     1157 <usage+0x37>
mov    -0x8(%rbp),%rsi
lea    0x116c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1,%edi
call   1040 <exit@plt>

x86 assembly (clang, -O2):
<usage>:
push   %rbx
mov    %rdi,%rbx
lea    0xecf(%rip),%rdi
call   1030 <puts@plt>
test   %rbx,%rbx
je     1156 <usage+0x26>
lea    0xeb4(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@.str = [700 x i8] c" Shellcode testing program\0A Usage:\0A shtest {-f file | $'\\xeb\\xfe' | '\\xb8\\x39\\x05\\x00\\x00\\xc3'}\0A Usage example:\0A $ shtest $'\\xeb\\xfe' # raw shellcode\0A $ shtest '\\xb8\\x39\\x05\\x00\\x00\\xc3' # escaped shellcode\0A $ shtest -f test.sc # shellcode from file\0A $ shtest -f <(python gen_payload.py) # test generated payload\0A $ shtest -s 5 -f test.sc # create socket at fd=5 (STDIN <- SOCKET -> STDOUT)\0A # Allows to test staged shellcodes # Flow is redirected like this: STDIN -> SOCKET -> STDOUT Compiling:\0A gcc -Wall shtest.c -o shtest\0A Author: hellman (hellman1908@gmail.com)\0A\00"
@.str.1 = [10 x i8] c"\0Aerr: %s\0A\00"
define void @usage(i8* %0) {
%2 = alloca i8*
store i8* %0, i8** %2
%3 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([700 x i8], [700 x i8]* @.str, i64 0, i64 0))
%4 = load i8*, i8** %2
%5 = icmp ne i8* %4, null
br i1 %5, label %6, label %9
6: ; preds = %1
%7 = load i8*, i8** %2
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* %7)
br label %9
9: ; preds = %6, %1
%10 = call i32 @exit(i32 1)
unreachable
}

LLVM IR (-O2):
@.str.1 = [10 x i8] c"\0Aerr: %s\0A\00"
@str = [699 x i8] c" Shellcode testing program\0A Usage:\0A shtest {-f file | $'\\xeb\\xfe' | '\\xb8\\x39\\x05\\x00\\x00\\xc3'}\0A Usage example:\0A $ shtest $'\\xeb\\xfe' # raw shellcode\0A $ shtest '\\xb8\\x39\\x05\\x00\\x00\\xc3' # escaped shellcode\0A $ shtest -f test.sc # shellcode from file\0A $ shtest -f <(python gen_payload.py) # test generated payload\0A $ shtest -s 5 -f test.sc # create socket at fd=5 (STDIN <- SOCKET -> STDOUT)\0A # Allows to test staged shellcodes # Flow is redirected like this: STDIN -> SOCKET -> STDOUT Compiling:\0A gcc -Wall shtest.c -o shtest\0A Author: hellman (hellman1908@gmail.com)\00"
define void @usage(i8* %0) {
%2 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([699 x i8], [699 x i8]* @str, i64 0, i64 0))
%3 = icmp eq i8* %0, null
br i1 %3, label %6, label %4
4: ; preds = %1
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %6
6: ; preds = %4, %1
%7 = tail call i32 @exit(i32 1)
unreachable
}