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

/* Variables and functions */
scalar_t__ cg_read(char const *, char *, char *, int);
int /*<<< orphan*/ usleep(int);
int cg_wait_for_proc_count(const char *cgroup, int count) {
  char buf[10 * 4096] = {0};
  int attempts;
  char *ptr;
  for (attempts = 10; attempts >= 0; attempts--) {
    int nr = 0;
    if (cg_read(cgroup, "cgroup.procs", buf, sizeof(buf)))
      break;
    for (ptr = buf; *ptr; ptr++)
      if (*ptr == '\n')
        nr++;
    if (nr >= count)
      return 0;
    usleep(100000);
  }
  return -1;
}


x86 assembly (clang, -O0):
<cg_wait_for_proc_count>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa040,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
lea    -0xa020(%rbp),%rdi
xor    %esi,%esi
mov    $0xa000,%edx
call   1040 <memset@plt>
movl   $0xa,-0xa024(%rbp)
cmpl   $0x0,-0xa024(%rbp)
jl     1236 <cg_wait_for_proc_count+0x106>
movl   $0x0,-0xa034(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0xa020(%rbp),%rdx
lea    0xe78(%rip),%rsi
mov    $0xa000,%ecx
call   1030 <cg_read@plt>
cmp    $0x0,%rax
je     11a1 <cg_wait_for_proc_count+0x71>
jmp    1236 <cg_wait_for_proc_count+0x106>
lea    -0xa020(%rbp),%rax
mov    %rax,-0xa030(%rbp)
mov    -0xa030(%rbp),%rax
cmpb   $0x0,(%rax)
je     11fd <cg_wait_for_proc_count+0xcd>
mov    -0xa030(%rbp),%rax
movsbl (%rax),%eax
cmp    $0xa,%eax
jne    11e1 <cg_wait_for_proc_count+0xb1>
mov    -0xa034(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xa034(%rbp)
jmp    11e6 <cg_wait_for_proc_count+0xb6>
mov    -0xa030(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0xa030(%rbp)
jmp    11af <cg_wait_for_proc_count+0x7f>
mov    -0xa034(%rbp),%eax
cmp    -0x14(%rbp),%eax
jl     1218 <cg_wait_for_proc_count+0xe8>
movl   $0x0,-0x4(%rbp)
jmp    123d <cg_wait_for_proc_count+0x10d>
mov    $0x186a0,%edi
call   1050 <usleep@plt>
mov    -0xa024(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xa024(%rbp)
jmp    115f <cg_wait_for_proc_count+0x2f>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xa040,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cg_wait_for_proc_count>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xa008,%rsp
mov    %esi,%r14d
mov    %rdi,%r12
mov    %rsp,%r13
mov    $0xa000,%edx
mov    %r13,%rdi
xor    %esi,%esi
call   1040 <memset@plt>
mov    $0xa,%ebp
lea    0xe9b(%rip),%r15
mov    $0xffffffff,%ebx
nopw   0x0(%rax,%rax,1)
mov    %r12,%rdi
mov    %r15,%rsi
mov    %r13,%rdx
mov    $0xa000,%ecx
call   1030 <cg_read@plt>
test   %rax,%rax
jne    11bb <cg_wait_for_proc_count+0x8b>
xor    %eax,%eax
mov    %r13,%rcx
jmp    1197 <cg_wait_for_proc_count+0x67>
nop
add    $0x1,%eax
add    $0x1,%rcx
movzbl (%rcx),%edx
cmp    $0xa,%dl
je     1190 <cg_wait_for_proc_count+0x60>
test   %dl,%dl
jne    1193 <cg_wait_for_proc_count+0x63>
cmp    %r14d,%eax
jge    11b9 <cg_wait_for_proc_count+0x89>
mov    $0x186a0,%edi
call   1050 <usleep@plt>
sub    $0x1,%ebp
jae    1170 <cg_wait_for_proc_count+0x40>
jmp    11bb <cg_wait_for_proc_count+0x8b>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0xa008,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [13 x i8] c"cgroup.procs\00"
define i32 @cg_wait_for_proc_count(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca [40960 x i8]
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
%10 = bitcast [40960 x i8]* %6 to i8*
store i32 10, i32* %7
br label %11
11: ; preds = %45, %2
%12 = load i32, i32* %7
%13 = icmp sge i32 %12, 0
br i1 %13, label %14, label %48
14: ; preds = %11
store i32 0, i32* %9
%15 = load i8*, i8** %4
%16 = getelementptr inbounds [40960 x i8], [40960 x i8]* %6, i64 0, i64 0
%17 = call i64 @cg_read(i8* %15, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* %16, i32 40960)
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %20
19: ; preds = %14
br label %48
20: ; preds = %14
%21 = getelementptr inbounds [40960 x i8], [40960 x i8]* %6, i64 0, i64 0
store i8* %21, i8** %8
br label %22
22: ; preds = %35, %20
%23 = load i8*, i8** %8
%24 = load i8, i8* %23
%25 = icmp ne i8 %24, 0
br i1 %25, label %26, label %38
26: ; preds = %22
%27 = load i8*, i8** %8
%28 = load i8, i8* %27
%29 = sext i8 %28 to i32
%30 = icmp eq i32 %29, 10
br i1 %30, label %31, label %34
31: ; preds = %26
%32 = load i32, i32* %9
%33 = add nsw i32 %32, 1
store i32 %33, i32* %9
br label %34
34: ; preds = %31, %26
br label %35
35: ; preds = %34
%36 = load i8*, i8** %8
%37 = getelementptr inbounds i8, i8* %36, i32 1
store i8* %37, i8** %8
br label %22
38: ; preds = %22
%39 = load i32, i32* %9
%40 = load i32, i32* %5
%41 = icmp sge i32 %39, %40
br i1 %41, label %42, label %43
42: ; preds = %38
store i32 0, i32* %3
br label %49
43: ; preds = %38
%44 = call i32 @usleep(i32 100000)
br label %45
45: ; preds = %43
%46 = load i32, i32* %7
%47 = add nsw i32 %46, -1
store i32 %47, i32* %7
br label %11
48: ; preds = %19, %11
store i32 -1, i32* %3
br label %49
49: ; preds = %48, %42
%50 = load i32, i32* %3
ret i32 %50
}

LLVM IR (-O2):
@.str = [13 x i8] c"cgroup.procs\00"
define i32 @cg_wait_for_proc_count(i8* %0, i32 %1) {
%3 = alloca [40960 x i8]
%4 = getelementptr inbounds [40960 x i8], [40960 x i8]* %3, i64 0, i64 0
br label %5
5: ; preds = %2, %20
%6 = phi i32 [ 10, %2 ], [ %22, %20 ]
%7 = call i64 @cg_read(i8* %0, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* %4, i32 40960)
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %24
9: ; preds = %5, %15
%10 = phi i8* [ %17, %15 ], [ %4, %5 ]
%11 = phi i32 [ %16, %15 ], [ 0, %5 ]
%12 = load i8, i8* %10
switch i8 %12, label %15 [
i8 0, label %18
i8 10, label %13
]
13: ; preds = %9
%14 = add nsw i32 %11, 1
br label %15
15: ; preds = %9, %13
%16 = phi i32 [ %14, %13 ], [ %11, %9 ]
%17 = getelementptr inbounds i8, i8* %10, i64 1
br label %9
18: ; preds = %9
%19 = icmp slt i32 %11, %1
br i1 %19, label %20, label %24
20: ; preds = %18
%21 = call i32 @usleep(i32 100000)
%22 = add nsw i32 %6, -1
%23 = icmp eq i32 %6, 0
br i1 %23, label %24, label %5
24: ; preds = %18, %20, %5
%25 = phi i32 [ -1, %5 ], [ -1, %20 ], [ 0, %18 ]
ret i32 %25
}