#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*/ Display;

/* Variables and functions */
scalar_t__ iupdrvGetDisplay();
scalar_t__ xCheckVisualInfo(int /*<<< orphan*/ *, int);
int iupdrvGetScreenDepth(void) {
  static int first = 1;
  static int bpp;
  if (first) {
    Display *drv_display = (Display *)iupdrvGetDisplay();
    if (xCheckVisualInfo(drv_display, 24)) {
      bpp = 24;
      return bpp;
    }
    if (xCheckVisualInfo(drv_display, 16)) {
      bpp = 16;
      return bpp;
    }
    if (xCheckVisualInfo(drv_display, 8)) {
      bpp = 8;
      return bpp;
    }
    if (xCheckVisualInfo(drv_display, 4)) {
      bpp = 4;
      return bpp;
    }
    bpp = 2;
    first = 0;
  }
  return bpp;
}


x86 assembly (clang, -O0):
<iupdrvGetScreenDepth>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
cmpl   $0x0,0x2f01(%rip)
je     1214 <iupdrvGetScreenDepth+0xf4>
mov    $0x0,%al
call   1040 <iupdrvGetDisplay@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x18,%esi
call   1030 <xCheckVisualInfo@plt>
cmp    $0x0,%rax
je     1170 <iupdrvGetScreenDepth+0x50>
movl   $0x18,0x2ed6(%rip)
mov    0x2ed0(%rip),%eax
mov    %eax,-0x4(%rbp)
jmp    121d <iupdrvGetScreenDepth+0xfd>
mov    -0x10(%rbp),%rdi
mov    $0x10,%esi
call   1030 <xCheckVisualInfo@plt>
cmp    $0x0,%rax
je     11a0 <iupdrvGetScreenDepth+0x80>
movl   $0x10,0x2ea6(%rip)
mov    0x2ea0(%rip),%eax
mov    %eax,-0x4(%rbp)
jmp    121d <iupdrvGetScreenDepth+0xfd>
mov    -0x10(%rbp),%rdi
mov    $0x8,%esi
call   1030 <xCheckVisualInfo@plt>
cmp    $0x0,%rax
je     11d0 <iupdrvGetScreenDepth+0xb0>
movl   $0x8,0x2e76(%rip)
mov    0x2e70(%rip),%eax
mov    %eax,-0x4(%rbp)
jmp    121d <iupdrvGetScreenDepth+0xfd>
mov    -0x10(%rbp),%rdi
mov    $0x4,%esi
call   1030 <xCheckVisualInfo@plt>
cmp    $0x0,%rax
je     1200 <iupdrvGetScreenDepth+0xe0>
movl   $0x4,0x2e46(%rip)
mov    0x2e40(%rip),%eax
mov    %eax,-0x4(%rbp)
jmp    121d <iupdrvGetScreenDepth+0xfd>
movl   $0x2,0x2e2e(%rip)
movl   $0x0,0x2e1c(%rip)
mov    0x2e1e(%rip),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<iupdrvGetScreenDepth>:
push   %r14
push   %rbx
push   %rax
cmpb   $0x1,0x2f09(%rip)
jne    1138 <iupdrvGetScreenDepth+0x18>
mov    0x2f05(%rip),%ebx
jmp    11e4 <iupdrvGetScreenDepth+0xc4>
xor    %eax,%eax
call   1040 <iupdrvGetDisplay@plt>
mov    %rax,%r14
mov    $0x18,%ebx
mov    %rax,%rdi
mov    $0x18,%esi
call   1030 <xCheckVisualInfo@plt>
test   %rax,%rax
je     1165 <iupdrvGetScreenDepth+0x45>
movl   $0x18,0x2ed5(%rip)
jmp    11e4 <iupdrvGetScreenDepth+0xc4>
mov    $0x10,%ebx
mov    %r14,%rdi
mov    $0x10,%esi
call   1030 <xCheckVisualInfo@plt>
test   %rax,%rax
je     1188 <iupdrvGetScreenDepth+0x68>
movl   $0x10,0x2eb2(%rip)
jmp    11e4 <iupdrvGetScreenDepth+0xc4>
mov    $0x8,%ebx
mov    %r14,%rdi
mov    $0x8,%esi
call   1030 <xCheckVisualInfo@plt>
test   %rax,%rax
je     11ab <iupdrvGetScreenDepth+0x8b>
movl   $0x8,0x2e8f(%rip)
jmp    11e4 <iupdrvGetScreenDepth+0xc4>
mov    $0x4,%ebx
mov    %r14,%rdi
mov    $0x4,%esi
call   1030 <xCheckVisualInfo@plt>
test   %rax,%rax
je     11ce <iupdrvGetScreenDepth+0xae>
movl   $0x4,0x2e6c(%rip)
jmp    11e4 <iupdrvGetScreenDepth+0xc4>
movl   $0x2,0x2e60(%rip)
movb   $0x1,0x2e55(%rip)
mov    $0x2,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@iupdrvGetScreenDepth.first = internal global i32 1
@iupdrvGetScreenDepth.bpp = internal global i32 0
define i32 @iupdrvGetScreenDepth() {
%1 = alloca i32
%2 = alloca i32*
%3 = load i32, i32* @iupdrvGetScreenDepth.first
%4 = icmp ne i32 %3, 0
br i1 %4, label %5, label %32
5: ; preds = %0
%6 = call i64 (...) @iupdrvGetDisplay()
%7 = inttoptr i64 %6 to i32*
store i32* %7, i32** %2
%8 = load i32*, i32** %2
%9 = call i64 @xCheckVisualInfo(i32* %8, i32 24)
%10 = icmp ne i64 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %5
store i32 24, i32* @iupdrvGetScreenDepth.bpp
%12 = load i32, i32* @iupdrvGetScreenDepth.bpp
store i32 %12, i32* %1
br label %34
13: ; preds = %5
%14 = load i32*, i32** %2
%15 = call i64 @xCheckVisualInfo(i32* %14, i32 16)
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %13
store i32 16, i32* @iupdrvGetScreenDepth.bpp
%18 = load i32, i32* @iupdrvGetScreenDepth.bpp
store i32 %18, i32* %1
br label %34
19: ; preds = %13
%20 = load i32*, i32** %2
%21 = call i64 @xCheckVisualInfo(i32* %20, i32 8)
%22 = icmp ne i64 %21, 0
br i1 %22, label %23, label %25
23: ; preds = %19
store i32 8, i32* @iupdrvGetScreenDepth.bpp
%24 = load i32, i32* @iupdrvGetScreenDepth.bpp
store i32 %24, i32* %1
br label %34
25: ; preds = %19
%26 = load i32*, i32** %2
%27 = call i64 @xCheckVisualInfo(i32* %26, i32 4)
%28 = icmp ne i64 %27, 0
br i1 %28, label %29, label %31
29: ; preds = %25
store i32 4, i32* @iupdrvGetScreenDepth.bpp
%30 = load i32, i32* @iupdrvGetScreenDepth.bpp
store i32 %30, i32* %1
br label %34
31: ; preds = %25
store i32 2, i32* @iupdrvGetScreenDepth.bpp
store i32 0, i32* @iupdrvGetScreenDepth.first
br label %32
32: ; preds = %31, %0
%33 = load i32, i32* @iupdrvGetScreenDepth.bpp
store i32 %33, i32* %1
br label %34
34: ; preds = %32, %29, %23, %17, %11
%35 = load i32, i32* %1
ret i32 %35
}

LLVM IR (-O2):
@iupdrvGetScreenDepth.first = internal unnamed_addr global i1 false
@iupdrvGetScreenDepth.bpp = internal unnamed_addr global i32 0
define i32 @iupdrvGetScreenDepth() {
%1 = load i1, i1* @iupdrvGetScreenDepth.first
br i1 %1, label %2, label %4
2: ; preds = %0
%3 = load i32, i32* @iupdrvGetScreenDepth.bpp
br label %23
4: ; preds = %0
%5 = tail call i64 (...) @iupdrvGetDisplay()
%6 = inttoptr i64 %5 to i32*
%7 = tail call i64 @xCheckVisualInfo(i32* %6, i32 24)
%8 = icmp eq i64 %7, 0
br i1 %8, label %10, label %9
9: ; preds = %4
store i32 24, i32* @iupdrvGetScreenDepth.bpp
br label %23
10: ; preds = %4
%11 = tail call i64 @xCheckVisualInfo(i32* %6, i32 16)
%12 = icmp eq i64 %11, 0
br i1 %12, label %14, label %13
13: ; preds = %10
store i32 16, i32* @iupdrvGetScreenDepth.bpp
br label %23
14: ; preds = %10
%15 = tail call i64 @xCheckVisualInfo(i32* %6, i32 8)
%16 = icmp eq i64 %15, 0
br i1 %16, label %18, label %17
17: ; preds = %14
store i32 8, i32* @iupdrvGetScreenDepth.bpp
br label %23
18: ; preds = %14
%19 = tail call i64 @xCheckVisualInfo(i32* %6, i32 4)
%20 = icmp eq i64 %19, 0
br i1 %20, label %22, label %21
21: ; preds = %18
store i32 4, i32* @iupdrvGetScreenDepth.bpp
br label %23
22: ; preds = %18
store i32 2, i32* @iupdrvGetScreenDepth.bpp
store i1 true, i1* @iupdrvGetScreenDepth.first
br label %23
23: ; preds = %22, %2, %21, %17, %13, %9
%24 = phi i32 [ 4, %21 ], [ 8, %17 ], [ 16, %13 ], [ 24, %9 ], [ %3, %2 ], [ 2, %22 ]
ret i32 %24
}