#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 pid_t;

/* Variables and functions */
int /*<<< orphan*/ SYS_gettid;
int /*<<< orphan*/ do_one_loop(int, int *);
int getpid();
int /*<<< orphan*/ printf(char *, int, int, ...);
scalar_t__ syscall(int /*<<< orphan*/);
void __do_all_loops(int quiet, int *i, int numloops) {
  pid_t pid, tid;
  int n;
  pid = getpid();
  tid = (pid_t)syscall(SYS_gettid);
  if (!quiet)
    printf("-- Enter bi (%d-%d) --\n", pid, tid);
  n = 0;
  for (; numloops < 0 || *i < numloops; (*i)++) {
    do_one_loop(*i, &n);
    if (!quiet)
      printf("(%d-%d) %d\n", pid, tid, *i);
  }
  if (!quiet)
    printf("-- End of bi (%d-%d) with %d loops --\n", pid, tid, *i);
}


x86 assembly (clang, -O0):
<__do_all_loops>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,-0x18(%rbp)
mov    0x2e85(%rip),%rax
mov    (%rax),%edi
call   1060 <syscall@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x4(%rbp)
jne    118b <__do_all_loops+0x4b>
mov    -0x18(%rbp),%esi
mov    -0x1c(%rbp),%edx
lea    0xe7c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x20(%rbp)
mov    $0x1,%al
cmpl   $0x0,-0x14(%rbp)
mov    %al,-0x21(%rbp)
jl     11b0 <__do_all_loops+0x70>
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
cmp    -0x14(%rbp),%eax
setl   %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    11c0 <__do_all_loops+0x80>
jmp    1208 <__do_all_loops+0xc8>
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
lea    -0x20(%rbp),%rsi
call   1050 <do_one_loop@plt>
cmpl   $0x0,-0x4(%rbp)
jne    11f3 <__do_all_loops+0xb3>
mov    -0x18(%rbp),%esi
mov    -0x1c(%rbp),%edx
mov    -0x10(%rbp),%rax
mov    (%rax),%ecx
lea    0xe2c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11f8 <__do_all_loops+0xb8>
mov    -0x10(%rbp),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    %ecx,(%rax)
jmp    1192 <__do_all_loops+0x52>
cmpl   $0x0,-0x4(%rbp)
jne    122c <__do_all_loops+0xec>
mov    -0x18(%rbp),%esi
mov    -0x1c(%rbp),%edx
mov    -0x10(%rbp),%rax
mov    (%rax),%ecx
lea    0xdff(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<__do_all_loops>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%ebx
mov    %rsi,%rbp
mov    %edi,%r15d
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %eax,%r14d
mov    0x2e84(%rip),%rax
mov    (%rax),%edi
call   1060 <syscall@plt>
mov    %rax,%r12
test   %r15d,%r15d
jne    1187 <__do_all_loops+0x47>
lea    0xe86(%rip),%rdi
mov    %r14d,%esi
mov    %r12d,%edx
xor    %eax,%eax
call   1040 <printf@plt>
movl   $0x0,0x4(%rsp)
mov    0x0(%rbp),%ecx
test   %ebx,%ebx
js     119a <__do_all_loops+0x5a>
cmp    %ebx,%ecx
jge    11d7 <__do_all_loops+0x97>
lea    0x4(%rsp),%r13
nop
mov    %ecx,%edi
mov    %r13,%rsi
call   1050 <do_one_loop@plt>
test   %r15d,%r15d
jne    11c6 <__do_all_loops+0x86>
mov    0x0(%rbp),%ecx
lea    0xe5f(%rip),%rdi
mov    %r14d,%esi
mov    %r12d,%edx
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x0(%rbp),%ecx
add    $0x1,%ecx
mov    %ecx,0x0(%rbp)
test   %ebx,%ebx
js     11a0 <__do_all_loops+0x60>
cmp    %ebx,%ecx
jl     11a0 <__do_all_loops+0x60>
test   %r15d,%r15d
jne    11f0 <__do_all_loops+0xb0>
lea    0xe41(%rip),%rdi
mov    %r14d,%esi
mov    %r12d,%edx
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@SYS_gettid = global i32 0
@.str = [24 x i8] c"-- Enter bi (%d-%d) --\0A\00"
@.str.1 = [12 x i8] c"(%d-%d) %d\0A\00"
@.str.2 = [39 x i8] c"-- End of bi (%d-%d) with %d loops --\0A\00"
define void @__do_all_loops(i32 %0, i32* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 %0, i32* %4
store i32* %1, i32** %5
store i32 %2, i32* %6
%10 = call i32 (...) @getpid()
store i32 %10, i32* %7
%11 = load i32, i32* @SYS_gettid
%12 = call i64 @syscall(i32 %11)
%13 = trunc i64 %12 to i32
store i32 %13, i32* %8
%14 = load i32, i32* %4
%15 = icmp ne i32 %14, 0
br i1 %15, label %20, label %16
16: ; preds = %3
%17 = load i32, i32* %7
%18 = load i32, i32* %8
%19 = call i32 (i8*, i32, i32, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i32 %17, i32 %18)
br label %20
20: ; preds = %16, %3
store i32 0, i32* %9
br label %21
21: ; preds = %44, %20
%22 = load i32, i32* %6
%23 = icmp slt i32 %22, 0
br i1 %23, label %29, label %24
24: ; preds = %21
%25 = load i32*, i32** %5
%26 = load i32, i32* %25
%27 = load i32, i32* %6
%28 = icmp slt i32 %26, %27
br label %29
29: ; preds = %24, %21
%30 = phi i1 [ true, %21 ], [ %28, %24 ]
br i1 %30, label %31, label %48
31: ; preds = %29
%32 = load i32*, i32** %5
%33 = load i32, i32* %32
%34 = call i32 @do_one_loop(i32 %33, i32* %9)
%35 = load i32, i32* %4
%36 = icmp ne i32 %35, 0
br i1 %36, label %43, label %37
37: ; preds = %31
%38 = load i32, i32* %7
%39 = load i32, i32* %8
%40 = load i32*, i32** %5
%41 = load i32, i32* %40
%42 = call i32 (i8*, i32, i32, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %38, i32 %39, i32 %41)
br label %43
43: ; preds = %37, %31
br label %44
44: ; preds = %43
%45 = load i32*, i32** %5
%46 = load i32, i32* %45
%47 = add nsw i32 %46, 1
store i32 %47, i32* %45
br label %21
48: ; preds = %29
%49 = load i32, i32* %4
%50 = icmp ne i32 %49, 0
br i1 %50, label %57, label %51
51: ; preds = %48
%52 = load i32, i32* %7
%53 = load i32, i32* %8
%54 = load i32*, i32** %5
%55 = load i32, i32* %54
%56 = call i32 (i8*, i32, i32, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.2, i64 0, i64 0), i32 %52, i32 %53, i32 %55)
br label %57
57: ; preds = %51, %48
ret void
}

LLVM IR (-O2):
@SYS_gettid = global i32 0
@.str = [24 x i8] c"-- Enter bi (%d-%d) --\0A\00"
@.str.1 = [12 x i8] c"(%d-%d) %d\0A\00"
@.str.2 = [39 x i8] c"-- End of bi (%d-%d) with %d loops --\0A\00"
define void @__do_all_loops(i32 %0, i32* nocapture %1, i32 %2) {
%4 = alloca i32
%5 = bitcast i32* %4 to i8*
%6 = tail call i32 (...) @getpid()
%7 = load i32, i32* @SYS_gettid
%8 = tail call i64 @syscall(i32 %7)
%9 = trunc i64 %8 to i32
%10 = icmp eq i32 %0, 0
br i1 %10, label %11, label %13
11: ; preds = %3
%12 = tail call i32 (i8*, i32, i32, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i32 %6, i32 %9)
br label %13
13: ; preds = %11, %3
store i32 0, i32* %4
%14 = icmp slt i32 %2, 0
%15 = load i32, i32* %1
%16 = icmp slt i32 %15, %2
%17 = select i1 %14, i1 true, i1 %16
br i1 %17, label %18, label %29
18: ; preds = %13, %24
%19 = phi i32 [ %26, %24 ], [ %15, %13 ]
%20 = call i32 @do_one_loop(i32 %19, i32* %4)
br i1 %10, label %21, label %24
21: ; preds = %18
%22 = load i32, i32* %1
%23 = call i32 (i8*, i32, i32, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %6, i32 %9, i32 %22)
br label %24
24: ; preds = %18, %21
%25 = load i32, i32* %1
%26 = add nsw i32 %25, 1
store i32 %26, i32* %1
%27 = icmp slt i32 %26, %2
%28 = select i1 %14, i1 true, i1 %27
br i1 %28, label %18, label %29
29: ; preds = %24, %13
%30 = phi i32 [ %15, %13 ], [ %26, %24 ]
br i1 %10, label %31, label %33
31: ; preds = %29
%32 = call i32 (i8*, i32, i32, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.2, i64 0, i64 0), i32 %6, i32 %9, i32 %30)
br label %33
33: ; preds = %31, %29
ret void
}