#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*/ DIR;

/* Variables and functions */
int /*<<< orphan*/ __system(char *);
int /*<<< orphan*/ *opendir(char const *);
int /*<<< orphan*/ sleep(int);
int main() {
  static int count = 0;
  DIR *d;
  static const char check_dir[] = "/data/local/tmp";
  while (count != 120) {
    count += 1;
    sleep(1);
    d = opendir(check_dir);
    if (d != 0)
      __system(
          "/system/bin/logcat -r 1000 -v long -f /data/local/tmp/logcat.log");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
cmpl   $0x78,0x2ef6(%rip)
je     1191 <main+0x61>
mov    0x2eea(%rip),%eax
add    $0x1,%eax
mov    %eax,0x2ee1(%rip)
mov    $0x1,%edi
call   1050 <sleep@plt>
lea    0xe94(%rip),%rdi
call   1030 <opendir@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     118c <main+0x5c>
lea    0xe89(%rip),%rdi
call   1040 <__system@plt>
jmp    113f <main+0xf>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    0x2f02(%rip),%eax
cmp    $0x78,%eax
jne    1149 <main+0x19>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xeb0(%rip),%rbx
lea    0xeb9(%rip),%r14
jmp    116b <main+0x3b>
nopl   0x0(%rax)
mov    0x2ed6(%rip),%eax
cmp    $0x78,%eax
je     113f <main+0xf>
add    $0x1,%eax
mov    %eax,0x2ec8(%rip)
mov    $0x1,%edi
call   1050 <sleep@plt>
mov    %rbx,%rdi
call   1030 <opendir@plt>
test   %rax,%rax
je     1160 <main+0x30>
mov    %r14,%rdi
call   1040 <__system@plt>
jmp    1160 <main+0x30>

LLVM IR (-O0):
@main.count = internal global i32 0
@main.check_dir = internal constant [16 x i8] c"/data/local/tmp\00"
@.str = [65 x i8] c"/system/bin/logcat -r 1000 -v long -f /data/local/tmp/logcat.log\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
store i32 0, i32* %1
br label %3
3: ; preds = %15, %0
%4 = load i32, i32* @main.count
%5 = icmp ne i32 %4, 120
br i1 %5, label %6, label %16
6: ; preds = %3
%7 = load i32, i32* @main.count
%8 = add nsw i32 %7, 1
store i32 %8, i32* @main.count
%9 = call i32 @sleep(i32 1)
%10 = call i32* @opendir(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @main.check_dir, i64 0, i64 0))
store i32* %10, i32** %2
%11 = load i32*, i32** %2
%12 = icmp ne i32* %11, null
br i1 %12, label %13, label %15
13: ; preds = %6
%14 = call i32 @__system(i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str, i64 0, i64 0))
br label %15
15: ; preds = %13, %6
br label %3
16: ; preds = %3
ret i32 0
}

LLVM IR (-O2):
@main.count = internal unnamed_addr global i32 0
@main.check_dir = internal constant [16 x i8] c"/data/local/tmp\00"
@.str = [65 x i8] c"/system/bin/logcat -r 1000 -v long -f /data/local/tmp/logcat.log\00"
define i32 @main() {
%1 = load i32, i32* @main.count
%2 = icmp eq i32 %1, 120
br i1 %2, label %14, label %3
3: ; preds = %0, %11
%4 = phi i32 [ %12, %11 ], [ %1, %0 ]
%5 = add nsw i32 %4, 1
store i32 %5, i32* @main.count
%6 = tail call i32 @sleep(i32 1)
%7 = tail call i32* @opendir(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @main.check_dir, i64 0, i64 0))
%8 = icmp eq i32* %7, null
br i1 %8, label %11, label %9
9: ; preds = %3
%10 = tail call i32 @__system(i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str, i64 0, i64 0))
br label %11
11: ; preds = %9, %3
%12 = load i32, i32* @main.count
%13 = icmp eq i32 %12, 120
br i1 %13, label %14, label %3
14: ; preds = %11, %0
ret i32 0
}