#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 */
scalar_t__ cg_create(char *);
int /*<<< orphan*/ cg_destroy(char *);
char *cg_name_indexed(char const *, char *, int);
scalar_t__ cg_run(char *, int (*)(char const *, void *), int /*<<< orphan*/ *);
int /*<<< orphan*/ free(char *);
int cg_run_in_subcgroups(const char *parent,
                         int (*fn)(const char *cgroup, void *arg), void *arg,
                         int times) {
  char *child;
  int i;
  for (i = 0; i < times; i++) {
    child = cg_name_indexed(parent, "child", i);
    if (!child)
      return -1;
    if (cg_create(child)) {
      cg_destroy(child);
      free(child);
      return -1;
    }
    if (cg_run(child, fn, NULL)) {
      cg_destroy(child);
      free(child);
      return -1;
    }
    cg_destroy(child);
    free(child);
  }
  return 0;
}


x86 assembly (clang, -O0):
<cg_run_in_subcgroups>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    1232 <cg_run_in_subcgroups+0xe2>
mov    -0x10(%rbp),%rdi
mov    -0x34(%rbp),%edx
lea    0xe78(%rip),%rsi
call   1060 <cg_name_indexed@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    11a8 <cg_run_in_subcgroups+0x58>
movl   $0xffffffff,-0x4(%rbp)
jmp    1239 <cg_run_in_subcgroups+0xe9>
mov    -0x30(%rbp),%rdi
call   1050 <cg_create@plt>
cmp    $0x0,%rax
je     11d9 <cg_run_in_subcgroups+0x89>
mov    -0x30(%rbp),%rdi
call   1030 <cg_destroy@plt>
mov    -0x30(%rbp),%rdi
call   1040 <free@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1239 <cg_run_in_subcgroups+0xe9>
mov    -0x30(%rbp),%rdi
mov    -0x18(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1070 <cg_run@plt>
cmp    $0x0,%rax
je     1212 <cg_run_in_subcgroups+0xc2>
mov    -0x30(%rbp),%rdi
call   1030 <cg_destroy@plt>
mov    -0x30(%rbp),%rdi
call   1040 <free@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1239 <cg_run_in_subcgroups+0xe9>
mov    -0x30(%rbp),%rdi
call   1030 <cg_destroy@plt>
mov    -0x30(%rbp),%rdi
call   1040 <free@plt>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    116e <cg_run_in_subcgroups+0x1e>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cg_run_in_subcgroups>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %ecx,%ecx
jle    11c0 <cg_run_in_subcgroups+0x70>
mov    %ecx,%r13d
mov    %rsi,%r14
mov    %rdi,%r15
xor    %ebx,%ebx
mov    $0xffffffff,%ebp
nop
mov    %r15,%rdi
lea    0xe86(%rip),%rsi
mov    %ebx,%edx
call   1060 <cg_name_indexed@plt>
test   %rax,%rax
je     11d4 <cg_run_in_subcgroups+0x84>
mov    %rax,%r12
mov    %rax,%rdi
call   1050 <cg_create@plt>
test   %rax,%rax
jne    11c4 <cg_run_in_subcgroups+0x74>
mov    %r12,%rdi
mov    %r14,%rsi
xor    %edx,%edx
call   1070 <cg_run@plt>
test   %rax,%rax
jne    11c4 <cg_run_in_subcgroups+0x74>
mov    %r12,%rdi
call   1030 <cg_destroy@plt>
mov    %r12,%rdi
call   1040 <free@plt>
add    $0x1,%ebx
cmp    %ebx,%r13d
jne    1170 <cg_run_in_subcgroups+0x20>
xor    %ebp,%ebp
jmp    11d4 <cg_run_in_subcgroups+0x84>
mov    %r12,%rdi
call   1030 <cg_destroy@plt>
mov    %r12,%rdi
call   1040 <free@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [6 x i8] c"child\00"
define i32 @cg_run_in_subcgroups(i8* %0, i32 (i8*, i8*)* %1, i8* nocapture readnone %2, i32 %3) {
%5 = icmp sgt i32 %3, 0
br i1 %5, label %6, label %24
6: ; preds = %4, %16
%7 = phi i32 [ %19, %16 ], [ 0, %4 ]
%8 = tail call i8* @cg_name_indexed(i8* %0, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %7)
%9 = icmp eq i8* %8, null
br i1 %9, label %24, label %10
10: ; preds = %6
%11 = tail call i64 @cg_create(i8* %8)
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %21
13: ; preds = %10
%14 = tail call i64 @cg_run(i8* %8, i32 (i8*, i8*)* %1, i32* null)
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %21
16: ; preds = %13
%17 = tail call i32 @cg_destroy(i8* %8)
%18 = tail call i32 @free(i8* %8)
%19 = add nuw nsw i32 %7, 1
%20 = icmp eq i32 %19, %3
br i1 %20, label %24, label %6
21: ; preds = %13, %10
%22 = tail call i32 @cg_destroy(i8* %8)
%23 = tail call i32 @free(i8* %8)
br label %24
24: ; preds = %6, %16, %21, %4
%25 = phi i32 [ 0, %4 ], [ -1, %21 ], [ -1, %6 ], [ 0, %16 ]
ret i32 %25
}