#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 uint32_t;

/* Variables and functions */
scalar_t__ xa_format_type_is_color(int);
unsigned int xa_format_depth(uint32_t xa_format) {
  return ((xa_format_type_is_color(xa_format))
              ? ((((xa_format) >> 12) & 0x0f) + (((xa_format) >> 8) & 0x0f) +
                 (((xa_format) >> 4) & 0x0f) + (((xa_format)) & 0x0f))
              : ((((xa_format) >> 8) & 0xff) + (((xa_format)) & 0xff)));
}


x86 assembly (clang, -O0):
<xa_format_depth>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
call   1030 <xa_format_type_is_color@plt>
cmp    $0x0,%rax
je     115c <xa_format_depth+0x4c>
mov    -0x4(%rbp),%eax
sar    $0xc,%eax
and    $0xf,%eax
mov    -0x4(%rbp),%ecx
sar    $0x8,%ecx
and    $0xf,%ecx
add    %ecx,%eax
mov    -0x4(%rbp),%ecx
sar    $0x4,%ecx
and    $0xf,%ecx
add    %ecx,%eax
mov    -0x4(%rbp),%ecx
and    $0xf,%ecx
add    %ecx,%eax
mov    %eax,-0x8(%rbp)
jmp    1175 <xa_format_depth+0x65>
mov    -0x4(%rbp),%eax
sar    $0x8,%eax
and    $0xff,%eax
mov    -0x4(%rbp),%ecx
and    $0xff,%ecx
add    %ecx,%eax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<xa_format_depth>:
push   %rbx
mov    %edi,%ebx
call   1030 <xa_format_type_is_color@plt>
test   %rax,%rax
je     1140 <xa_format_depth+0x30>
mov    %ebx,%eax
shr    $0xc,%eax
and    $0xf,%eax
mov    %ebx,%ecx
shr    $0x8,%ecx
and    $0xf,%ecx
mov    %ebx,%edx
shr    $0x4,%edx
and    $0xf,%edx
and    $0xf,%ebx
add    %ecx,%ebx
add    %eax,%ebx
add    %edx,%ebx
jmp    1148 <xa_format_depth+0x38>
movzbl %bh,%eax
movzbl %bl,%ebx
add    %eax,%ebx
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
define i32 @xa_format_depth(i32 %0) {
%2 = alloca i32
store i32 %0, i32* %2
%3 = load i32, i32* %2
%4 = call i64 @xa_format_type_is_color(i32 %3)
%5 = icmp ne i64 %4, 0
br i1 %5, label %6, label %21
6: ; preds = %1
%7 = load i32, i32* %2
%8 = ashr i32 %7, 12
%9 = and i32 %8, 15
%10 = load i32, i32* %2
%11 = ashr i32 %10, 8
%12 = and i32 %11, 15
%13 = add nsw i32 %9, %12
%14 = load i32, i32* %2
%15 = ashr i32 %14, 4
%16 = and i32 %15, 15
%17 = add nsw i32 %13, %16
%18 = load i32, i32* %2
%19 = and i32 %18, 15
%20 = add nsw i32 %17, %19
br label %28
21: ; preds = %1
%22 = load i32, i32* %2
%23 = ashr i32 %22, 8
%24 = and i32 %23, 255
%25 = load i32, i32* %2
%26 = and i32 %25, 255
%27 = add nsw i32 %24, %26
br label %28
28: ; preds = %21, %6
%29 = phi i32 [ %20, %6 ], [ %27, %21 ]
ret i32 %29
}

LLVM IR (-O2):
define i32 @xa_format_depth(i32 %0) {
%2 = tail call i64 @xa_format_type_is_color(i32 %0)
%3 = icmp eq i64 %2, 0
br i1 %3, label %15, label %4
4: ; preds = %1
%5 = lshr i32 %0, 12
%6 = and i32 %5, 15
%7 = lshr i32 %0, 8
%8 = and i32 %7, 15
%9 = lshr i32 %0, 4
%10 = and i32 %9, 15
%11 = and i32 %0, 15
%12 = add nuw nsw i32 %8, %11
%13 = add nuw nsw i32 %12, %6
%14 = add nuw nsw i32 %13, %10
br label %20
15: ; preds = %1
%16 = lshr i32 %0, 8
%17 = and i32 %16, 255
%18 = and i32 %0, 255
%19 = add nuw nsw i32 %17, %18
br label %20
20: ; preds = %15, %4
%21 = phi i32 [ %14, %4 ], [ %19, %15 ]
ret i32 %21
}