#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_freeze_nowait(char const *, int);
int cg_prepare_for_wait(char const *);
int cg_wait_for(int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ stderr;
int cg_freeze_wait(const char *cgroup, bool freeze) {
  int fd, ret = -1;
  fd = cg_prepare_for_wait(cgroup);
  if (fd < 0)
    return fd;
  ret = cg_freeze_nowait(cgroup, freeze);
  if (ret) {
    fprintf(stderr, "Error: cg_freeze_nowait() failed\n");
    goto out;
  }
  ret = cg_wait_for(fd);
  if (ret)
    goto out;
  ret = cg_check_frozen(cgroup, freeze);
out:
  close(fd);
  return ret;
}


x86 assembly (clang, -O0):
<cg_freeze_wait>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
movl   $0xffffffff,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
call   1070 <cg_prepare_for_wait@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    1197 <cg_freeze_wait+0x37>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1201 <cg_freeze_wait+0xa1>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1060 <cg_freeze_nowait@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     11ca <cg_freeze_wait+0x6a>
mov    0x2e29(%rip),%rax
mov    (%rax),%edi
lea    0xe40(%rip),%rsi
call   1050 <fprintf@plt>
jmp    11f3 <cg_freeze_wait+0x93>
mov    -0x18(%rbp),%edi
call   1030 <cg_wait_for@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     11e4 <cg_freeze_wait+0x84>
jmp    11f3 <cg_freeze_wait+0x93>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1080 <cg_check_frozen@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%edi
call   1040 <close@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cg_freeze_wait>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%r14d
mov    %rdi,%rbp
call   1070 <cg_prepare_for_wait@plt>
mov    %eax,%ebx
test   %eax,%eax
js     11c7 <cg_freeze_wait+0x67>
mov    %rbp,%rdi
mov    %r14d,%esi
call   1060 <cg_freeze_nowait@plt>
test   %eax,%eax
je     11a1 <cg_freeze_wait+0x41>
mov    %eax,%r15d
mov    0x2e4f(%rip),%rax
mov    (%rax),%edi
lea    0xe66(%rip),%rsi
call   1050 <fprintf@plt>
jmp    11bd <cg_freeze_wait+0x5d>
mov    %ebx,%edi
call   1030 <cg_wait_for@plt>
mov    %eax,%r15d
test   %eax,%eax
jne    11bd <cg_freeze_wait+0x5d>
mov    %rbp,%rdi
mov    %r14d,%esi
call   1080 <cg_check_frozen@plt>
mov    %eax,%r15d
mov    %ebx,%edi
call   1040 <close@plt>
mov    %r15d,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [34 x i8] c"Error: cg_freeze_nowait() failed\0A\00"
define i32 @cg_freeze_wait(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32 -1, i32* %7
%8 = load i8*, i8** %4
%9 = call i32 @cg_prepare_for_wait(i8* %8)
store i32 %9, i32* %6
%10 = load i32, i32* %6
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %2
%13 = load i32, i32* %6
store i32 %13, i32* %3
br label %37
14: ; preds = %2
%15 = load i8*, i8** %4
%16 = load i32, i32* %5
%17 = call i32 @cg_freeze_nowait(i8* %15, i32 %16)
store i32 %17, i32* %7
%18 = load i32, i32* %7
%19 = icmp ne i32 %18, 0
br i1 %19, label %20, label %23
20: ; preds = %14
%21 = load i32, i32* @stderr
%22 = call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
br label %33
23: ; preds = %14
%24 = load i32, i32* %6
%25 = call i32 @cg_wait_for(i32 %24)
store i32 %25, i32* %7
%26 = load i32, i32* %7
%27 = icmp ne i32 %26, 0
br i1 %27, label %28, label %29
28: ; preds = %23
br label %33
29: ; preds = %23
%30 = load i8*, i8** %4
%31 = load i32, i32* %5
%32 = call i32 @cg_check_frozen(i8* %30, i32 %31)
store i32 %32, i32* %7
br label %33
33: ; preds = %29, %28, %20
%34 = load i32, i32* %6
%35 = call i32 @close(i32 %34)
%36 = load i32, i32* %7
store i32 %36, i32* %3
br label %37
37: ; preds = %33, %12
%38 = load i32, i32* %3
ret i32 %38
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [34 x i8] c"Error: cg_freeze_nowait() failed\0A\00"
define i32 @cg_freeze_wait(i8* %0, i32 %1) {
%3 = tail call i32 @cg_prepare_for_wait(i8* %0)
%4 = icmp slt i32 %3, 0
br i1 %4, label %19, label %5
5: ; preds = %2
%6 = tail call i32 @cg_freeze_nowait(i8* %0, i32 %1)
%7 = icmp eq i32 %6, 0
br i1 %7, label %11, label %8
8: ; preds = %5
%9 = load i32, i32* @stderr
%10 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
br label %16
11: ; preds = %5
%12 = tail call i32 @cg_wait_for(i32 %3)
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %11
%15 = tail call i32 @cg_check_frozen(i8* %0, i32 %1)
br label %16
16: ; preds = %11, %14, %8
%17 = phi i32 [ %6, %8 ], [ %12, %11 ], [ %15, %14 ]
%18 = tail call i32 @close(i32 %3)
br label %19
19: ; preds = %2, %16
%20 = phi i32 [ %17, %16 ], [ %3, %2 ]
ret i32 %20
}