#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 depth;
  int bits_per_pixel;
};
typedef TYPE_1__ XPixmapFormatValues;
typedef int /*<<< orphan*/ Display;

/* Variables and functions */
int /*<<< orphan*/ XFree(TYPE_1__ *);
TYPE_1__ *XListPixmapFormats(int /*<<< orphan*/ *, int *);
int get_bits_per_pixel(Display *dpy, int depth) {
  unsigned i = 0;
  int count, result;
  XPixmapFormatValues *formats = XListPixmapFormats(dpy, &count);
  if (!formats)
    return 0;
  for (;;) {
    if (i == (unsigned)count) {
      result = 0;
      break;
    }
    if (formats[i].depth == depth) {
      result = formats[i].bits_per_pixel;
      break;
    }
    ++i;
  }
  XFree(formats);
  return result;
}


x86 assembly (clang, -O0):
<get_bits_per_pixel>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x1c(%rbp),%rsi
call   1030 <XListPixmapFormats@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    115e <get_bits_per_pixel+0x3e>
movl   $0x0,-0x4(%rbp)
jmp    11be <get_bits_per_pixel+0x9e>
jmp    1163 <get_bits_per_pixel+0x43>
mov    -0x18(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jne    117b <get_bits_per_pixel+0x5b>
movl   $0x0,-0x20(%rbp)
jmp    11af <get_bits_per_pixel+0x8f>
mov    -0x28(%rbp),%rax
mov    -0x18(%rbp),%ecx
mov    (%rax,%rcx,8),%eax
cmp    -0x14(%rbp),%eax
jne    11a1 <get_bits_per_pixel+0x81>
mov    -0x28(%rbp),%rax
mov    -0x18(%rbp),%ecx
mov    0x4(%rax,%rcx,8),%eax
mov    %eax,-0x20(%rbp)
jmp    11af <get_bits_per_pixel+0x8f>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1163 <get_bits_per_pixel+0x43>
mov    -0x28(%rbp),%rdi
call   1040 <XFree@plt>
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_bits_per_pixel>:
push   %rbx
sub    $0x10,%rsp
mov    %esi,%ebx
lea    0xc(%rsp),%rsi
call   1030 <XListPixmapFormats@plt>
test   %rax,%rax
je     1163 <get_bits_per_pixel+0x43>
mov    0xc(%rsp),%ecx
test   %rcx,%rcx
je     115f <get_bits_per_pixel+0x3f>
xor    %edx,%edx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %edx,%esi
cmp    %ebx,(%rax,%rsi,8)
je     1167 <get_bits_per_pixel+0x47>
add    $0x1,%rdx
cmp    %edx,%ecx
jne    1150 <get_bits_per_pixel+0x30>
xor    %ebx,%ebx
jmp    116b <get_bits_per_pixel+0x4b>
xor    %ebx,%ebx
jmp    1173 <get_bits_per_pixel+0x53>
mov    0x4(%rax,%rdx,8),%ebx
mov    %rax,%rdi
call   1040 <XFree@plt>
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
ret

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

LLVM IR (-O2):
%struct.TYPE_4__ = type { i32, i32 }
define i32 @get_bits_per_pixel(i32* %0, i32 %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = call %struct.TYPE_4__* @XListPixmapFormats(i32* %0, i32* %3)
%6 = icmp eq %struct.TYPE_4__* %5, null
br i1 %6, label %26, label %7
7: ; preds = %2
%8 = load i32, i32* %3
%9 = icmp eq i32 %8, 0
br i1 %9, label %23, label %10
10: ; preds = %7, %20
%11 = phi i32 [ %21, %20 ], [ 0, %7 ]
%12 = zext i32 %11 to i64
%13 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %5, i64 %12, i32 0
%14 = load i32, i32* %13
%15 = icmp eq i32 %14, %1
br i1 %15, label %16, label %20
16: ; preds = %10
%17 = zext i32 %11 to i64
%18 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %5, i64 %17, i32 1
%19 = load i32, i32* %18
br label %23
20: ; preds = %10
%21 = add i32 %11, 1
%22 = icmp eq i32 %21, %8
br i1 %22, label %23, label %10
23: ; preds = %20, %7, %16
%24 = phi i32 [ %19, %16 ], [ 0, %7 ], [ 0, %20 ]
%25 = call i32 @XFree(%struct.TYPE_4__* %5)
br label %26
26: ; preds = %2, %23
%27 = phi i32 [ %24, %23 ], [ 0, %2 ]
ret i32 %27
}