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

/* Variables and functions */
int only_one_process();
int /*<<< orphan*/ set_process_name(char *);
int /*<<< orphan*/ sleep(int);
int waitpid(int, int *, int /*<<< orphan*/);
int loop(char *user) {
  int wstat;
  int sleep_cnt = 0;
  int last_proccess = 0;
  int pid_wait;
  set_process_name(user);
  while ((pid_wait = waitpid(-1, &wstat, 0)) > 0 || last_proccess == 0) {
    if (pid_wait > 0) {
      continue;
    }
    sleep_cnt++;
    sleep(1);
    if (sleep_cnt % 30 == 0) {
      sleep_cnt = 0;
      last_proccess = only_one_process();
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<loop>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <set_process_name@plt>
mov    $0xffffffff,%edi
lea    -0xc(%rbp),%rsi
xor    %edx,%edx
call   1050 <waitpid@plt>
mov    %eax,%ecx
mov    %ecx,-0x18(%rbp)
mov    $0x1,%al
cmp    $0x0,%ecx
mov    %al,-0x19(%rbp)
jg     1190 <loop+0x50>
cmpl   $0x0,-0x14(%rbp)
sete   %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    11a0 <loop+0x60>
jmp    11ec <loop+0xac>
cmpl   $0x0,-0x18(%rbp)
jle    11af <loop+0x6f>
jmp    1163 <loop+0x23>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    $0x1,%edi
call   1060 <sleep@plt>
mov    -0x10(%rbp),%eax
mov    $0x1e,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    11e7 <loop+0xa7>
movl   $0x0,-0x10(%rbp)
mov    $0x0,%al
call   1040 <only_one_process@plt>
mov    %eax,-0x14(%rbp)
jmp    1163 <loop+0x23>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<loop>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
call   1030 <set_process_name@plt>
lea    0xc(%rsp),%rbx
xor    %ebp,%ebp
xor    %r14d,%r14d
jmp    1164 <loop+0x24>
nopl   0x0(%rax)
test   %eax,%eax
jle    117d <loop+0x3d>
mov    $0xffffffff,%edi
mov    %rbx,%rsi
xor    %edx,%edx
call   1050 <waitpid@plt>
test   %eax,%eax
jg     1160 <loop+0x20>
test   %ebp,%ebp
je     1160 <loop+0x20>
jmp    11a6 <loop+0x66>
add    $0x1,%r14d
mov    $0x1,%edi
call   1060 <sleep@plt>
imul   $0xeeeeeeef,%r14d,%eax
ror    %eax
cmp    $0x8888888,%eax
ja     1164 <loop+0x24>
xor    %eax,%eax
call   1040 <only_one_process@plt>
mov    %eax,%ebp
jmp    1154 <loop+0x14>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @loop(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %2
store i32 0, i32* %4
store i32 0, i32* %5
%7 = load i8*, i8** %2
%8 = call i32 @set_process_name(i8* %7)
br label %9
9: ; preds = %30, %20, %1
%10 = call i32 @waitpid(i32 -1, i32* %3, i32 0)
store i32 %10, i32* %6
%11 = icmp sgt i32 %10, 0
br i1 %11, label %15, label %12
12: ; preds = %9
%13 = load i32, i32* %5
%14 = icmp eq i32 %13, 0
br label %15
15: ; preds = %12, %9
%16 = phi i1 [ true, %9 ], [ %14, %12 ]
br i1 %16, label %17, label %31
17: ; preds = %15
%18 = load i32, i32* %6
%19 = icmp sgt i32 %18, 0
br i1 %19, label %20, label %21
20: ; preds = %17
br label %9
21: ; preds = %17
%22 = load i32, i32* %4
%23 = add nsw i32 %22, 1
store i32 %23, i32* %4
%24 = call i32 @sleep(i32 1)
%25 = load i32, i32* %4
%26 = srem i32 %25, 30
%27 = icmp eq i32 %26, 0
br i1 %27, label %28, label %30
28: ; preds = %21
store i32 0, i32* %4
%29 = call i32 (...) @only_one_process()
store i32 %29, i32* %5
br label %30
30: ; preds = %28, %21
br label %9
31: ; preds = %15
ret i32 0
}

LLVM IR (-O2):
define i32 @loop(i8* %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
%4 = tail call i32 @set_process_name(i8* %0)
br label %5
5: ; preds = %20, %1
%6 = phi i32 [ %21, %20 ], [ 0, %1 ]
%7 = icmp eq i32 %6, 0
br label %8
8: ; preds = %5, %15
%9 = phi i32 [ %16, %15 ], [ 0, %5 ]
br label %10
10: ; preds = %8, %14
%11 = call i32 @waitpid(i32 -1, i32* %2, i32 0)
%12 = icmp sgt i32 %11, 0
%13 = select i1 %12, i1 true, i1 %7
br i1 %13, label %14, label %22
14: ; preds = %10
br i1 %12, label %10, label %15
15: ; preds = %14
%16 = add nuw nsw i32 %9, 1
%17 = call i32 @sleep(i32 1)
%18 = urem i32 %16, 30
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %8
20: ; preds = %15
%21 = call i32 (...) @only_one_process()
br label %5
22: ; preds = %10
ret i32 0
}