#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_7__ TYPE_2__;
typedef struct TYPE_6__ TYPE_1__;

/* Type definitions */
struct TYPE_6__ {
  int depth;
  int /*<<< orphan*/ visual;
};
typedef TYPE_1__ XVisualInfo;
struct TYPE_7__ {
  int bits_per_pixel;
  int /*<<< orphan*/ *data;
};
typedef TYPE_2__ XImage;
typedef int /*<<< orphan*/ Display;

/* Variables and functions */
TYPE_2__ *XCreateImage(int /*<<< orphan*/ *, int /*<<< orphan*/, int,
                       int /*<<< orphan*/, int /*<<< orphan*/, char *, int, int,
                       int, int /*<<< orphan*/);
int /*<<< orphan*/ XDestroyImage(TYPE_2__ *);
int /*<<< orphan*/ ZPixmap;
int /*<<< orphan*/ gl_free(char *);
char *gl_malloc(int);
int bits_per_pixel(Display *dpy, XVisualInfo *visinfo) {
  XImage *img;
  int bpp;
  char *data;
  data = gl_malloc(8);
  if (data == NULL)
    return visinfo->depth;
  img = XCreateImage(dpy, visinfo->visual, visinfo->depth, ZPixmap, 0, data, 1,
                     1, 32, 0);
  if (img == NULL) {
    gl_free(data);
    return visinfo->depth;
  }
  bpp = img->bits_per_pixel;
  gl_free(data);
  img->data = NULL;
  XDestroyImage(img);
  return bpp;
}


x86 assembly (clang, -O0):
<bits_per_pixel>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    $0x8,%edi
call   1050 <gl_malloc@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1177 <bits_per_pixel+0x37>
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    120f <bits_per_pixel+0xcf>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    0x4(%rax),%esi
mov    -0x18(%rbp),%rax
mov    (%rax),%edx
mov    0x2e59(%rip),%rax
mov    (%rax),%ecx
mov    -0x30(%rbp),%r9
xor    %r8d,%r8d
movl   $0x1,(%rsp)
movl   $0x1,0x8(%rsp)
movl   $0x20,0x10(%rsp)
movl   $0x0,0x18(%rsp)
call   1060 <XCreateImage@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11e2 <bits_per_pixel+0xa2>
mov    -0x30(%rbp),%rdi
call   1040 <gl_free@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    120f <bits_per_pixel+0xcf>
mov    -0x20(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    -0x30(%rbp),%rdi
call   1040 <gl_free@plt>
mov    -0x20(%rbp),%rax
movq   $0x0,0x8(%rax)
mov    -0x20(%rbp),%rdi
call   1030 <XDestroyImage@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bits_per_pixel>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rbp
mov    $0x8,%edi
call   1050 <gl_malloc@plt>
test   %rax,%rax
je     11b3 <bits_per_pixel+0x73>
mov    %rax,%rbx
mov    (%r14),%edx
mov    0x4(%r14),%esi
mov    0x2e7e(%rip),%rax
mov    (%rax),%ecx
mov    %rbp,%rdi
xor    %r8d,%r8d
mov    %rbx,%r9
push   $0x0
push   $0x20
push   $0x1
push   $0x1
call   1060 <XCreateImage@plt>
add    $0x20,%rsp
test   %rax,%rax
je     11ab <bits_per_pixel+0x6b>
mov    %rax,%rbp
mov    (%rax),%r14d
mov    %rbx,%rdi
call   1040 <gl_free@plt>
movq   $0x0,0x8(%rbp)
mov    %rbp,%rdi
call   1030 <XDestroyImage@plt>
jmp    11b6 <bits_per_pixel+0x76>
mov    %rbx,%rdi
call   1040 <gl_free@plt>
mov    (%r14),%r14d
mov    %r14d,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.TYPE_6__ = type { i32, i32 }
%struct.TYPE_7__ = type { i32, i32* }
@ZPixmap = global i32 0
define i32 @bits_per_pixel(i32* %0, %struct.TYPE_6__* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca %struct.TYPE_6__*
%6 = alloca %struct.TYPE_7__*
%7 = alloca i32
%8 = alloca i8*
store i32* %0, i32** %4
store %struct.TYPE_6__* %1, %struct.TYPE_6__** %5
%9 = call i8* @gl_malloc(i32 8)
store i8* %9, i8** %8
%10 = load i8*, i8** %8
%11 = icmp eq i8* %10, null
br i1 %11, label %12, label %16
12: ; preds = %2
%13 = load %struct.TYPE_6__*, %struct.TYPE_6__** %5
%14 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %13, i32 0, i32 0
%15 = load i32, i32* %14
store i32 %15, i32* %3
br label %46
16: ; preds = %2
%17 = load i32*, i32** %4
%18 = load %struct.TYPE_6__*, %struct.TYPE_6__** %5
%19 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %18, i32 0, i32 1
%20 = load i32, i32* %19
%21 = load %struct.TYPE_6__*, %struct.TYPE_6__** %5
%22 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %21, i32 0, i32 0
%23 = load i32, i32* %22
%24 = load i32, i32* @ZPixmap
%25 = load i8*, i8** %8
%26 = call %struct.TYPE_7__* @XCreateImage(i32* %17, i32 %20, i32 %23, i32 %24, i32 0, i8* %25, i32 1, i32 1, i32 32, i32 0)
store %struct.TYPE_7__* %26, %struct.TYPE_7__** %6
%27 = load %struct.TYPE_7__*, %struct.TYPE_7__** %6
%28 = icmp eq %struct.TYPE_7__* %27, null
br i1 %28, label %29, label %35
29: ; preds = %16
%30 = load i8*, i8** %8
%31 = call i32 @gl_free(i8* %30)
%32 = load %struct.TYPE_6__*, %struct.TYPE_6__** %5
%33 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %32, i32 0, i32 0
%34 = load i32, i32* %33
store i32 %34, i32* %3
br label %46
35: ; preds = %16
%36 = load %struct.TYPE_7__*, %struct.TYPE_7__** %6
%37 = getelementptr inbounds %struct.TYPE_7__, %struct.TYPE_7__* %36, i32 0, i32 0
%38 = load i32, i32* %37
store i32 %38, i32* %7
%39 = load i8*, i8** %8
%40 = call i32 @gl_free(i8* %39)
%41 = load %struct.TYPE_7__*, %struct.TYPE_7__** %6
%42 = getelementptr inbounds %struct.TYPE_7__, %struct.TYPE_7__* %41, i32 0, i32 1
store i32* null, i32** %42
%43 = load %struct.TYPE_7__*, %struct.TYPE_7__** %6
%44 = call i32 @XDestroyImage(%struct.TYPE_7__* %43)
%45 = load i32, i32* %7
store i32 %45, i32* %3
br label %46
46: ; preds = %35, %29, %12
%47 = load i32, i32* %3
ret i32 %47
}

LLVM IR (-O2):
%struct.TYPE_6__ = type { i32, i32 }
%struct.TYPE_7__ = type { i32, i32* }
@ZPixmap = global i32 0
define i32 @bits_per_pixel(i32* %0, %struct.TYPE_6__* nocapture %1) {
%3 = tail call i8* @gl_malloc(i32 8)
%4 = icmp eq i8* %3, null
br i1 %4, label %5, label %8
5: ; preds = %2
%6 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %1, i64 0, i32 0
%7 = load i32, i32* %6
br label %25
8: ; preds = %2
%9 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %1, i64 0, i32 1
%10 = load i32, i32* %9
%11 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %1, i64 0, i32 0
%12 = load i32, i32* %11
%13 = load i32, i32* @ZPixmap
%14 = tail call %struct.TYPE_7__* @XCreateImage(i32* %0, i32 %10, i32 %12, i32 %13, i32 0, i8* %3, i32 1, i32 1, i32 32, i32 0)
%15 = icmp eq %struct.TYPE_7__* %14, null
br i1 %15, label %16, label %19
16: ; preds = %8
%17 = tail call i32 @gl_free(i8* %3)
%18 = load i32, i32* %11
br label %25
19: ; preds = %8
%20 = getelementptr inbounds %struct.TYPE_7__, %struct.TYPE_7__* %14, i64 0, i32 0
%21 = load i32, i32* %20
%22 = tail call i32 @gl_free(i8* %3)
%23 = getelementptr inbounds %struct.TYPE_7__, %struct.TYPE_7__* %14, i64 0, i32 1
store i32* null, i32** %23
%24 = tail call i32 @XDestroyImage(%struct.TYPE_7__* %14)
br label %25
25: ; preds = %19, %16, %5
%26 = phi i32 [ %7, %5 ], [ %18, %16 ], [ %21, %19 ]
ret i32 %26
}