#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*/ virus;
typedef int /*<<< orphan*/ promis;

/* Variables and functions */
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ snprintf(char *, int, char *, char *);
int system(char *);
int scan_ip(char *ip) {
  printf("Entre dans scan ip\n");
  int r_p = 0, r_v = 0;
  char virus[512];
  char promis[512];
  snprintf(virus, sizeof(virus) - 1,
           "/usr/bin/nmap -p 445 -d --script smb-check-vulns --script-args "
           "safe=1 %s | /bin/grep -i \"Likely INFECTED\"",
           ip);
  snprintf(promis, sizeof(promis) - 1,
           "/usr/bin/nmap -sS -p1 -n --script=sniffer-detect.nse %s | "
           "/bin/grep -iE \"Likely|libpcap\"",
           ip);
  r_v = system(virus);
  r_p = system(promis);
  if (r_p == 0) {
  }
  if (r_v == 0) {
  }
  if (r_p != 0 && r_v != 0)
    return 1;
  if (r_v == 0)
    return 2;
  return 0;
}


x86 assembly (clang, -O0):
<scan_ip>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    %rdi,-0x10(%rbp)
lea    0xeba(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
lea    -0x220(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x1ff,%esi
lea    0xea4(%rip),%rdx
call   1050 <snprintf@plt>
lea    -0x420(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x1ff,%esi
lea    0xef2(%rip),%rdx
call   1050 <snprintf@plt>
lea    -0x220(%rbp),%rdi
call   1030 <system@plt>
mov    %eax,-0x18(%rbp)
lea    -0x420(%rbp),%rdi
call   1030 <system@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    11be <scan_ip+0x8e>
jmp    11be <scan_ip+0x8e>
cmpl   $0x0,-0x18(%rbp)
jne    11cd <scan_ip+0x9d>
jmp    11cd <scan_ip+0x9d>
cmpl   $0x0,-0x14(%rbp)
je     11ed <scan_ip+0xbd>
cmpl   $0x0,-0x18(%rbp)
je     11ed <scan_ip+0xbd>
movl   $0x1,-0x4(%rbp)
jmp    120a <scan_ip+0xda>
cmpl   $0x0,-0x18(%rbp)
jne    1203 <scan_ip+0xd3>
movl   $0x2,-0x4(%rbp)
jmp    120a <scan_ip+0xda>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<scan_ip>:
push   %r15
push   %r14
push   %rbx
sub    $0x400,%rsp
mov    %rdi,%rbx
lea    0xf7d(%rip),%rdi
call   1030 <puts@plt>
lea    0xeae(%rip),%rdx
lea    0x200(%rsp),%r14
mov    %r14,%rdi
mov    $0x1ff,%esi
mov    %rbx,%rcx
call   1050 <snprintf@plt>
lea    0xef9(%rip),%rdx
mov    %rsp,%r15
mov    %r15,%rdi
mov    $0x1ff,%esi
mov    %rbx,%rcx
call   1050 <snprintf@plt>
mov    %r14,%rdi
call   1040 <system@plt>
mov    %eax,%ebx
mov    %r15,%rdi
call   1040 <system@plt>
xor    %ecx,%ecx
test   %ebx,%ebx
sete   %cl
add    %ecx,%ecx
test   %eax,%eax
mov    $0x1,%eax
cmove  %ecx,%eax
test   %ebx,%ebx
cmove  %ecx,%eax
add    $0x400,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [20 x i8] c"Entre dans scan ip\0A\00"
@.str.1 = [106 x i8] c"/usr/bin/nmap -p 445 -d --script smb-check-vulns --script-args safe=1 %s | /bin/grep -i \22Likely INFECTED\22\00"
@.str.2 = [89 x i8] c"/usr/bin/nmap -sS -p1 -n --script=sniffer-detect.nse %s | /bin/grep -iE \22Likely|libpcap\22\00"
define i32 @scan_ip(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca [512 x i8]
%7 = alloca [512 x i8]
store i8* %0, i8** %3
%8 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %4
store i32 0, i32* %5
%9 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%10 = load i8*, i8** %3
%11 = call i32 @snprintf(i8* %9, i32 511, i8* getelementptr inbounds ([106 x i8], [106 x i8]* @.str.1, i64 0, i64 0), i8* %10)
%12 = getelementptr inbounds [512 x i8], [512 x i8]* %7, i64 0, i64 0
%13 = load i8*, i8** %3
%14 = call i32 @snprintf(i8* %12, i32 511, i8* getelementptr inbounds ([89 x i8], [89 x i8]* @.str.2, i64 0, i64 0), i8* %13)
%15 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%16 = call i32 @system(i8* %15)
store i32 %16, i32* %5
%17 = getelementptr inbounds [512 x i8], [512 x i8]* %7, i64 0, i64 0
%18 = call i32 @system(i8* %17)
store i32 %18, i32* %4
%19 = load i32, i32* %4
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %22
21: ; preds = %1
br label %22
22: ; preds = %21, %1
%23 = load i32, i32* %5
%24 = icmp eq i32 %23, 0
br i1 %24, label %25, label %26
25: ; preds = %22
br label %26
26: ; preds = %25, %22
%27 = load i32, i32* %4
%28 = icmp ne i32 %27, 0
br i1 %28, label %29, label %33
29: ; preds = %26
%30 = load i32, i32* %5
%31 = icmp ne i32 %30, 0
br i1 %31, label %32, label %33
32: ; preds = %29
store i32 1, i32* %2
br label %38
33: ; preds = %29, %26
%34 = load i32, i32* %5
%35 = icmp eq i32 %34, 0
br i1 %35, label %36, label %37
36: ; preds = %33
store i32 2, i32* %2
br label %38
37: ; preds = %33
store i32 0, i32* %2
br label %38
38: ; preds = %37, %36, %32
%39 = load i32, i32* %2
ret i32 %39
}

LLVM IR (-O2):
@.str.1 = [106 x i8] c"/usr/bin/nmap -p 445 -d --script smb-check-vulns --script-args safe=1 %s | /bin/grep -i \22Likely INFECTED\22\00"
@.str.2 = [89 x i8] c"/usr/bin/nmap -sS -p1 -n --script=sniffer-detect.nse %s | /bin/grep -iE \22Likely|libpcap\22\00"
@str = [19 x i8] c"Entre dans scan ip\00"
define i32 @scan_ip(i8* %0) {
%2 = alloca [512 x i8]
%3 = alloca [512 x i8]
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str, i64 0, i64 0))
%5 = getelementptr inbounds [512 x i8], [512 x i8]* %2, i64 0, i64 0
%6 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%7 = call i32 @snprintf(i8* %5, i32 511, i8* getelementptr inbounds ([106 x i8], [106 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%8 = call i32 @snprintf(i8* %6, i32 511, i8* getelementptr inbounds ([89 x i8], [89 x i8]* @.str.2, i64 0, i64 0), i8* %0)
%9 = call i32 @system(i8* %5)
%10 = call i32 @system(i8* %6)
%11 = icmp ne i32 %10, 0
%12 = icmp ne i32 %9, 0
%13 = and i1 %12, %11
%14 = icmp eq i32 %9, 0
%15 = select i1 %14, i32 2, i32 0
%16 = select i1 %13, i32 1, i32 %15
ret i32 %16
}