#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*/ Write_File(char *, char *);
int /*<<< orphan*/ bzero(char *, int);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ pclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *popen(char *, char *);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ strncat(char *, char *, int);
int /*<<< orphan*/ strncpy(char *, char *, int);
scalar_t__ strstr(char *, char *);
int main() {
  FILE *fp;
  char buffer[500 + 1], tmp[(500 << 1) + 3];
  puts("Simple nmap Bot :: by Cooler_");
  fp = popen("/usr/bin/nmap 192.168.0.1/24", "r");
  while (fgets(buffer, 500, fp) != NULL) {
    if (strstr(buffer, "report")) {
      fprintf(stdout, "%s", buffer);
      bzero(tmp, (500 << 1) + 2);
      strncpy(tmp, buffer, 500);
    }
    if (strstr(buffer, "open  ssh")) {
      fprintf(stdout, "DORK HERE hohoho \n %s\n", buffer);
      strncat(tmp, buffer, 500);
      Write_File("log_nmap.txt", tmp);
    }
  }
  pclose(fp);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x600,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe47(%rip),%rdi
call   1040 <puts@plt>
lea    0xe59(%rip),%rdi
lea    0xe6f(%rip),%rsi
call   10a0 <popen@plt>
mov    %rax,-0x10(%rbp)
lea    -0x210(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x1f4,%esi
call   1080 <fgets@plt>
cmp    $0x0,%rax
je     12bf <main+0x11f>
lea    -0x210(%rbp),%rdi
lea    0xe3b(%rip),%rsi
call   10c0 <strstr@plt>
cmp    $0x0,%rax
je     1256 <main+0xb6>
mov    0x2dc8(%rip),%rax
mov    (%rax),%edi
lea    -0x210(%rbp),%rdx
lea    0xe1c(%rip),%rsi
call   1090 <fprintf@plt>
lea    -0x600(%rbp),%rdi
mov    $0x3ea,%esi
call   10b0 <bzero@plt>
lea    -0x600(%rbp),%rdi
lea    -0x210(%rbp),%rsi
mov    $0x1f4,%edx
call   1030 <strncpy@plt>
lea    -0x210(%rbp),%rdi
lea    0xde3(%rip),%rsi
call   10c0 <strstr@plt>
cmp    $0x0,%rax
je     12ba <main+0x11a>
mov    0x2d66(%rip),%rax
mov    (%rax),%edi
lea    -0x210(%rbp),%rdx
lea    0xdc7(%rip),%rsi
call   1090 <fprintf@plt>
lea    -0x600(%rbp),%rdi
lea    -0x210(%rbp),%rsi
mov    $0x1f4,%edx
call   1070 <strncat@plt>
lea    -0x600(%rbp),%rsi
lea    0xdb3(%rip),%rdi
call   1060 <Write_File@plt>
jmp    11d5 <main+0x35>
mov    -0x10(%rbp),%rdi
call   1050 <pclose@plt>
xor    %eax,%eax
add    $0x600,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x5f8,%rsp
lea    0xe48(%rip),%rdi
call   1040 <puts@plt>
lea    0xe5a(%rip),%rdi
lea    0xe70(%rip),%rsi
call   10a0 <popen@plt>
mov    %rax,%r15
mov    %rsp,%rdi
mov    $0x1f4,%esi
mov    %rax,%rdx
call   1080 <fgets@plt>
test   %rax,%rax
je     12b0 <main+0x110>
lea    0xe4a(%rip),%r14
mov    %rsp,%rbx
lea    0xe4a(%rip),%r12
mov    0x2ddc(%rip),%r13
lea    0x200(%rsp),%rbp
jmp    1229 <main+0x89>
xchg   %ax,%ax
mov    %rbx,%rdi
mov    $0x1f4,%esi
mov    %r15,%rdx
call   1080 <fgets@plt>
test   %rax,%rax
je     12b0 <main+0x110>
mov    %rbx,%rdi
mov    %r14,%rsi
call   10c0 <strstr@plt>
test   %rax,%rax
je     1269 <main+0xc9>
mov    0x0(%r13),%edi
lea    0xe00(%rip),%rsi
mov    %rbx,%rdx
call   1090 <fprintf@plt>
mov    %rbp,%rdi
mov    $0x3ea,%esi
call   10b0 <bzero@plt>
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    $0x1f4,%edx
call   1030 <strncpy@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
call   10c0 <strstr@plt>
test   %rax,%rax
je     1210 <main+0x70>
mov    0x0(%r13),%edi
lea    0xdcd(%rip),%rsi
mov    %rbx,%rdx
call   1090 <fprintf@plt>
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    $0x1f4,%edx
call   1070 <strncat@plt>
lea    0xdc5(%rip),%rdi
mov    %rbp,%rsi
call   1060 <Write_File@plt>
jmp    1210 <main+0x70>
mov    %r15,%rdi
call   1050 <pclose@plt>
xor    %eax,%eax
add    $0x5f8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [30 x i8] c"Simple nmap Bot :: by Cooler_\00"
@.str.1 = [29 x i8] c"/usr/bin/nmap 192.168.0.1/24\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [7 x i8] c"report\00"
@stdout = global i32 0
@.str.4 = [3 x i8] c"%s\00"
@.str.5 = [10 x i8] c"open ssh\00"
@.str.6 = [23 x i8] c"DORK HERE hohoho \0A %s\0A\00"
@.str.7 = [13 x i8] c"log_nmap.txt\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca [501 x i8]
%4 = alloca [1003 x i8]
store i32 0, i32* %1
%5 = call i32 @puts(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
%6 = call i32* @popen(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %6, i32** %2
br label %7
7: ; preds = %38, %0
%8 = getelementptr inbounds [501 x i8], [501 x i8]* %3, i64 0, i64 0
%9 = load i32*, i32** %2
%10 = call i32* @fgets(i8* %8, i32 500, i32* %9)
%11 = icmp ne i32* %10, null
br i1 %11, label %12, label %39
12: ; preds = %7
%13 = getelementptr inbounds [501 x i8], [501 x i8]* %3, i64 0, i64 0
%14 = call i64 @strstr(i8* %13, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%15 = icmp ne i64 %14, 0
br i1 %15, label %16, label %25
16: ; preds = %12
%17 = load i32, i32* @stdout
%18 = getelementptr inbounds [501 x i8], [501 x i8]* %3, i64 0, i64 0
%19 = call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %18)
%20 = getelementptr inbounds [1003 x i8], [1003 x i8]* %4, i64 0, i64 0
%21 = call i32 @bzero(i8* %20, i32 1002)
%22 = getelementptr inbounds [1003 x i8], [1003 x i8]* %4, i64 0, i64 0
%23 = getelementptr inbounds [501 x i8], [501 x i8]* %3, i64 0, i64 0
%24 = call i32 @strncpy(i8* %22, i8* %23, i32 500)
br label %25
25: ; preds = %16, %12
%26 = getelementptr inbounds [501 x i8], [501 x i8]* %3, i64 0, i64 0
%27 = call i64 @strstr(i8* %26, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0))
%28 = icmp ne i64 %27, 0
br i1 %28, label %29, label %38
29: ; preds = %25
%30 = load i32, i32* @stdout
%31 = getelementptr inbounds [501 x i8], [501 x i8]* %3, i64 0, i64 0
%32 = call i32 @fprintf(i32 %30, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.6, i64 0, i64 0), i8* %31)
%33 = getelementptr inbounds [1003 x i8], [1003 x i8]* %4, i64 0, i64 0
%34 = getelementptr inbounds [501 x i8], [501 x i8]* %3, i64 0, i64 0
%35 = call i32 @strncat(i8* %33, i8* %34, i32 500)
%36 = getelementptr inbounds [1003 x i8], [1003 x i8]* %4, i64 0, i64 0
%37 = call i32 @Write_File(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.7, i64 0, i64 0), i8* %36)
br label %38
38: ; preds = %29, %25
br label %7
39: ; preds = %7
%40 = load i32*, i32** %2
%41 = call i32 @pclose(i32* %40)
ret i32 0
}

LLVM IR (-O2):
@.str = [30 x i8] c"Simple nmap Bot :: by Cooler_\00"
@.str.1 = [29 x i8] c"/usr/bin/nmap 192.168.0.1/24\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [7 x i8] c"report\00"
@stdout = global i32 0
@.str.4 = [3 x i8] c"%s\00"
@.str.5 = [10 x i8] c"open ssh\00"
@.str.6 = [23 x i8] c"DORK HERE hohoho \0A %s\0A\00"
@.str.7 = [13 x i8] c"log_nmap.txt\00"
define i32 @main() {
%1 = alloca [501 x i8]
%2 = alloca [1003 x i8]
%3 = getelementptr inbounds [501 x i8], [501 x i8]* %1, i64 0, i64 0
%4 = getelementptr inbounds [1003 x i8], [1003 x i8]* %2, i64 0, i64 0
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
%6 = tail call i32* @popen(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%7 = call i32* @fgets(i8* %3, i32 500, i32* %6)
%8 = icmp eq i32* %7, null
br i1 %8, label %28, label %9
9: ; preds = %0, %25
%10 = call i64 @strstr(i8* %3, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%11 = icmp eq i64 %10, 0
br i1 %11, label %17, label %12
12: ; preds = %9
%13 = load i32, i32* @stdout
%14 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %3)
%15 = call i32 @bzero(i8* %4, i32 1002)
%16 = call i32 @strncpy(i8* %4, i8* %3, i32 500)
br label %17
17: ; preds = %12, %9
%18 = call i64 @strstr(i8* %3, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0))
%19 = icmp eq i64 %18, 0
br i1 %19, label %25, label %20
20: ; preds = %17
%21 = load i32, i32* @stdout
%22 = call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.6, i64 0, i64 0), i8* %3)
%23 = call i32 @strncat(i8* %4, i8* %3, i32 500)
%24 = call i32 @Write_File(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.7, i64 0, i64 0), i8* %4)
br label %25
25: ; preds = %20, %17
%26 = call i32* @fgets(i8* %3, i32 500, i32* %6)
%27 = icmp eq i32* %26, null
br i1 %27, label %28, label %9
28: ; preds = %25, %0
%29 = call i32 @pclose(i32* %6)
ret i32 0
}