#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 cg_check_frozen(char const *, int);
int cg_enter(char const *, int);
int cg_prepare_for_wait(char const *);
int cg_wait_for(int);
int /*<<< orphan*/ close(int);
int cg_enter_and_wait_for_frozen(const char *cgroup, int pid, bool frozen) {
  int fd, ret = -1;
  int attempts;
  fd = cg_prepare_for_wait(cgroup);
  if (fd < 0)
    return fd;
  ret = cg_enter(cgroup, pid);
  if (ret)
    goto out;
  for (attempts = 0; attempts < 10; attempts++) {
    ret = cg_wait_for(fd);
    if (ret)
      break;
    ret = cg_check_frozen(cgroup, frozen);
    if (ret)
      continue;
  }
out:
  close(fd);
  return ret;
}


x86 assembly (clang, -O0):
<cg_enter_and_wait_for_frozen>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
movl   $0xffffffff,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <cg_prepare_for_wait@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    118a <cg_enter_and_wait_for_frozen+0x3a>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1217 <cg_enter_and_wait_for_frozen+0xc7>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1050 <cg_enter@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
je     11a8 <cg_enter_and_wait_for_frozen+0x58>
jmp    1209 <cg_enter_and_wait_for_frozen+0xb9>
movl   $0x0,-0x24(%rbp)
cmpl   $0xa,-0x24(%rbp)
jge    1204 <cg_enter_and_wait_for_frozen+0xb4>
mov    -0x1c(%rbp),%edi
call   1030 <cg_wait_for@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
je     11d3 <cg_enter_and_wait_for_frozen+0x83>
jmp    1204 <cg_enter_and_wait_for_frozen+0xb4>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%esi
call   1070 <cg_check_frozen@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
je     11f1 <cg_enter_and_wait_for_frozen+0xa1>
jmp    11f6 <cg_enter_and_wait_for_frozen+0xa6>
jmp    11f6 <cg_enter_and_wait_for_frozen+0xa6>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11af <cg_enter_and_wait_for_frozen+0x5f>
jmp    1209 <cg_enter_and_wait_for_frozen+0xb9>
mov    -0x1c(%rbp),%edi
call   1040 <close@plt>
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cg_enter_and_wait_for_frozen>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%r14d
mov    %esi,%ebx
mov    %rdi,%r15
call   1060 <cg_prepare_for_wait@plt>
mov    %eax,%ebp
test   %eax,%eax
js     1291 <cg_enter_and_wait_for_frozen+0x141>
mov    %r15,%rdi
mov    %ebx,%esi
call   1050 <cg_enter@plt>
mov    %eax,%ebx
test   %eax,%eax
jne    1288 <cg_enter_and_wait_for_frozen+0x138>
mov    %ebp,%edi
call   1030 <cg_wait_for@plt>
mov    %eax,%ebx
test   %eax,%eax
jne    1288 <cg_enter_and_wait_for_frozen+0x138>
mov    %r15,%rdi
mov    %r14d,%esi
call   1070 <cg_check_frozen@plt>
mov    %ebp,%edi
call   1030 <cg_wait_for@plt>
mov    %eax,%ebx
test   %eax,%eax
jne    1288 <cg_enter_and_wait_for_frozen+0x138>
mov    %r15,%rdi
mov    %r14d,%esi
call   1070 <cg_check_frozen@plt>
mov    %ebp,%edi
call   1030 <cg_wait_for@plt>
mov    %eax,%ebx
test   %eax,%eax
jne    1288 <cg_enter_and_wait_for_frozen+0x138>
mov    %r15,%rdi
mov    %r14d,%esi
call   1070 <cg_check_frozen@plt>
mov    %ebp,%edi
call   1030 <cg_wait_for@plt>
mov    %eax,%ebx
test   %eax,%eax
jne    1288 <cg_enter_and_wait_for_frozen+0x138>
mov    %r15,%rdi
mov    %r14d,%esi
call   1070 <cg_check_frozen@plt>
mov    %ebp,%edi
call   1030 <cg_wait_for@plt>
mov    %eax,%ebx
test   %eax,%eax
jne    1288 <cg_enter_and_wait_for_frozen+0x138>
mov    %r15,%rdi
mov    %r14d,%esi
call   1070 <cg_check_frozen@plt>
mov    %ebp,%edi
call   1030 <cg_wait_for@plt>
mov    %eax,%ebx
test   %eax,%eax
jne    1288 <cg_enter_and_wait_for_frozen+0x138>
mov    %r15,%rdi
mov    %r14d,%esi
call   1070 <cg_check_frozen@plt>
mov    %ebp,%edi
call   1030 <cg_wait_for@plt>
mov    %eax,%ebx
test   %eax,%eax
jne    1288 <cg_enter_and_wait_for_frozen+0x138>
mov    %r15,%rdi
mov    %r14d,%esi
call   1070 <cg_check_frozen@plt>
mov    %ebp,%edi
call   1030 <cg_wait_for@plt>
mov    %eax,%ebx
test   %eax,%eax
jne    1288 <cg_enter_and_wait_for_frozen+0x138>
mov    %r15,%rdi
mov    %r14d,%esi
call   1070 <cg_check_frozen@plt>
mov    %ebp,%edi
call   1030 <cg_wait_for@plt>
mov    %eax,%ebx
test   %eax,%eax
jne    1288 <cg_enter_and_wait_for_frozen+0x138>
mov    %r15,%rdi
mov    %r14d,%esi
call   1070 <cg_check_frozen@plt>
mov    %ebp,%edi
call   1030 <cg_wait_for@plt>
mov    %eax,%ebx
test   %eax,%eax
jne    1288 <cg_enter_and_wait_for_frozen+0x138>
mov    %r15,%rdi
mov    %r14d,%esi
call   1070 <cg_check_frozen@plt>
mov    %eax,%ebx
mov    %ebp,%edi
call   1040 <close@plt>
mov    %ebx,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @cg_enter_and_wait_for_frozen(i8* %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i8* %0, i8** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i32 -1, i32* %9
%11 = load i8*, i8** %5
%12 = call i32 @cg_prepare_for_wait(i8* %11)
store i32 %12, i32* %8
%13 = load i32, i32* %8
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %3
%16 = load i32, i32* %8
store i32 %16, i32* %4
br label %50
17: ; preds = %3
%18 = load i8*, i8** %5
%19 = load i32, i32* %6
%20 = call i32 @cg_enter(i8* %18, i32 %19)
store i32 %20, i32* %9
%21 = load i32, i32* %9
%22 = icmp ne i32 %21, 0
br i1 %22, label %23, label %24
23: ; preds = %17
br label %46
24: ; preds = %17
store i32 0, i32* %10
br label %25
25: ; preds = %42, %24
%26 = load i32, i32* %10
%27 = icmp slt i32 %26, 10
br i1 %27, label %28, label %45
28: ; preds = %25
%29 = load i32, i32* %8
%30 = call i32 @cg_wait_for(i32 %29)
store i32 %30, i32* %9
%31 = load i32, i32* %9
%32 = icmp ne i32 %31, 0
br i1 %32, label %33, label %34
33: ; preds = %28
br label %45
34: ; preds = %28
%35 = load i8*, i8** %5
%36 = load i32, i32* %7
%37 = call i32 @cg_check_frozen(i8* %35, i32 %36)
store i32 %37, i32* %9
%38 = load i32, i32* %9
%39 = icmp ne i32 %38, 0
br i1 %39, label %40, label %41
40: ; preds = %34
br label %42
41: ; preds = %34
br label %42
42: ; preds = %41, %40
%43 = load i32, i32* %10
%44 = add nsw i32 %43, 1
store i32 %44, i32* %10
br label %25
45: ; preds = %33, %25
br label %46
46: ; preds = %45, %23
%47 = load i32, i32* %8
%48 = call i32 @close(i32 %47)
%49 = load i32, i32* %9
store i32 %49, i32* %4
br label %50
50: ; preds = %46, %15
%51 = load i32, i32* %4
ret i32 %51
}

LLVM IR (-O2):
define i32 @cg_enter_and_wait_for_frozen(i8* %0, i32 %1, i32 %2) {
%4 = tail call i32 @cg_prepare_for_wait(i8* %0)
%5 = icmp slt i32 %4, 0
br i1 %5, label %53, label %6
6: ; preds = %3
%7 = tail call i32 @cg_enter(i8* %0, i32 %1)
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %50
9: ; preds = %6
%10 = tail call i32 @cg_wait_for(i32 %4)
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %50
12: ; preds = %9
%13 = tail call i32 @cg_check_frozen(i8* %0, i32 %2)
%14 = tail call i32 @cg_wait_for(i32 %4)
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %50
16: ; preds = %12
%17 = tail call i32 @cg_check_frozen(i8* %0, i32 %2)
%18 = tail call i32 @cg_wait_for(i32 %4)
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %50
20: ; preds = %16
%21 = tail call i32 @cg_check_frozen(i8* %0, i32 %2)
%22 = tail call i32 @cg_wait_for(i32 %4)
%23 = icmp eq i32 %22, 0
br i1 %23, label %24, label %50
24: ; preds = %20
%25 = tail call i32 @cg_check_frozen(i8* %0, i32 %2)
%26 = tail call i32 @cg_wait_for(i32 %4)
%27 = icmp eq i32 %26, 0
br i1 %27, label %28, label %50
28: ; preds = %24
%29 = tail call i32 @cg_check_frozen(i8* %0, i32 %2)
%30 = tail call i32 @cg_wait_for(i32 %4)
%31 = icmp eq i32 %30, 0
br i1 %31, label %32, label %50
32: ; preds = %28
%33 = tail call i32 @cg_check_frozen(i8* %0, i32 %2)
%34 = tail call i32 @cg_wait_for(i32 %4)
%35 = icmp eq i32 %34, 0
br i1 %35, label %36, label %50
36: ; preds = %32
%37 = tail call i32 @cg_check_frozen(i8* %0, i32 %2)
%38 = tail call i32 @cg_wait_for(i32 %4)
%39 = icmp eq i32 %38, 0
br i1 %39, label %40, label %50
40: ; preds = %36
%41 = tail call i32 @cg_check_frozen(i8* %0, i32 %2)
%42 = tail call i32 @cg_wait_for(i32 %4)
%43 = icmp eq i32 %42, 0
br i1 %43, label %44, label %50
44: ; preds = %40
%45 = tail call i32 @cg_check_frozen(i8* %0, i32 %2)
%46 = tail call i32 @cg_wait_for(i32 %4)
%47 = icmp eq i32 %46, 0
br i1 %47, label %48, label %50
48: ; preds = %44
%49 = tail call i32 @cg_check_frozen(i8* %0, i32 %2)
br label %50
50: ; preds = %9, %12, %16, %20, %24, %28, %32, %36, %40, %44, %48, %6
%51 = phi i32 [ %7, %6 ], [ %10, %9 ], [ %14, %12 ], [ %18, %16 ], [ %22, %20 ], [ %26, %24 ], [ %30, %28 ], [ %34, %32 ], [ %38, %36 ], [ %42, %40 ], [ %46, %44 ], [ %49, %48 ]
%52 = tail call i32 @close(i32 %4)
br label %53
53: ; preds = %3, %50
%54 = phi i32 [ %51, %50 ], [ %4, %3 ]
ret i32 %54
}