#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 */
struct dm_ioctl {
  size_t data_size;
  int data_start;
  int /*<<< orphan*/ *version;
};

/* Variables and functions */
int /*<<< orphan*/ DM_VERSION_MAJOR;
int /*<<< orphan*/ DM_VERSION_MINOR;
int /*<<< orphan*/ DM_VERSION_PATCHLEVEL;
struct dm_ioctl *zalloc(size_t);
struct dm_ioctl *alloc_ctl(size_t payload_size) {
  size_t len = sizeof(struct dm_ioctl) + payload_size;
  struct dm_ioctl *ctl = zalloc(len);
  if (ctl) {
    ctl->version[0] = DM_VERSION_MAJOR;
    ctl->version[1] = DM_VERSION_MINOR;
    ctl->version[2] = DM_VERSION_PATCHLEVEL;
    ctl->data_size = len;
    ctl->data_start = sizeof(*ctl);
  }
  return ctl;
}


x86 assembly (clang, -O0):
<alloc_ctl>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x18,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <zalloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1191 <alloc_ctl+0x81>
mov    0x2e91(%rip),%rax
mov    (%rax),%ecx
mov    -0x18(%rbp),%rax
mov    0x10(%rax),%rax
mov    %ecx,(%rax)
mov    0x2e76(%rip),%rax
mov    (%rax),%ecx
mov    -0x18(%rbp),%rax
mov    0x10(%rax),%rax
mov    %ecx,0x4(%rax)
mov    0x2e7a(%rip),%rax
mov    (%rax),%ecx
mov    -0x18(%rbp),%rax
mov    0x10(%rax),%rax
mov    %ecx,0x8(%rax)
mov    -0x10(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rax
movl   $0x18,0x8(%rax)
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<alloc_ctl>:
push   %rbx
mov    %rdi,%rbx
add    $0x18,%rbx
mov    %rbx,%rdi
call   1030 <zalloc@plt>
test   %rax,%rax
je     1156 <alloc_ctl+0x46>
mov    0x2eac(%rip),%rcx
mov    (%rcx),%ecx
mov    0x10(%rax),%rdx
mov    %ecx,(%rdx)
mov    0x2e95(%rip),%rcx
mov    (%rcx),%ecx
mov    %ecx,0x4(%rdx)
mov    0x2ea1(%rip),%rcx
mov    (%rcx),%ecx
mov    %ecx,0x8(%rdx)
mov    %rbx,(%rax)
movl   $0x18,0x8(%rax)
pop    %rbx
ret

LLVM IR (-O0):
%struct.dm_ioctl = type { i64, i32, i32* }
@DM_VERSION_MAJOR = global i32 0
@DM_VERSION_MINOR = global i32 0
@DM_VERSION_PATCHLEVEL = global i32 0
define %struct.dm_ioctl* @alloc_ctl(i64 %0) {
%2 = alloca i64
%3 = alloca i64
%4 = alloca %struct.dm_ioctl*
store i64 %0, i64* %2
%5 = load i64, i64* %2
%6 = add i64 24, %5
store i64 %6, i64* %3
%7 = load i64, i64* %3
%8 = call %struct.dm_ioctl* @zalloc(i64 %7)
store %struct.dm_ioctl* %8, %struct.dm_ioctl** %4
%9 = load %struct.dm_ioctl*, %struct.dm_ioctl** %4
%10 = icmp ne %struct.dm_ioctl* %9, null
br i1 %10, label %11, label %32
11: ; preds = %1
%12 = load i32, i32* @DM_VERSION_MAJOR
%13 = load %struct.dm_ioctl*, %struct.dm_ioctl** %4
%14 = getelementptr inbounds %struct.dm_ioctl, %struct.dm_ioctl* %13, i32 0, i32 2
%15 = load i32*, i32** %14
%16 = getelementptr inbounds i32, i32* %15, i64 0
store i32 %12, i32* %16
%17 = load i32, i32* @DM_VERSION_MINOR
%18 = load %struct.dm_ioctl*, %struct.dm_ioctl** %4
%19 = getelementptr inbounds %struct.dm_ioctl, %struct.dm_ioctl* %18, i32 0, i32 2
%20 = load i32*, i32** %19
%21 = getelementptr inbounds i32, i32* %20, i64 1
store i32 %17, i32* %21
%22 = load i32, i32* @DM_VERSION_PATCHLEVEL
%23 = load %struct.dm_ioctl*, %struct.dm_ioctl** %4
%24 = getelementptr inbounds %struct.dm_ioctl, %struct.dm_ioctl* %23, i32 0, i32 2
%25 = load i32*, i32** %24
%26 = getelementptr inbounds i32, i32* %25, i64 2
store i32 %22, i32* %26
%27 = load i64, i64* %3
%28 = load %struct.dm_ioctl*, %struct.dm_ioctl** %4
%29 = getelementptr inbounds %struct.dm_ioctl, %struct.dm_ioctl* %28, i32 0, i32 0
store i64 %27, i64* %29
%30 = load %struct.dm_ioctl*, %struct.dm_ioctl** %4
%31 = getelementptr inbounds %struct.dm_ioctl, %struct.dm_ioctl* %30, i32 0, i32 1
store i32 24, i32* %31
br label %32
32: ; preds = %11, %1
%33 = load %struct.dm_ioctl*, %struct.dm_ioctl** %4
ret %struct.dm_ioctl* %33
}

LLVM IR (-O2):
%struct.dm_ioctl = type { i64, i32, i32* }
@DM_VERSION_MAJOR = global i32 0
@DM_VERSION_MINOR = global i32 0
@DM_VERSION_PATCHLEVEL = global i32 0
define %struct.dm_ioctl* @alloc_ctl(i64 %0) {
%2 = add i64 %0, 24
%3 = tail call %struct.dm_ioctl* @zalloc(i64 %2)
%4 = icmp eq %struct.dm_ioctl* %3, null
br i1 %4, label %15, label %5
5: ; preds = %1
%6 = load i32, i32* @DM_VERSION_MAJOR
%7 = getelementptr inbounds %struct.dm_ioctl, %struct.dm_ioctl* %3, i64 0, i32 2
%8 = load i32*, i32** %7
store i32 %6, i32* %8
%9 = load i32, i32* @DM_VERSION_MINOR
%10 = getelementptr inbounds i32, i32* %8, i64 1
store i32 %9, i32* %10
%11 = load i32, i32* @DM_VERSION_PATCHLEVEL
%12 = getelementptr inbounds i32, i32* %8, i64 2
store i32 %11, i32* %12
%13 = getelementptr inbounds %struct.dm_ioctl, %struct.dm_ioctl* %3, i64 0, i32 0
store i64 %2, i64* %13
%14 = getelementptr inbounds %struct.dm_ioctl, %struct.dm_ioctl* %3, i64 0, i32 1
store i32 24, i32* %14
br label %15
15: ; preds = %5, %1
ret %struct.dm_ioctl* %3
}