#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_8__ TYPE_4__;
typedef struct TYPE_7__ TYPE_3__;
typedef struct TYPE_6__ TYPE_2__;
typedef struct TYPE_5__ TYPE_1__;

/* Type definitions */
struct TYPE_8__ {
  scalar_t__ length;
};
struct TYPE_7__ {
  scalar_t__ length;
};
struct TYPE_6__ {
  scalar_t__ length;
};
struct TYPE_5__ {
  scalar_t__ length;
};
struct fb_var_screeninfo {
  TYPE_4__ blue;
  TYPE_3__ green;
  TYPE_2__ red;
  TYPE_1__ transp;
};
struct fb_fix_screeninfo {
  scalar_t__ visual;
};
struct fb_cmap {
  int len;
  int /*<<< orphan*/ *blue;
  int /*<<< orphan*/ *green;
  int /*<<< orphan*/ *red;
  int /*<<< orphan*/ *transp;
};
typedef int /*<<< orphan*/ __u16;

/* Variables and functions */
scalar_t__ FB_VISUAL_MONO01;
scalar_t__ FB_VISUAL_MONO10;
scalar_t__ FB_VISUAL_TRUECOLOR;
int /*<<< orphan*/ free(int /*<<< orphan*/ *);
scalar_t__ malloc(int);
int /*<<< orphan*/ memset(struct fb_cmap *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
struct fb_cmap *fb_cmap_create(struct fb_fix_screeninfo *fscinfo,
                               struct fb_var_screeninfo *vscinfo) {
  struct fb_cmap *cmap;
  int cmaplen = (256);
  if (fscinfo->visual == FB_VISUAL_MONO01 ||
      fscinfo->visual == FB_VISUAL_MONO10 ||
      fscinfo->visual == FB_VISUAL_TRUECOLOR)
    return NULL;
  cmap = (struct fb_cmap *)malloc(sizeof(struct fb_cmap));
  if (!cmap) {
    perror("cmap malloc error\n");
    return (struct fb_cmap *)-1;
  }
  memset(cmap, 0, sizeof(struct fb_cmap));
  if (vscinfo->red.length) {
    cmap->red = (__u16 *)malloc(sizeof(__u16) * cmaplen);
    if (!cmap->red) {
      perror("red lut malloc error\n");
      return (struct fb_cmap *)-1;
    }
  }
  if (vscinfo->green.length) {
    cmap->green = (__u16 *)malloc(sizeof(__u16) * cmaplen);
    if (!cmap->green) {
      if (vscinfo->red.length)
        free(cmap->red);
      perror("green lut malloc error\n");
      return (struct fb_cmap *)-1;
    }
  }
  if (vscinfo->blue.length) {
    cmap->blue = (__u16 *)malloc(sizeof(__u16) * cmaplen);
    if (!cmap->blue) {
      if (vscinfo->red.length)
        free(cmap->red);
      if (vscinfo->green.length)
        free(cmap->green);
      perror("blue lut malloc error\n");
      return (struct fb_cmap *)-1;
    }
  }
  if (vscinfo->transp.length) {
    cmap->transp = (__u16 *)malloc(sizeof(__u16) * cmaplen);
    if (!cmap->transp) {
      if (vscinfo->red.length)
        free(cmap->red);
      if (vscinfo->green.length)
        free(cmap->green);
      if (vscinfo->blue.length)
        free(cmap->blue);
      perror("transp lut malloc error\n");
      return (struct fb_cmap *)-1;
    }
  }
  cmap->len = cmaplen;
  return cmap;
}


x86 assembly (clang, -O0):
<fb_cmap_create>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x100,-0x24(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    0x2e83(%rip),%rcx
cmp    (%rcx),%rax
je     119c <fb_cmap_create+0x5c>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    0x2e64(%rip),%rcx
cmp    (%rcx),%rax
je     119c <fb_cmap_create+0x5c>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    0x2e45(%rip),%rcx
cmp    (%rcx),%rax
jne    11a9 <fb_cmap_create+0x69>
movq   $0x0,-0x8(%rbp)
jmp    1409 <fb_cmap_create+0x2c9>
mov    $0x28,%edi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11de <fb_cmap_create+0x9e>
lea    0xe37(%rip),%rdi
call   1060 <perror@plt>
mov    $0xffffffffffffffff,%rax
mov    %rax,-0x8(%rbp)
jmp    1409 <fb_cmap_create+0x2c9>
mov    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   1040 <memset@plt>
mov    -0x18(%rbp),%rax
cmpq   $0x0,0x10(%rax)
je     1247 <fb_cmap_create+0x107>
movslq -0x24(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,0x18(%rax)
mov    -0x20(%rbp),%rax
cmpq   $0x0,0x18(%rax)
jne    1242 <fb_cmap_create+0x102>
lea    0xde6(%rip),%rdi
call   1060 <perror@plt>
mov    $0xffffffffffffffff,%rax
mov    %rax,-0x8(%rbp)
jmp    1409 <fb_cmap_create+0x2c9>
jmp    1247 <fb_cmap_create+0x107>
mov    -0x18(%rbp),%rax
cmpq   $0x0,0x8(%rax)
je     12bc <fb_cmap_create+0x17c>
movslq -0x24(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,0x10(%rax)
mov    -0x20(%rbp),%rax
cmpq   $0x0,0x10(%rax)
jne    12b7 <fb_cmap_create+0x177>
mov    -0x18(%rbp),%rax
cmpq   $0x0,0x10(%rax)
je     129b <fb_cmap_create+0x15b>
mov    -0x20(%rbp),%rax
mov    0x18(%rax),%rdi
call   1030 <free@plt>
lea    0xd87(%rip),%rdi
call   1060 <perror@plt>
mov    $0xffffffffffffffff,%rax
mov    %rax,-0x8(%rbp)
jmp    1409 <fb_cmap_create+0x2c9>
jmp    12bc <fb_cmap_create+0x17c>
mov    -0x18(%rbp),%rax
cmpq   $0x0,(%rax)
je     134c <fb_cmap_create+0x20c>
movslq -0x24(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,0x8(%rax)
mov    -0x20(%rbp),%rax
cmpq   $0x0,0x8(%rax)
jne    1347 <fb_cmap_create+0x207>
mov    -0x18(%rbp),%rax
cmpq   $0x0,0x10(%rax)
je     130f <fb_cmap_create+0x1cf>
mov    -0x20(%rbp),%rax
mov    0x18(%rax),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rax
cmpq   $0x0,0x8(%rax)
je     132b <fb_cmap_create+0x1eb>
mov    -0x20(%rbp),%rax
mov    0x10(%rax),%rdi
call   1030 <free@plt>
lea    0xd0f(%rip),%rdi
call   1060 <perror@plt>
mov    $0xffffffffffffffff,%rax
mov    %rax,-0x8(%rbp)
jmp    1409 <fb_cmap_create+0x2c9>
jmp    134c <fb_cmap_create+0x20c>
mov    -0x18(%rbp),%rax
cmpq   $0x0,0x18(%rax)
je     13f8 <fb_cmap_create+0x2b8>
movslq -0x24(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,0x20(%rax)
mov    -0x20(%rbp),%rax
cmpq   $0x0,0x20(%rax)
jne    13f3 <fb_cmap_create+0x2b3>
mov    -0x18(%rbp),%rax
cmpq   $0x0,0x10(%rax)
je     13a0 <fb_cmap_create+0x260>
mov    -0x20(%rbp),%rax
mov    0x18(%rax),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rax
cmpq   $0x0,0x8(%rax)
je     13bc <fb_cmap_create+0x27c>
mov    -0x20(%rbp),%rax
mov    0x10(%rax),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rax
cmpq   $0x0,(%rax)
je     13d7 <fb_cmap_create+0x297>
mov    -0x20(%rbp),%rax
mov    0x8(%rax),%rdi
call   1030 <free@plt>
lea    0xc7a(%rip),%rdi
call   1060 <perror@plt>
mov    $0xffffffffffffffff,%rax
mov    %rax,-0x8(%rbp)
jmp    1409 <fb_cmap_create+0x2c9>
jmp    13f8 <fb_cmap_create+0x2b8>
mov    -0x24(%rbp),%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fb_cmap_create>:
push   %r14
push   %rbx
push   %rax
mov    (%rdi),%rax
mov    0x2e9a(%rip),%rcx
xor    %ebx,%ebx
cmp    (%rcx),%rax
je     120e <fb_cmap_create+0xce>
mov    0x2e80(%rip),%rcx
cmp    (%rcx),%rax
je     120e <fb_cmap_create+0xce>
mov    0x2e68(%rip),%rcx
cmp    (%rcx),%rax
je     120e <fb_cmap_create+0xce>
mov    %rsi,%r14
mov    $0x28,%edi
call   1050 <malloc@plt>
test   %rax,%rax
je     1219 <fb_cmap_create+0xd9>
mov    %rax,%rbx
mov    %rax,%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   1040 <memset@plt>
cmpq   $0x0,0x10(%r14)
je     11bb <fb_cmap_create+0x7b>
mov    $0x400,%edi
call   1050 <malloc@plt>
mov    %rax,0x18(%rbx)
test   %rax,%rax
je     1222 <fb_cmap_create+0xe2>
cmpq   $0x0,0x8(%r14)
je     11d5 <fb_cmap_create+0x95>
mov    $0x400,%edi
call   1050 <malloc@plt>
mov    %rax,0x10(%rbx)
test   %rax,%rax
je     122b <fb_cmap_create+0xeb>
cmpq   $0x0,(%r14)
je     11ee <fb_cmap_create+0xae>
mov    $0x400,%edi
call   1050 <malloc@plt>
mov    %rax,0x8(%rbx)
test   %rax,%rax
je     1244 <fb_cmap_create+0x104>
cmpq   $0x0,0x18(%r14)
je     1208 <fb_cmap_create+0xc8>
mov    $0x400,%edi
call   1050 <malloc@plt>
mov    %rax,0x20(%rbx)
test   %rax,%rax
je     126d <fb_cmap_create+0x12d>
movl   $0x100,(%rbx)
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xde0(%rip),%rdi
jmp    1291 <fb_cmap_create+0x151>
lea    0xdea(%rip),%rdi
jmp    1291 <fb_cmap_create+0x151>
cmpq   $0x0,0x10(%r14)
je     123b <fb_cmap_create+0xfb>
mov    0x18(%rbx),%rdi
call   1030 <free@plt>
lea    0xde7(%rip),%rdi
jmp    1291 <fb_cmap_create+0x151>
cmpq   $0x0,0x10(%r14)
je     1254 <fb_cmap_create+0x114>
mov    0x18(%rbx),%rdi
call   1030 <free@plt>
cmpq   $0x0,0x8(%r14)
je     1264 <fb_cmap_create+0x124>
mov    0x10(%rbx),%rdi
call   1030 <free@plt>
lea    0xdd6(%rip),%rdi
jmp    1291 <fb_cmap_create+0x151>
cmpq   $0x0,0x10(%r14)
jne    12a2 <fb_cmap_create+0x162>
cmpq   $0x0,0x8(%r14)
jne    12b2 <fb_cmap_create+0x172>
cmpq   $0x0,(%r14)
je     128a <fb_cmap_create+0x14a>
mov    0x8(%rbx),%rdi
call   1030 <free@plt>
lea    0xdc7(%rip),%rdi
call   1060 <perror@plt>
mov    $0xffffffffffffffff,%rbx
jmp    120e <fb_cmap_create+0xce>
mov    0x18(%rbx),%rdi
call   1030 <free@plt>
cmpq   $0x0,0x8(%r14)
je     127b <fb_cmap_create+0x13b>
mov    0x10(%rbx),%rdi
call   1030 <free@plt>
cmpq   $0x0,(%r14)
jne    1281 <fb_cmap_create+0x141>
jmp    128a <fb_cmap_create+0x14a>

LLVM IR (-O0):
%struct.fb_cmap = type { i32, i32*, i32*, i32*, i32* }
%struct.fb_fix_screeninfo = type { i64 }
%struct.fb_var_screeninfo = type { %struct.TYPE_8__, %struct.TYPE_7__, %struct.TYPE_6__, %struct.TYPE_5__ }
%struct.TYPE_8__ = type { i64 }
%struct.TYPE_7__ = type { i64 }
%struct.TYPE_6__ = type { i64 }
%struct.TYPE_5__ = type { i64 }
@FB_VISUAL_MONO01 = global i64 0
@FB_VISUAL_MONO10 = global i64 0
@FB_VISUAL_TRUECOLOR = global i64 0
@.str = [19 x i8] c"cmap malloc error\0A\00"
@.str.1 = [22 x i8] c"red lut malloc error\0A\00"
@.str.2 = [24 x i8] c"green lut malloc error\0A\00"
@.str.3 = [23 x i8] c"blue lut malloc error\0A\00"
@.str.4 = [25 x i8] c"transp lut malloc error\0A\00"
define %struct.fb_cmap* @fb_cmap_create(%struct.fb_fix_screeninfo* %0, %struct.fb_var_screeninfo* %1) {
%3 = alloca %struct.fb_cmap*
%4 = alloca %struct.fb_fix_screeninfo*
%5 = alloca %struct.fb_var_screeninfo*
%6 = alloca %struct.fb_cmap*
%7 = alloca i32
store %struct.fb_fix_screeninfo* %0, %struct.fb_fix_screeninfo** %4
store %struct.fb_var_screeninfo* %1, %struct.fb_var_screeninfo** %5
store i32 256, i32* %7
%8 = load %struct.fb_fix_screeninfo*, %struct.fb_fix_screeninfo** %4
%9 = getelementptr inbounds %struct.fb_fix_screeninfo, %struct.fb_fix_screeninfo* %8, i32 0, i32 0
%10 = load i64, i64* %9
%11 = load i64, i64* @FB_VISUAL_MONO01
%12 = icmp eq i64 %10, %11
br i1 %12, label %25, label %13
13: ; preds = %2
%14 = load %struct.fb_fix_screeninfo*, %struct.fb_fix_screeninfo** %4
%15 = getelementptr inbounds %struct.fb_fix_screeninfo, %struct.fb_fix_screeninfo* %14, i32 0, i32 0
%16 = load i64, i64* %15
%17 = load i64, i64* @FB_VISUAL_MONO10
%18 = icmp eq i64 %16, %17
br i1 %18, label %25, label %19
19: ; preds = %13
%20 = load %struct.fb_fix_screeninfo*, %struct.fb_fix_screeninfo** %4
%21 = getelementptr inbounds %struct.fb_fix_screeninfo, %struct.fb_fix_screeninfo* %20, i32 0, i32 0
%22 = load i64, i64* %21
%23 = load i64, i64* @FB_VISUAL_TRUECOLOR
%24 = icmp eq i64 %22, %23
br i1 %24, label %25, label %26
25: ; preds = %19, %13, %2
store %struct.fb_cmap* null, %struct.fb_cmap** %3
br label %194
26: ; preds = %19
%27 = call i64 @malloc(i32 40)
%28 = inttoptr i64 %27 to %struct.fb_cmap*
store %struct.fb_cmap* %28, %struct.fb_cmap** %6
%29 = load %struct.fb_cmap*, %struct.fb_cmap** %6
%30 = icmp ne %struct.fb_cmap* %29, null
br i1 %30, label %33, label %31
31: ; preds = %26
%32 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
store %struct.fb_cmap* inttoptr (i64 -1 to %struct.fb_cmap*), %struct.fb_cmap** %3
br label %194
33: ; preds = %26
%34 = load %struct.fb_cmap*, %struct.fb_cmap** %6
%35 = call i32 @memset(%struct.fb_cmap* %34, i32 0, i32 40)
%36 = load %struct.fb_var_screeninfo*, %struct.fb_var_screeninfo** %5
%37 = getelementptr inbounds %struct.fb_var_screeninfo, %struct.fb_var_screeninfo* %36, i32 0, i32 2
%38 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %37, i32 0, i32 0
%39 = load i64, i64* %38
%40 = icmp ne i64 %39, 0
br i1 %40, label %41, label %57
41: ; preds = %33
%42 = load i32, i32* %7
%43 = sext i32 %42 to i64
%44 = mul i64 4, %43
%45 = trunc i64 %44 to i32
%46 = call i64 @malloc(i32 %45)
%47 = inttoptr i64 %46 to i32*
%48 = load %struct.fb_cmap*, %struct.fb_cmap** %6
%49 = getelementptr inbounds %struct.fb_cmap, %struct.fb_cmap* %48, i32 0, i32 3
store i32* %47, i32** %49
%50 = load %struct.fb_cmap*, %struct.fb_cmap** %6
%51 = getelementptr inbounds %struct.fb_cmap, %struct.fb_cmap* %50, i32 0, i32 3
%52 = load i32*, i32** %51
%53 = icmp ne i32* %52, null
br i1 %53, label %56, label %54
54: ; preds = %41
%55 = call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
store %struct.fb_cmap* inttoptr (i64 -1 to %struct.fb_cmap*), %struct.fb_cmap** %3
br label %194
56: ; preds = %41
br label %57
57: ; preds = %56, %33
%58 = load %struct.fb_var_screeninfo*, %struct.fb_var_screeninfo** %5
%59 = getelementptr inbounds %struct.fb_var_screeninfo, %struct.fb_var_screeninfo* %58, i32 0, i32 1
%60 = getelementptr inbounds %struct.TYPE_7__, %struct.TYPE_7__* %59, i32 0, i32 0
%61 = load i64, i64* %60
%62 = icmp ne i64 %61, 0
br i1 %62, label %63, label %90
63: ; preds = %57
%64 = load i32, i32* %7
%65 = sext i32 %64 to i64
%66 = mul i64 4, %65
%67 = trunc i64 %66 to i32
%68 = call i64 @malloc(i32 %67)
%69 = inttoptr i64 %68 to i32*
%70 = load %struct.fb_cmap*, %struct.fb_cmap** %6
%71 = getelementptr inbounds %struct.fb_cmap, %struct.fb_cmap* %70, i32 0, i32 2
store i32* %69, i32** %71
%72 = load %struct.fb_cmap*, %struct.fb_cmap** %6
%73 = getelementptr inbounds %struct.fb_cmap, %struct.fb_cmap* %72, i32 0, i32 2
%74 = load i32*, i32** %73
%75 = icmp ne i32* %74, null
br i1 %75, label %89, label %76
76: ; preds = %63
%77 = load %struct.fb_var_screeninfo*, %struct.fb_var_screeninfo** %5
%78 = getelementptr inbounds %struct.fb_var_screeninfo, %struct.fb_var_screeninfo* %77, i32 0, i32 2
%79 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %78, i32 0, i32 0
%80 = load i64, i64* %79
%81 = icmp ne i64 %80, 0
br i1 %81, label %82, label %87
82: ; preds = %76
%83 = load %struct.fb_cmap*, %struct.fb_cmap** %6
%84 = getelementptr inbounds %struct.fb_cmap, %struct.fb_cmap* %83, i32 0, i32 3
%85 = load i32*, i32** %84
%86 = call i32 @free(i32* %85)
br label %87
87: ; preds = %82, %76
%88 = call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
store %struct.fb_cmap* inttoptr (i64 -1 to %struct.fb_cmap*), %struct.fb_cmap** %3
br label %194
89: ; preds = %63
br label %90
90: ; preds = %89, %57
%91 = load %struct.fb_var_screeninfo*, %struct.fb_var_screeninfo** %5
%92 = getelementptr inbounds %struct.fb_var_screeninfo, %struct.fb_var_screeninfo* %91, i32 0, i32 0
%93 = getelementptr inbounds %struct.TYPE_8__, %struct.TYPE_8__* %92, i32 0, i32 0
%94 = load i64, i64* %93
%95 = icmp ne i64 %94, 0
br i1 %95, label %96, label %134
96: ; preds = %90
%97 = load i32, i32* %7
%98 = sext i32 %97 to i64
%99 = mul i64 4, %98
%100 = trunc i64 %99 to i32
%101 = call i64 @malloc(i32 %100)
%102 = inttoptr i64 %101 to i32*
%103 = load %struct.fb_cmap*, %struct.fb_cmap** %6
%104 = getelementptr inbounds %struct.fb_cmap, %struct.fb_cmap* %103, i32 0, i32 1
store i32* %102, i32** %104
%105 = load %struct.fb_cmap*, %struct.fb_cmap** %6
%106 = getelementptr inbounds %struct.fb_cmap, %struct.fb_cmap* %105, i32 0, i32 1
%107 = load i32*, i32** %106
%108 = icmp ne i32* %107, null
br i1 %108, label %133, label %109
109: ; preds = %96
%110 = load %struct.fb_var_screeninfo*, %struct.fb_var_screeninfo** %5
%111 = getelementptr inbounds %struct.fb_var_screeninfo, %struct.fb_var_screeninfo* %110, i32 0, i32 2
%112 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %111, i32 0, i32 0
%113 = load i64, i64* %112
%114 = icmp ne i64 %113, 0
br i1 %114, label %115, label %120
115: ; preds = %109
%116 = load %struct.fb_cmap*, %struct.fb_cmap** %6
%117 = getelementptr inbounds %struct.fb_cmap, %struct.fb_cmap* %116, i32 0, i32 3
%118 = load i32*, i32** %117
%119 = call i32 @free(i32* %118)
br label %120
120: ; preds = %115, %109
%121 = load %struct.fb_var_screeninfo*, %struct.fb_var_screeninfo** %5
%122 = getelementptr inbounds %struct.fb_var_screeninfo, %struct.fb_var_screeninfo* %121, i32 0, i32 1
%123 = getelementptr inbounds %struct.TYPE_7__, %struct.TYPE_7__* %122, i32 0, i32 0
%124 = load i64, i64* %123
%125 = icmp ne i64 %124, 0
br i1 %125, label %126, label %131
126: ; preds = %120
%127 = load %struct.fb_cmap*, %struct.fb_cmap** %6
%128 = getelementptr inbounds %struct.fb_cmap, %struct.fb_cmap* %127, i32 0, i32 2
%129 = load i32*, i32** %128
%130 = call i32 @free(i32* %129)
br label %131
131: ; preds = %126, %120
%132 = call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0))
store %struct.fb_cmap* inttoptr (i64 -1 to %struct.fb_cmap*), %struct.fb_cmap** %3
br label %194
133: ; preds = %96
br label %134
134: ; preds = %133, %90
%135 = load %struct.fb_var_screeninfo*, %struct.fb_var_screeninfo** %5
%136 = getelementptr inbounds %struct.fb_var_screeninfo, %struct.fb_var_screeninfo* %135, i32 0, i32 3
%137 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %136, i32 0, i32 0
%138 = load i64, i64* %137
%139 = icmp ne i64 %138, 0
br i1 %139, label %140, label %189
140: ; preds = %134
%141 = load i32, i32* %7
%142 = sext i32 %141 to i64
%143 = mul i64 4, %142
%144 = trunc i64 %143 to i32
%145 = call i64 @malloc(i32 %144)
%146 = inttoptr i64 %145 to i32*
%147 = load %struct.fb_cmap*, %struct.fb_cmap** %6
%148 = getelementptr inbounds %struct.fb_cmap, %struct.fb_cmap* %147, i32 0, i32 4
store i32* %146, i32** %148
%149 = load %struct.fb_cmap*, %struct.fb_cmap** %6
%150 = getelementptr inbounds %struct.fb_cmap, %struct.fb_cmap* %149, i32 0, i32 4
%151 = load i32*, i32** %150
%152 = icmp ne i32* %151, null
br i1 %152, label %188, label %153
153: ; preds = %140
%154 = load %struct.fb_var_screeninfo*, %struct.fb_var_screeninfo** %5
%155 = getelementptr inbounds %struct.fb_var_screeninfo, %struct.fb_var_screeninfo* %154, i32 0, i32 2
%156 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %155, i32 0, i32 0
%157 = load i64, i64* %156
%158 = icmp ne i64 %157, 0
br i1 %158, label %159, label %164
159: ; preds = %153
%160 = load %struct.fb_cmap*, %struct.fb_cmap** %6
%161 = getelementptr inbounds %struct.fb_cmap, %struct.fb_cmap* %160, i32 0, i32 3
%162 = load i32*, i32** %161
%163 = call i32 @free(i32* %162)
br label %164
164: ; preds = %159, %153
%165 = load %struct.fb_var_screeninfo*, %struct.fb_var_screeninfo** %5
%166 = getelementptr inbounds %struct.fb_var_screeninfo, %struct.fb_var_screeninfo* %165, i32 0, i32 1
%167 = getelementptr inbounds %struct.TYPE_7__, %struct.TYPE_7__* %166, i32 0, i32 0
%168 = load i64, i64* %167
%169 = icmp ne i64 %168, 0
br i1 %169, label %170, label %175
170: ; preds = %164
%171 = load %struct.fb_cmap*, %struct.fb_cmap** %6
%172 = getelementptr inbounds %struct.fb_cmap, %struct.fb_cmap* %171, i32 0, i32 2
%173 = load i32*, i32** %172
%174 = call i32 @free(i32* %173)
br label %175
175: ; preds = %170, %164
%176 = load %struct.fb_var_screeninfo*, %struct.fb_var_screeninfo** %5
%177 = getelementptr inbounds %struct.fb_var_screeninfo, %struct.fb_var_screeninfo* %176, i32 0, i32 0
%178 = getelementptr inbounds %struct.TYPE_8__, %struct.TYPE_8__* %177, i32 0, i32 0
%179 = load i64, i64* %178
%180 = icmp ne i64 %179, 0
br i1 %180, label %181, label %186
181: ; preds = %175
%182 = load %struct.fb_cmap*, %struct.fb_cmap** %6
%183 = getelementptr inbounds %struct.fb_cmap, %struct.fb_cmap* %182, i32 0, i32 1
%184 = load i32*, i32** %183
%185 = call i32 @free(i32* %184)
br label %186
186: ; preds = %181, %175
%187 = call i32 @perror(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0))
store %struct.fb_cmap* inttoptr (i64 -1 to %struct.fb_cmap*), %struct.fb_cmap** %3
br label %194
188: ; preds = %140
br label %189
189: ; preds = %188, %134
%190 = load i32, i32* %7
%191 = load %struct.fb_cmap*, %struct.fb_cmap** %6
%192 = getelementptr inbounds %struct.fb_cmap, %struct.fb_cmap* %191, i32 0, i32 0
store i32 %190, i32* %192
%193 = load %struct.fb_cmap*, %struct.fb_cmap** %6
store %struct.fb_cmap* %193, %struct.fb_cmap** %3
br label %194
194: ; preds = %189, %186, %131, %87, %54, %31, %25
%195 = load %struct.fb_cmap*, %struct.fb_cmap** %3
ret %struct.fb_cmap* %195
}

LLVM IR (-O2):
%struct.fb_cmap = type { i32, i32*, i32*, i32*, i32* }
%struct.fb_fix_screeninfo = type { i64 }
%struct.fb_var_screeninfo = type { %struct.TYPE_8__, %struct.TYPE_7__, %struct.TYPE_6__, %struct.TYPE_5__ }
%struct.TYPE_8__ = type { i64 }
%struct.TYPE_7__ = type { i64 }
%struct.TYPE_6__ = type { i64 }
%struct.TYPE_5__ = type { i64 }
@FB_VISUAL_MONO01 = global i64 0
@FB_VISUAL_MONO10 = global i64 0
@FB_VISUAL_TRUECOLOR = global i64 0
@.str = [19 x i8] c"cmap malloc error\0A\00"
@.str.1 = [22 x i8] c"red lut malloc error\0A\00"
@.str.2 = [24 x i8] c"green lut malloc error\0A\00"
@.str.3 = [23 x i8] c"blue lut malloc error\0A\00"
@.str.4 = [25 x i8] c"transp lut malloc error\0A\00"
define %struct.fb_cmap* @fb_cmap_create(%struct.fb_fix_screeninfo* nocapture %0, %struct.fb_var_screeninfo* nocapture %1) {
%3 = getelementptr inbounds %struct.fb_fix_screeninfo, %struct.fb_fix_screeninfo* %0, i64 0, i32 0
%4 = load i64, i64* %3
%5 = load i64, i64* @FB_VISUAL_MONO01
%6 = icmp eq i64 %4, %5
%7 = load i64, i64* @FB_VISUAL_MONO10
%8 = icmp eq i64 %4, %7
%9 = select i1 %6, i1 true, i1 %8
%10 = load i64, i64* @FB_VISUAL_TRUECOLOR
%11 = icmp eq i64 %4, %10
%12 = select i1 %9, i1 true, i1 %11
br i1 %12, label %108, label %13
13: ; preds = %2
%14 = tail call i64 @malloc(i32 40)
%15 = inttoptr i64 %14 to %struct.fb_cmap*
%16 = icmp eq i64 %14, 0
br i1 %16, label %17, label %19
17: ; preds = %13
%18 = tail call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
br label %108
19: ; preds = %13
%20 = tail call i32 @memset(%struct.fb_cmap* %15, i32 0, i32 40)
%21 = getelementptr inbounds %struct.fb_var_screeninfo, %struct.fb_var_screeninfo* %1, i64 0, i32 2, i32 0
%22 = load i64, i64* %21
%23 = icmp eq i64 %22, 0
br i1 %23, label %31, label %24
24: ; preds = %19
%25 = tail call i64 @malloc(i32 1024)
%26 = inttoptr i64 %25 to i32*
%27 = getelementptr inbounds %struct.fb_cmap, %struct.fb_cmap* %15, i64 0, i32 3
store i32* %26, i32** %27
%28 = icmp eq i64 %25, 0
br i1 %28, label %29, label %31
29: ; preds = %24
%30 = tail call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
br label %108
31: ; preds = %24, %19
%32 = getelementptr inbounds %struct.fb_var_screeninfo, %struct.fb_var_screeninfo* %1, i64 0, i32 1, i32 0
%33 = load i64, i64* %32
%34 = icmp eq i64 %33, 0
br i1 %34, label %49, label %35
35: ; preds = %31
%36 = tail call i64 @malloc(i32 1024)
%37 = inttoptr i64 %36 to i32*
%38 = getelementptr inbounds %struct.fb_cmap, %struct.fb_cmap* %15, i64 0, i32 2
store i32* %37, i32** %38
%39 = icmp eq i64 %36, 0
br i1 %39, label %40, label %49
40: ; preds = %35
%41 = load i64, i64* %21
%42 = icmp eq i64 %41, 0
br i1 %42, label %47, label %43
43: ; preds = %40
%44 = getelementptr inbounds %struct.fb_cmap, %struct.fb_cmap* %15, i64 0, i32 3
%45 = load i32*, i32** %44
%46 = tail call i32 @free(i32* %45)
br label %47
47: ; preds = %43, %40
%48 = tail call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
br label %108
49: ; preds = %35, %31
%50 = getelementptr inbounds %struct.fb_var_screeninfo, %struct.fb_var_screeninfo* %1, i64 0, i32 0, i32 0
%51 = load i64, i64* %50
%52 = icmp eq i64 %51, 0
br i1 %52, label %74, label %53
53: ; preds = %49
%54 = tail call i64 @malloc(i32 1024)
%55 = inttoptr i64 %54 to i32*
%56 = getelementptr inbounds %struct.fb_cmap, %struct.fb_cmap* %15, i64 0, i32 1
store i32* %55, i32** %56
%57 = icmp eq i64 %54, 0
br i1 %57, label %58, label %74
58: ; preds = %53
%59 = load i64, i64* %21
%60 = icmp eq i64 %59, 0
br i1 %60, label %65, label %61
61: ; preds = %58
%62 = getelementptr inbounds %struct.fb_cmap, %struct.fb_cmap* %15, i64 0, i32 3
%63 = load i32*, i32** %62
%64 = tail call i32 @free(i32* %63)
br label %65
65: ; preds = %61, %58
%66 = load i64, i64* %32
%67 = icmp eq i64 %66, 0
br i1 %67, label %72, label %68
68: ; preds = %65
%69 = getelementptr inbounds %struct.fb_cmap, %struct.fb_cmap* %15, i64 0, i32 2
%70 = load i32*, i32** %69
%71 = tail call i32 @free(i32* %70)
br label %72
72: ; preds = %68, %65
%73 = tail call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0))
br label %108
74: ; preds = %53, %49
%75 = getelementptr inbounds %struct.fb_var_screeninfo, %struct.fb_var_screeninfo* %1, i64 0, i32 3, i32 0
%76 = load i64, i64* %75
%77 = icmp eq i64 %76, 0
br i1 %77, label %106, label %78
78: ; preds = %74
%79 = tail call i64 @malloc(i32 1024)
%80 = inttoptr i64 %79 to i32*
%81 = getelementptr inbounds %struct.fb_cmap, %struct.fb_cmap* %15, i64 0, i32 4
store i32* %80, i32** %81
%82 = icmp eq i64 %79, 0
br i1 %82, label %83, label %106
83: ; preds = %78
%84 = load i64, i64* %21
%85 = icmp eq i64 %84, 0
br i1 %85, label %90, label %86
86: ; preds = %83
%87 = getelementptr inbounds %struct.fb_cmap, %struct.fb_cmap* %15, i64 0, i32 3
%88 = load i32*, i32** %87
%89 = tail call i32 @free(i32* %88)
br label %90
90: ; preds = %86, %83
%91 = load i64, i64* %32
%92 = icmp eq i64 %91, 0
br i1 %92, label %97, label %93
93: ; preds = %90
%94 = getelementptr inbounds %struct.fb_cmap, %struct.fb_cmap* %15, i64 0, i32 2
%95 = load i32*, i32** %94
%96 = tail call i32 @free(i32* %95)
br label %97
97: ; preds = %93, %90
%98 = load i64, i64* %50
%99 = icmp eq i64 %98, 0
br i1 %99, label %104, label %100
100: ; preds = %97
%101 = getelementptr inbounds %struct.fb_cmap, %struct.fb_cmap* %15, i64 0, i32 1
%102 = load i32*, i32** %101
%103 = tail call i32 @free(i32* %102)
br label %104
104: ; preds = %100, %97
%105 = tail call i32 @perror(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0))
br label %108
106: ; preds = %78, %74
%107 = getelementptr inbounds %struct.fb_cmap, %struct.fb_cmap* %15, i64 0, i32 0
store i32 256, i32* %107
br label %108
108: ; preds = %2, %106, %104, %72, %47, %29, %17
%109 = phi %struct.fb_cmap* [ %15, %106 ], [ inttoptr (i64 -1 to %struct.fb_cmap*), %104 ], [ inttoptr (i64 -1 to %struct.fb_cmap*), %72 ], [ inttoptr (i64 -1 to %struct.fb_cmap*), %47 ], [ inttoptr (i64 -1 to %struct.fb_cmap*), %29 ], [ inttoptr (i64 -1 to %struct.fb_cmap*), %17 ], [ null, %2 ]
ret %struct.fb_cmap* %109
}