#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 /*<<< orphan*/ bitmap_bit_order;
  int /*<<< orphan*/ byte_order;
};
typedef TYPE_1__ XImage;
typedef int /*<<< orphan*/ Display;

/* Variables and functions */
int /*<<< orphan*/ DefaultScreen(int /*<<< orphan*/ *);
int /*<<< orphan*/ DefaultVisual(int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ MSBFirst;
TYPE_1__ *XCreateImage(int /*<<< orphan*/ *, int /*<<< orphan*/, int,
                       int /*<<< orphan*/, int /*<<< orphan*/, char *, int, int,
                       int, int /*<<< orphan*/);
int /*<<< orphan*/ XYBitmap;
scalar_t__ calloc(unsigned int, int);
XImage *MakeXImage(Display *dpy, int w, int h) {
  XImage *I;
  char *data;
  data = (char *)calloc((unsigned)(((w - 1) / 8 + 1) * h), 1);
  if (data == NULL)
    return NULL;
  I = XCreateImage(dpy, DefaultVisual(dpy, DefaultScreen(dpy)), 1, XYBitmap, 0,
                   data, w, h, 8, 0);
  if (I == NULL)
    return NULL;
  I->byte_order = I->bitmap_bit_order = MSBFirst;
  return I;
}


x86 assembly (clang, -O0):
<MakeXImage>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    -0x14(%rbp),%eax
sub    $0x1,%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
mov    %eax,%edi
add    $0x1,%edi
imul   -0x18(%rbp),%edi
mov    $0x1,%esi
call   1030 <calloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    118f <MakeXImage+0x4f>
movq   $0x0,-0x8(%rbp)
jmp    122c <MakeXImage+0xec>
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <DefaultScreen@plt>
mov    -0x38(%rbp),%rdi
mov    %eax,%esi
call   1060 <DefaultVisual@plt>
mov    -0x30(%rbp),%rdi
mov    %eax,%esi
mov    0x2e18(%rip),%rax
mov    (%rax),%ecx
mov    -0x28(%rbp),%r9
mov    -0x14(%rbp),%r10d
mov    -0x18(%rbp),%eax
mov    $0x1,%edx
xor    %r8d,%r8d
mov    %r10d,(%rsp)
mov    %eax,0x8(%rsp)
movl   $0x8,0x10(%rsp)
movl   $0x0,0x18(%rsp)
call   1050 <XCreateImage@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    120e <MakeXImage+0xce>
movq   $0x0,-0x8(%rbp)
jmp    122c <MakeXImage+0xec>
mov    0x2dd3(%rip),%rax
mov    (%rax),%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x20(%rbp),%rax
mov    %ecx,0x4(%rax)
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<MakeXImage>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %esi,%r15d
lea    -0x1(%r15),%ecx
lea    0x6(%r15),%eax
test   %ecx,%ecx
cmovns %ecx,%eax
mov    %edx,%r14d
mov    %rdi,%r13
sar    $0x3,%eax
add    $0x1,%eax
imul   %edx,%eax
mov    %eax,%edi
mov    $0x1,%esi
call   1030 <calloc@plt>
test   %rax,%rax
je     11d3 <MakeXImage+0x93>
mov    %rax,%rbx
mov    %r13,%rdi
call   1040 <DefaultScreen@plt>
mov    %r13,%rdi
mov    %eax,%esi
call   1060 <DefaultVisual@plt>
mov    0x2e43(%rip),%rcx
mov    (%rcx),%ecx
xor    %r12d,%r12d
mov    %r13,%rdi
mov    %eax,%esi
mov    $0x1,%edx
xor    %r8d,%r8d
mov    %rbx,%r9
push   $0x0
push   $0x8
push   %r14
push   %r15
call   1050 <XCreateImage@plt>
add    $0x20,%rsp
test   %rax,%rax
je     11d6 <MakeXImage+0x96>
mov    0x2e21(%rip),%rcx
mov    (%rcx),%ecx
mov    %ecx,(%rax)
mov    %ecx,0x4(%rax)
mov    %rax,%r12
jmp    11d6 <MakeXImage+0x96>
xor    %r12d,%r12d
mov    %r12,%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.TYPE_4__ = type { i32, i32 }
@XYBitmap = global i32 0
@MSBFirst = global i32 0
define %struct.TYPE_4__* @MakeXImage(i32* %0, i32 %1, i32 %2) {
%4 = alloca %struct.TYPE_4__*
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
%8 = alloca %struct.TYPE_4__*
%9 = alloca i8*
store i32* %0, i32** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
%10 = load i32, i32* %6
%11 = sub nsw i32 %10, 1
%12 = sdiv i32 %11, 8
%13 = add nsw i32 %12, 1
%14 = load i32, i32* %7
%15 = mul nsw i32 %13, %14
%16 = call i64 @calloc(i32 %15, i32 1)
%17 = inttoptr i64 %16 to i8*
store i8* %17, i8** %9
%18 = load i8*, i8** %9
%19 = icmp eq i8* %18, null
br i1 %19, label %20, label %21
20: ; preds = %3
store %struct.TYPE_4__* null, %struct.TYPE_4__** %4
br label %42
21: ; preds = %3
%22 = load i32*, i32** %5
%23 = load i32*, i32** %5
%24 = load i32*, i32** %5
%25 = call i32 @DefaultScreen(i32* %24)
%26 = call i32 @DefaultVisual(i32* %23, i32 %25)
%27 = load i32, i32* @XYBitmap
%28 = load i8*, i8** %9
%29 = load i32, i32* %6
%30 = load i32, i32* %7
%31 = call %struct.TYPE_4__* @XCreateImage(i32* %22, i32 %26, i32 1, i32 %27, i32 0, i8* %28, i32 %29, i32 %30, i32 8, i32 0)
store %struct.TYPE_4__* %31, %struct.TYPE_4__** %8
%32 = load %struct.TYPE_4__*, %struct.TYPE_4__** %8
%33 = icmp eq %struct.TYPE_4__* %32, null
br i1 %33, label %34, label %35
34: ; preds = %21
store %struct.TYPE_4__* null, %struct.TYPE_4__** %4
br label %42
35: ; preds = %21
%36 = load i32, i32* @MSBFirst
%37 = load %struct.TYPE_4__*, %struct.TYPE_4__** %8
%38 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %37, i32 0, i32 0
store i32 %36, i32* %38
%39 = load %struct.TYPE_4__*, %struct.TYPE_4__** %8
%40 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %39, i32 0, i32 1
store i32 %36, i32* %40
%41 = load %struct.TYPE_4__*, %struct.TYPE_4__** %8
store %struct.TYPE_4__* %41, %struct.TYPE_4__** %4
br label %42
42: ; preds = %35, %34, %20
%43 = load %struct.TYPE_4__*, %struct.TYPE_4__** %4
ret %struct.TYPE_4__* %43
}

LLVM IR (-O2):
%struct.TYPE_4__ = type { i32, i32 }
@XYBitmap = global i32 0
@MSBFirst = global i32 0
define %struct.TYPE_4__* @MakeXImage(i32* %0, i32 %1, i32 %2) {
%4 = add nsw i32 %1, -1
%5 = sdiv i32 %4, 8
%6 = add nsw i32 %5, 1
%7 = mul nsw i32 %6, %2
%8 = tail call i64 @calloc(i32 %7, i32 1)
%9 = icmp eq i64 %8, 0
br i1 %9, label %21, label %10
10: ; preds = %3
%11 = inttoptr i64 %8 to i8*
%12 = tail call i32 @DefaultScreen(i32* %0)
%13 = tail call i32 @DefaultVisual(i32* %0, i32 %12)
%14 = load i32, i32* @XYBitmap
%15 = tail call %struct.TYPE_4__* @XCreateImage(i32* %0, i32 %13, i32 1, i32 %14, i32 0, i8* %11, i32 %1, i32 %2, i32 8, i32 0)
%16 = icmp eq %struct.TYPE_4__* %15, null
br i1 %16, label %21, label %17
17: ; preds = %10
%18 = load i32, i32* @MSBFirst
%19 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %15, i64 0, i32 0
store i32 %18, i32* %19
%20 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %15, i64 0, i32 1
store i32 %18, i32* %20
br label %21
21: ; preds = %10, %3, %17
%22 = phi %struct.TYPE_4__* [ %15, %17 ], [ null, %3 ], [ null, %10 ]
ret %struct.TYPE_4__* %22
}