#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*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
scalar_t__ malloc(scalar_t__);
int /*<<< orphan*/ *popen(char *, char *);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
scalar_t__ strlen(char *);
long strtol(char *, int /*<<< orphan*/ *, int);
void get_eventlog(char *arg1) {
  0;
  char *call = "powershell.exe ";
  char *pwsh = "$lines = Get-WinEvent -ListLog * ^| measure-object -line; echo "
               "$lines.Lines";
  char *command = (char *)malloc(strlen(pwsh) + strlen(call) + 1);
  long num_eventlog_threshold = strtol(arg1, NULL, 10);
  FILE *fp;
  char buf[128];
  char retval[10];
  strcpy(command, call);
  strcat(command, pwsh);
  if ((fp = popen(command, "r")) == NULL) {
    0;
    exit(0);
  }
  while (fgets(buf, 128, fp) != NULL) {
    strcat(retval, buf);
  }
  long eventlog_count = strtol(retval, NULL, 10);
  0;
  if (eventlog_count > num_eventlog_threshold) {
    0;
  } else {
    exit(0);
  }
}


x86 assembly (clang, -O0):
<get_eventlog>:
push   %rbp
mov    %rsp,%rbp
sub    $0xd0,%rsp
mov    %rdi,-0x8(%rbp)
lea    0xe6a(%rip),%rax
mov    %rax,-0x10(%rbp)
lea    0xe6f(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0xd0(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0xd0(%rbp),%rdi
add    %rax,%rdi
add    $0x1,%rdi
call   1070 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1060 <strtol@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1090 <strcat@plt>
mov    -0x20(%rbp),%rdi
lea    0xe4c(%rip),%rsi
call   1080 <popen@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
jne    122a <get_eventlog+0xaa>
xor    %edi,%edi
call   10a0 <exit@plt>
jmp    122f <get_eventlog+0xaf>
lea    -0xb0(%rbp),%rdi
mov    -0x30(%rbp),%rdx
mov    $0x80,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     1266 <get_eventlog+0xe6>
lea    -0xba(%rbp),%rdi
lea    -0xb0(%rbp),%rsi
call   1090 <strcat@plt>
jmp    122f <get_eventlog+0xaf>
lea    -0xba(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1060 <strtol@plt>
mov    %rax,-0xc8(%rbp)
mov    -0xc8(%rbp),%rax
cmp    -0x28(%rbp),%rax
jle    1298 <get_eventlog+0x118>
jmp    129f <get_eventlog+0x11f>
xor    %edi,%edi
call   10a0 <exit@plt>
add    $0xd0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_eventlog>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x98,%rsp
mov    %rdi,%r14
mov    $0x5b,%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
mov    %r14,%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1050 <strtol@plt>
mov    %rax,%r14
lea    0xe59(%rip),%rsi
mov    %rbx,%rdi
call   1030 <strcpy@plt>
lea    0xe5a(%rip),%rsi
mov    %rbx,%rdi
call   1080 <strcat@plt>
lea    0xe97(%rip),%rsi
mov    %rbx,%rdi
call   1070 <popen@plt>
test   %rax,%rax
je     1245 <get_eventlog+0xd5>
mov    %rax,%r12
lea    0x10(%rsp),%rdi
mov    $0x80,%esi
mov    %rax,%rdx
call   1040 <fgets@plt>
test   %rax,%rax
je     1220 <get_eventlog+0xb0>
lea    0x6(%rsp),%r15
lea    0x10(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    %rbx,%rsi
call   1080 <strcat@plt>
mov    %rbx,%rdi
mov    $0x80,%esi
mov    %r12,%rdx
call   1040 <fgets@plt>
test   %rax,%rax
jne    1200 <get_eventlog+0x90>
lea    0x6(%rsp),%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1050 <strtol@plt>
cmp    %r14,%rax
jle    1245 <get_eventlog+0xd5>
add    $0x98,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
xor    %edi,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [16 x i8] c"powershell.exe \00"
@.str.1 = [76 x i8] c"$lines = Get-WinEvent -ListLog * ^| measure-object -line; echo $lines.Lines\00"
@.str.2 = [2 x i8] c"r\00"
define void @get_eventlog(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i32*
%8 = alloca [128 x i8]
%9 = alloca [10 x i8]
%10 = alloca i64
store i8* %0, i8** %2
store i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8** %3
store i8* getelementptr inbounds ([76 x i8], [76 x i8]* @.str.1, i64 0, i64 0), i8** %4
%11 = load i8*, i8** %4
%12 = call i64 @strlen(i8* %11)
%13 = load i8*, i8** %3
%14 = call i64 @strlen(i8* %13)
%15 = add nsw i64 %12, %14
%16 = add nsw i64 %15, 1
%17 = call i64 @malloc(i64 %16)
%18 = inttoptr i64 %17 to i8*
store i8* %18, i8** %5
%19 = load i8*, i8** %2
%20 = call i64 @strtol(i8* %19, i32* null, i32 10)
store i64 %20, i64* %6
%21 = load i8*, i8** %5
%22 = load i8*, i8** %3
%23 = call i32 @strcpy(i8* %21, i8* %22)
%24 = load i8*, i8** %5
%25 = load i8*, i8** %4
%26 = call i32 @strcat(i8* %24, i8* %25)
%27 = load i8*, i8** %5
%28 = call i32* @popen(i8* %27, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %28, i32** %7
%29 = icmp eq i32* %28, null
br i1 %29, label %30, label %32
30: ; preds = %1
%31 = call i32 @exit(i32 0)
unreachable
32: ; preds = %1
br label %33
33: ; preds = %38, %32
%34 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 0
%35 = load i32*, i32** %7
%36 = call i32* @fgets(i8* %34, i32 128, i32* %35)
%37 = icmp ne i32* %36, null
br i1 %37, label %38, label %42
38: ; preds = %33
%39 = getelementptr inbounds [10 x i8], [10 x i8]* %9, i64 0, i64 0
%40 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 0
%41 = call i32 @strcat(i8* %39, i8* %40)
br label %33
42: ; preds = %33
%43 = getelementptr inbounds [10 x i8], [10 x i8]* %9, i64 0, i64 0
%44 = call i64 @strtol(i8* %43, i32* null, i32 10)
store i64 %44, i64* %10
%45 = load i64, i64* %10
%46 = load i64, i64* %6
%47 = icmp sgt i64 %45, %46
br i1 %47, label %48, label %49
48: ; preds = %42
br label %51
49: ; preds = %42
%50 = call i32 @exit(i32 0)
unreachable
51: ; preds = %48
ret void
}

LLVM IR (-O2):
@.str = [16 x i8] c"powershell.exe \00"
@.str.1 = [76 x i8] c"$lines = Get-WinEvent -ListLog * ^| measure-object -line; echo $lines.Lines\00"
@.str.2 = [2 x i8] c"r\00"
define void @get_eventlog(i8* nocapture %0) {
%2 = alloca [128 x i8]
%3 = alloca [10 x i8]
%4 = tail call i64 @malloc(i64 91)
%5 = inttoptr i64 %4 to i8*
%6 = tail call i64 @strtol(i8* nocapture %0, i32* null, i32 10)
%7 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 0
%8 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%9 = tail call i32 @strcpy(i8* %5, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%10 = tail call i32 @strcat(i8* %5, i8* getelementptr inbounds ([76 x i8], [76 x i8]* @.str.1, i64 0, i64 0))
%11 = tail call i32* @popen(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%12 = icmp eq i32* %11, null
br i1 %12, label %16, label %13
13: ; preds = %1
%14 = call i32* @fgets(i8* %7, i32 128, i32* %11)
%15 = icmp eq i32* %14, null
br i1 %15, label %22, label %18
16: ; preds = %1
%17 = tail call i32 @exit(i32 0)
unreachable
18: ; preds = %13, %18
%19 = call i32 @strcat(i8* %8, i8* %7)
%20 = call i32* @fgets(i8* %7, i32 128, i32* %11)
%21 = icmp eq i32* %20, null
br i1 %21, label %22, label %18
22: ; preds = %18, %13
%23 = call i64 @strtol(i8* nocapture %8, i32* null, i32 10)
%24 = icmp sgt i64 %23, %6
br i1 %24, label %27, label %25
25: ; preds = %22
%26 = call i32 @exit(i32 0)
unreachable
27: ; preds = %22
ret void
}