#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*/ xcb_get_atom_name_cookie_t;
typedef int /*<<< orphan*/ xcb_connection_t;

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, long);
int /*<<< orphan*/ free(int /*<<< orphan*/ *);
int /*<<< orphan*/ *malloc(int);
int say_batch(int /*<<< orphan*/ *, char const *, int /*<<< orphan*/ *, long,
              int);
int /*<<< orphan*/ stderr;
void list_atoms(xcb_connection_t *c, const char *format, int mask, long low,
                long high) {
  xcb_get_atom_name_cookie_t *cookie_jar;
  int done = 0;
  switch (mask) {
  case (1 << 1):
    low = 1;
  case ((1 << 0) | (1 << 1)):
    cookie_jar = malloc((high - low + 1) * sizeof(xcb_get_atom_name_cookie_t));
    if (!cookie_jar) {
      fprintf(stderr, "Out of memory allocating space for %ld atom requests\n",
              high - low);
      return;
    }
    say_batch(c, format, cookie_jar, low, high - low + 1);
    free(cookie_jar);
    break;
  default:
    low = 1;
  case (1 << 0):
    cookie_jar = malloc(100 * sizeof(xcb_get_atom_name_cookie_t));
    if (!cookie_jar) {
      fprintf(stderr, "Out of memory allocating space for %ld atom requests\n",
              (long)100);
      return;
    }
    while (!done) {
      done = say_batch(c, format, cookie_jar, low, 100);
      low += 100;
    }
    free(cookie_jar);
    break;
  }
  return;
}


x86 assembly (clang, -O0):
<list_atoms>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x38(%rbp)
sub    $0x1,%eax
je     1222 <list_atoms+0xe2>
jmp    1176 <list_atoms+0x36>
mov    -0x38(%rbp),%eax
sub    $0x2,%eax
je     1198 <list_atoms+0x58>
jmp    1187 <list_atoms+0x47>
mov    -0x38(%rbp),%eax
sub    $0x3,%eax
je     11a0 <list_atoms+0x60>
jmp    121a <list_atoms+0xda>
movq   $0x1,-0x20(%rbp)
mov    -0x28(%rbp),%rax
sub    -0x20(%rbp),%rax
add    $0x1,%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    11e8 <list_atoms+0xa8>
mov    0x2e13(%rip),%rax
mov    (%rax),%edi
mov    -0x28(%rbp),%rdx
sub    -0x20(%rbp),%rdx
lea    0xe22(%rip),%rsi
call   1040 <fprintf@plt>
jmp    12b2 <list_atoms+0x172>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x30(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    -0x28(%rbp),%rax
sub    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %eax,%r8d
call   1060 <say_batch@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
jmp    12ad <list_atoms+0x16d>
movq   $0x1,-0x20(%rbp)
mov    $0x190,%edi
call   1050 <malloc@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    125a <list_atoms+0x11a>
mov    0x2d9e(%rip),%rax
mov    (%rax),%edi
lea    0xdb5(%rip),%rsi
mov    $0x64,%edx
call   1040 <fprintf@plt>
jmp    12b2 <list_atoms+0x172>
jmp    125f <list_atoms+0x11f>
cmpl   $0x0,-0x34(%rbp)
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1275 <list_atoms+0x135>
jmp    12a4 <list_atoms+0x164>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x30(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    $0x64,%r8d
call   1060 <say_batch@plt>
mov    %eax,-0x34(%rbp)
mov    -0x20(%rbp),%rax
add    $0x64,%rax
mov    %rax,-0x20(%rbp)
jmp    125f <list_atoms+0x11f>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
jmp    12b2 <list_atoms+0x172>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<list_atoms>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rcx,%rbx
mov    %rsi,%r14
mov    %rdi,%r15
cmp    $0x1,%edx
je     119c <list_atoms+0x5c>
mov    %r8,%r12
cmp    $0x3,%edx
je     1169 <list_atoms+0x29>
mov    $0x1,%ebx
cmp    $0x2,%edx
jne    119c <list_atoms+0x5c>
sub    %rbx,%r12
lea    0x4(,%r12,4),%edi
call   1050 <malloc@plt>
test   %rax,%rax
je     11e0 <list_atoms+0xa0>
mov    %rax,%r13
lea    0x1(%r12),%r8d
mov    %r15,%rdi
mov    %r14,%rsi
mov    %rax,%rdx
mov    %rbx,%rcx
call   1060 <say_batch@plt>
mov    %r13,%rdi
jmp    11d2 <list_atoms+0x92>
mov    $0x190,%edi
call   1050 <malloc@plt>
test   %rax,%rax
je     11f5 <list_atoms+0xb5>
mov    %rax,%r12
xchg   %ax,%ax
mov    %r15,%rdi
mov    %r14,%rsi
mov    %r12,%rdx
mov    %rbx,%rcx
mov    $0x64,%r8d
call   1060 <say_batch@plt>
add    $0x64,%rbx
test   %eax,%eax
je     11b0 <list_atoms+0x70>
mov    %r12,%rdi
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
jmp    1030 <free@plt>
mov    0x2df9(%rip),%rax
mov    (%rax),%edi
lea    0xe10(%rip),%rsi
mov    %r12,%rdx
jmp    120a <list_atoms+0xca>
mov    0x2de4(%rip),%rax
mov    (%rax),%edi
lea    0xdfb(%rip),%rsi
mov    $0x64,%edx
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
jmp    1040 <fprintf@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [54 x i8] c"Out of memory allocating space for %ld atom requests\0A\00"
define void @list_atoms(i32* %0, i8* %1, i32 %2, i64 %3, i64 %4) {
%6 = alloca i32*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i64
%10 = alloca i64
%11 = alloca i32*
%12 = alloca i32
store i32* %0, i32** %6
store i8* %1, i8** %7
store i32 %2, i32* %8
store i64 %3, i64* %9
store i64 %4, i64* %10
store i32 0, i32* %12
%13 = load i32, i32* %8
switch i32 %13, label %44 [
i32 2, label %14
i32 3, label %15
i32 1, label %45
]
14: ; preds = %5
store i64 1, i64* %9
br label %15
15: ; preds = %5, %14
%16 = load i64, i64* %10
%17 = load i64, i64* %9
%18 = sub nsw i64 %16, %17
%19 = add nsw i64 %18, 1
%20 = mul i64 %19, 4
%21 = trunc i64 %20 to i32
%22 = call i32* @malloc(i32 %21)
store i32* %22, i32** %11
%23 = load i32*, i32** %11
%24 = icmp ne i32* %23, null
br i1 %24, label %31, label %25
25: ; preds = %15
%26 = load i32, i32* @stderr
%27 = load i64, i64* %10
%28 = load i64, i64* %9
%29 = sub nsw i64 %27, %28
%30 = call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str, i64 0, i64 0), i64 %29)
br label %69
31: ; preds = %15
%32 = load i32*, i32** %6
%33 = load i8*, i8** %7
%34 = load i32*, i32** %11
%35 = load i64, i64* %9
%36 = load i64, i64* %10
%37 = load i64, i64* %9
%38 = sub nsw i64 %36, %37
%39 = add nsw i64 %38, 1
%40 = trunc i64 %39 to i32
%41 = call i32 @say_batch(i32* %32, i8* %33, i32* %34, i64 %35, i32 %40)
%42 = load i32*, i32** %11
%43 = call i32 @free(i32* %42)
br label %68
44: ; preds = %5
store i64 1, i64* %9
br label %45
45: ; preds = %5, %44
%46 = call i32* @malloc(i32 400)
store i32* %46, i32** %11
%47 = load i32*, i32** %11
%48 = icmp ne i32* %47, null
br i1 %48, label %52, label %49
49: ; preds = %45
%50 = load i32, i32* @stderr
%51 = call i32 @fprintf(i32 %50, i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str, i64 0, i64 0), i64 100)
br label %69
52: ; preds = %45
br label %53
53: ; preds = %57, %52
%54 = load i32, i32* %12
%55 = icmp ne i32 %54, 0
%56 = xor i1 %55, true
br i1 %56, label %57, label %65
57: ; preds = %53
%58 = load i32*, i32** %6
%59 = load i8*, i8** %7
%60 = load i32*, i32** %11
%61 = load i64, i64* %9
%62 = call i32 @say_batch(i32* %58, i8* %59, i32* %60, i64 %61, i32 100)
store i32 %62, i32* %12
%63 = load i64, i64* %9
%64 = add nsw i64 %63, 100
store i64 %64, i64* %9
br label %53
65: ; preds = %53
%66 = load i32*, i32** %11
%67 = call i32 @free(i32* %66)
br label %68
68: ; preds = %65, %31
br label %69
69: ; preds = %68, %49, %25
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [54 x i8] c"Out of memory allocating space for %ld atom requests\0A\00"
define void @list_atoms(i32* %0, i8* %1, i32 %2, i64 %3, i64 %4) {
switch i32 %2, label %21 [
i32 2, label %6
i32 3, label %7
i32 1, label %22
]
6: ; preds = %5
br label %7
7: ; preds = %5, %6
%8 = phi i64 [ %3, %5 ], [ 1, %6 ]
%9 = sub nsw i64 %4, %8
%10 = trunc i64 %9 to i32
%11 = add i32 %10, 1
%12 = shl i32 %11, 2
%13 = tail call i32* @malloc(i32 %12)
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %18
15: ; preds = %7
%16 = load i32, i32* @stderr
%17 = tail call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str, i64 0, i64 0), i64 %9)
br label %36
18: ; preds = %7
%19 = tail call i32 @say_batch(i32* %0, i8* %1, i32* %13, i64 %8, i32 %11)
%20 = tail call i32 @free(i32* %13)
br label %36
21: ; preds = %5
br label %22
22: ; preds = %5, %21
%23 = phi i64 [ 1, %21 ], [ %3, %5 ]
%24 = tail call i32* @malloc(i32 400)
%25 = icmp eq i32* %24, null
br i1 %25, label %26, label %29
26: ; preds = %22
%27 = load i32, i32* @stderr
%28 = tail call i32 @fprintf(i32 %27, i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str, i64 0, i64 0), i64 100)
br label %36
29: ; preds = %22, %29
%30 = phi i64 [ %32, %29 ], [ %23, %22 ]
%31 = tail call i32 @say_batch(i32* %0, i8* %1, i32* %24, i64 %30, i32 100)
%32 = add nsw i64 %30, 100
%33 = icmp eq i32 %31, 0
br i1 %33, label %29, label %34
34: ; preds = %29
%35 = tail call i32 @free(i32* %24)
br label %36
36: ; preds = %18, %34, %26, %15
ret void
}