#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 */
typedef struct TYPE_4__ TYPE_1__;

/* Type definitions */
struct TYPE_4__ {
  int /*<<< orphan*/ atom;
};
typedef TYPE_1__ xcb_intern_atom_reply_t;
typedef int /*<<< orphan*/ xcb_intern_atom_cookie_t;
typedef int /*<<< orphan*/ xcb_connection_t;
typedef int /*<<< orphan*/ xcb_atom_t;

/* Variables and functions */
int /*<<< orphan*/ free(TYPE_1__ *);
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ xcb_intern_atom(int /*<<< orphan*/ *, int /*<<< orphan*/,
                                   int /*<<< orphan*/, char *);
TYPE_1__ *xcb_intern_atom_reply(int /*<<< orphan*/ *, int /*<<< orphan*/,
                                int /*<<< orphan*/ *);
void useXCBPoorly(char **names, xcb_connection_t *connection) {
  xcb_atom_t atoms[500];
  for (int i = 0; i < 500; i++) {
    xcb_intern_atom_cookie_t cookie =
        xcb_intern_atom(connection, 0, strlen(names[i]), names[i]);
    xcb_intern_atom_reply_t *reply =
        xcb_intern_atom_reply(connection, cookie, NULL);
    if (reply) {
      atoms[i] = reply->atom;
      free(reply);
    }
  }
}


x86 assembly (clang, -O0):
<useXCBPoorly>:
push   %rbp
mov    %rsp,%rbp
sub    $0x800,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x7e4(%rbp)
cmpl   $0x1f4,-0x7e4(%rbp)
jge    1215 <useXCBPoorly+0xd5>
mov    -0x10(%rbp),%rax
mov    %rax,-0x7f8(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x7e4(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1040 <strlen@plt>
mov    -0x7f8(%rbp),%rdi
mov    %eax,%edx
mov    -0x8(%rbp),%rax
movslq -0x7e4(%rbp),%rcx
mov    (%rax,%rcx,8),%rcx
xor    %esi,%esi
call   1050 <xcb_intern_atom@plt>
mov    %eax,-0x7e8(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x7e8(%rbp),%esi
xor    %eax,%eax
mov    %eax,%edx
call   1060 <xcb_intern_atom_reply@plt>
mov    %rax,-0x7f0(%rbp)
cmpq   $0x0,-0x7f0(%rbp)
je     11fc <useXCBPoorly+0xbc>
mov    -0x7f0(%rbp),%rax
mov    (%rax),%ecx
movslq -0x7e4(%rbp),%rax
mov    %ecx,-0x7e0(%rbp,%rax,4)
mov    -0x7f0(%rbp),%rdi
call   1030 <free@plt>
jmp    1201 <useXCBPoorly+0xc1>
mov    -0x7e4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x7e4(%rbp)
jmp    115d <useXCBPoorly+0x1d>
add    $0x800,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<useXCBPoorly>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
xor    %ebx,%ebx
jmp    115d <useXCBPoorly+0x1d>
nop
add    $0x1,%rbx
cmp    $0x1f4,%rbx
je     1191 <useXCBPoorly+0x51>
mov    (%r15,%rbx,8),%rdi
call   1040 <strlen@plt>
mov    (%r15,%rbx,8),%rcx
mov    %r14,%rdi
xor    %esi,%esi
mov    %eax,%edx
call   1050 <xcb_intern_atom@plt>
mov    %r14,%rdi
mov    %eax,%esi
xor    %edx,%edx
call   1060 <xcb_intern_atom_reply@plt>
test   %rax,%rax
je     1150 <useXCBPoorly+0x10>
mov    %rax,%rdi
call   1030 <free@plt>
jmp    1150 <useXCBPoorly+0x10>
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.TYPE_4__ = type { i32 }
define void @useXCBPoorly(i8** %0, i32* %1) {
%3 = alloca i8**
%4 = alloca i32*
%5 = alloca [500 x i32]
%6 = alloca i32
%7 = alloca i32
%8 = alloca %struct.TYPE_4__*
store i8** %0, i8*** %3
store i32* %1, i32** %4
store i32 0, i32* %6
br label %9
9: ; preds = %41, %2
%10 = load i32, i32* %6
%11 = icmp slt i32 %10, 500
br i1 %11, label %12, label %44
12: ; preds = %9
%13 = load i32*, i32** %4
%14 = load i8**, i8*** %3
%15 = load i32, i32* %6
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i8*, i8** %14, i64 %16
%18 = load i8*, i8** %17
%19 = call i32 @strlen(i8* %18)
%20 = load i8**, i8*** %3
%21 = load i32, i32* %6
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8*, i8** %20, i64 %22
%24 = load i8*, i8** %23
%25 = call i32 @xcb_intern_atom(i32* %13, i32 0, i32 %19, i8* %24)
store i32 %25, i32* %7
%26 = load i32*, i32** %4
%27 = load i32, i32* %7
%28 = call %struct.TYPE_4__* @xcb_intern_atom_reply(i32* %26, i32 %27, i32* null)
store %struct.TYPE_4__* %28, %struct.TYPE_4__** %8
%29 = load %struct.TYPE_4__*, %struct.TYPE_4__** %8
%30 = icmp ne %struct.TYPE_4__* %29, null
br i1 %30, label %31, label %40
31: ; preds = %12
%32 = load %struct.TYPE_4__*, %struct.TYPE_4__** %8
%33 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %32, i32 0, i32 0
%34 = load i32, i32* %33
%35 = load i32, i32* %6
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds [500 x i32], [500 x i32]* %5, i64 0, i64 %36
store i32 %34, i32* %37
%38 = load %struct.TYPE_4__*, %struct.TYPE_4__** %8
%39 = call i32 @free(%struct.TYPE_4__* %38)
br label %40
40: ; preds = %31, %12
br label %41
41: ; preds = %40
%42 = load i32, i32* %6
%43 = add nsw i32 %42, 1
store i32 %43, i32* %6
br label %9
44: ; preds = %9
ret void
}

LLVM IR (-O2):
%struct.TYPE_4__ = type { i32 }
define void @useXCBPoorly(i8** nocapture %0, i32* %1) {
br label %4
3: ; preds = %15
ret void
4: ; preds = %2, %15
%5 = phi i64 [ 0, %2 ], [ %16, %15 ]
%6 = getelementptr inbounds i8*, i8** %0, i64 %5
%7 = load i8*, i8** %6
%8 = tail call i32 @strlen(i8* %7)
%9 = load i8*, i8** %6
%10 = tail call i32 @xcb_intern_atom(i32* %1, i32 0, i32 %8, i8* %9)
%11 = tail call %struct.TYPE_4__* @xcb_intern_atom_reply(i32* %1, i32 %10, i32* null)
%12 = icmp eq %struct.TYPE_4__* %11, null
br i1 %12, label %15, label %13
13: ; preds = %4
%14 = tail call i32 @free(%struct.TYPE_4__* %11)
br label %15
15: ; preds = %13, %4
%16 = add nuw nsw i64 %5, 1
%17 = icmp eq i64 %16, 500
br i1 %17, label %3, label %4
}