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

/* Variables and functions */
int /*<<< orphan*/ free(int /*<<< orphan*/ *);
int /*<<< orphan*/ memcpy(char *, int /*<<< orphan*/, int);
int strlen(char const *);
char *xcb_atom_get_name_predefined(int /*<<< orphan*/);
int /*<<< orphan*/ xcb_get_atom_name(int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ xcb_get_atom_name_name(int /*<<< orphan*/ *);
int xcb_get_atom_name_name_length(int /*<<< orphan*/ *);
int /*<<< orphan*/ *xcb_get_atom_name_reply(int /*<<< orphan*/ *,
                                            int /*<<< orphan*/,
                                            int /*<<< orphan*/);
int xcb_atom_get_name(xcb_connection_t *c, xcb_atom_t atom, const char **namep,
                      int *lengthp) {
  static char buf[100];
  const char *name = xcb_atom_get_name_predefined(atom);
  int namelen;
  xcb_get_atom_name_cookie_t atomc;
  xcb_get_atom_name_reply_t *atomr;
  if (name) {
    *namep = name;
    *lengthp = strlen(name);
    return 1;
  }
  atomc = xcb_get_atom_name(c, atom);
  atomr = xcb_get_atom_name_reply(c, atomc, 0);
  if (!atomr)
    return 0;
  namelen = xcb_get_atom_name_name_length(atomr);
  if (namelen > sizeof(buf))
    namelen = sizeof(buf);
  *lengthp = namelen;
  memcpy(buf, xcb_get_atom_name_name(atomr), namelen);
  *namep = buf;
  free(atomr);
  return 1;
}


x86 assembly (clang, -O0):
<xcb_atom_get_name>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x14(%rbp),%edi
call   1070 <xcb_atom_get_name_predefined@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     11d6 <xcb_atom_get_name+0x56>
mov    -0x30(%rbp),%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x30(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x1,-0x4(%rbp)
jmp    1270 <xcb_atom_get_name+0xf0>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1030 <xcb_get_atom_name@plt>
mov    %eax,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x38(%rbp),%esi
xor    %edx,%edx
call   1060 <xcb_get_atom_name_reply@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
jne    120e <xcb_atom_get_name+0x8e>
movl   $0x0,-0x4(%rbp)
jmp    1270 <xcb_atom_get_name+0xf0>
mov    -0x40(%rbp),%rdi
call   10a0 <xcb_get_atom_name_name_length@plt>
mov    %eax,-0x34(%rbp)
movslq -0x34(%rbp),%rax
cmp    $0x64,%rax
jbe    122f <xcb_atom_get_name+0xaf>
movl   $0x64,-0x34(%rbp)
mov    -0x34(%rbp),%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x40(%rbp),%rdi
call   1080 <xcb_get_atom_name_name@plt>
mov    %eax,%esi
mov    -0x34(%rbp),%edx
lea    0x2e23(%rip),%rdi
call   1090 <memcpy@plt>
mov    -0x20(%rbp),%rax
lea    0x2e13(%rip),%rcx
mov    %rcx,(%rax)
mov    -0x40(%rbp),%rdi
call   1040 <free@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<xcb_atom_get_name>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rcx,%r15
mov    %rdx,%r14
mov    %esi,%ebp
mov    %rdi,%rbx
mov    %esi,%edi
call   1070 <xcb_atom_get_name_predefined@plt>
test   %rax,%rax
je     11ae <xcb_atom_get_name+0x2e>
mov    %rax,(%r14)
mov    %rax,%rdi
call   1050 <strlen@plt>
mov    %eax,(%r15)
jmp    120a <xcb_atom_get_name+0x8a>
mov    %rbx,%rdi
mov    %ebp,%esi
call   1030 <xcb_get_atom_name@plt>
xor    %ebp,%ebp
mov    %rbx,%rdi
mov    %eax,%esi
xor    %edx,%edx
call   1060 <xcb_get_atom_name_reply@plt>
test   %rax,%rax
je     120f <xcb_atom_get_name+0x8f>
mov    %rax,%rbx
mov    %rax,%rdi
call   10a0 <xcb_get_atom_name_name_length@plt>
cmp    $0x64,%eax
mov    $0x64,%ebp
cmovb  %eax,%ebp
mov    %ebp,(%r15)
mov    %rbx,%rdi
call   1080 <xcb_get_atom_name_name@plt>
lea    0x2e7d(%rip),%r15
mov    %r15,%rdi
mov    %eax,%esi
mov    %ebp,%edx
call   1090 <memcpy@plt>
mov    %r15,(%r14)
mov    %rbx,%rdi
call   1040 <free@plt>
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@xcb_atom_get_name.buf = internal global [100 x i8] zeroinitializer
define i32 @xcb_atom_get_name(i32* %0, i32 %1, i8** %2, i32* %3) {
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i8**
%9 = alloca i32*
%10 = alloca i8*
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32*
store i32* %0, i32** %6
store i32 %1, i32* %7
store i8** %2, i8*** %8
store i32* %3, i32** %9
%14 = load i32, i32* %7
%15 = call i8* @xcb_atom_get_name_predefined(i32 %14)
store i8* %15, i8** %10
%16 = load i8*, i8** %10
%17 = icmp ne i8* %16, null
br i1 %17, label %18, label %24
18: ; preds = %4
%19 = load i8*, i8** %10
%20 = load i8**, i8*** %8
store i8* %19, i8** %20
%21 = load i8*, i8** %10
%22 = call i32 @strlen(i8* %21)
%23 = load i32*, i32** %9
store i32 %22, i32* %23
store i32 1, i32* %5
br label %51
24: ; preds = %4
%25 = load i32*, i32** %6
%26 = load i32, i32* %7
%27 = call i32 @xcb_get_atom_name(i32* %25, i32 %26)
store i32 %27, i32* %12
%28 = load i32*, i32** %6
%29 = load i32, i32* %12
%30 = call i32* @xcb_get_atom_name_reply(i32* %28, i32 %29, i32 0)
store i32* %30, i32** %13
%31 = load i32*, i32** %13
%32 = icmp ne i32* %31, null
br i1 %32, label %34, label %33
33: ; preds = %24
store i32 0, i32* %5
br label %51
34: ; preds = %24
%35 = load i32*, i32** %13
%36 = call i32 @xcb_get_atom_name_name_length(i32* %35)
store i32 %36, i32* %11
%37 = load i32, i32* %11
%38 = sext i32 %37 to i64
%39 = icmp ugt i64 %38, 100
br i1 %39, label %40, label %41
40: ; preds = %34
store i32 100, i32* %11
br label %41
41: ; preds = %40, %34
%42 = load i32, i32* %11
%43 = load i32*, i32** %9
store i32 %42, i32* %43
%44 = load i32*, i32** %13
%45 = call i32 @xcb_get_atom_name_name(i32* %44)
%46 = load i32, i32* %11
%47 = call i32 @memcpy(i8* getelementptr inbounds ([100 x i8], [100 x i8]* @xcb_atom_get_name.buf, i64 0, i64 0), i32 %45, i32 %46)
%48 = load i8**, i8*** %8
store i8* getelementptr inbounds ([100 x i8], [100 x i8]* @xcb_atom_get_name.buf, i64 0, i64 0), i8** %48
%49 = load i32*, i32** %13
%50 = call i32 @free(i32* %49)
store i32 1, i32* %5
br label %51
51: ; preds = %41, %33, %18
%52 = load i32, i32* %5
ret i32 %52
}

LLVM IR (-O2):
@xcb_atom_get_name.buf = internal global [100 x i8] zeroinitializer
define i32 @xcb_atom_get_name(i32* %0, i32 %1, i8** nocapture writeonly %2, i32* nocapture writeonly %3) {
%5 = tail call i8* @xcb_atom_get_name_predefined(i32 %1)
%6 = icmp eq i8* %5, null
br i1 %6, label %9, label %7
7: ; preds = %4
store i8* %5, i8** %2
%8 = tail call i32 @strlen(i8* %5)
store i32 %8, i32* %3
br label %20
9: ; preds = %4
%10 = tail call i32 @xcb_get_atom_name(i32* %0, i32 %1)
%11 = tail call i32* @xcb_get_atom_name_reply(i32* %0, i32 %10, i32 0)
%12 = icmp eq i32* %11, null
br i1 %12, label %20, label %13
13: ; preds = %9
%14 = tail call i32 @xcb_get_atom_name_name_length(i32* %11)
%15 = icmp ult i32 %14, 100
%16 = select i1 %15, i32 %14, i32 100
store i32 %16, i32* %3
%17 = tail call i32 @xcb_get_atom_name_name(i32* %11)
%18 = tail call i32 @memcpy(i8* getelementptr inbounds ([100 x i8], [100 x i8]* @xcb_atom_get_name.buf, i64 0, i64 0), i32 %17, i32 %16)
store i8* getelementptr inbounds ([100 x i8], [100 x i8]* @xcb_atom_get_name.buf, i64 0, i64 0), i8** %2
%19 = tail call i32 @free(i32* %11)
br label %20
20: ; preds = %9, %13, %7
%21 = phi i32 [ 1, %7 ], [ 1, %13 ], [ 0, %9 ]
ret i32 %21
}