#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 *version;
  unsigned int flags;
  int /*<<< orphan*/ name;
};

/* Variables and functions */
int /*<<< orphan*/ memset(struct dm_ioctl *, int /*<<< orphan*/, size_t);
int /*<<< orphan*/ strncpy(int /*<<< orphan*/, char const *, int);
void ioctl_init(struct dm_ioctl *io, size_t dataSize, const char *name,
                unsigned flags) {
  memset(io, 0, dataSize);
  io->data_size = dataSize;
  io->data_start = sizeof(struct dm_ioctl);
  io->version[0] = 4;
  io->version[1] = 0;
  io->version[2] = 0;
  io->flags = flags;
  if (name) {
    strncpy(io->name, name, sizeof(io->name));
  }
}


x86 assembly (clang, -O0):
<ioctl_init>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rdx
xor    %esi,%esi
call   1040 <memset@plt>
mov    -0x10(%rbp),%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x8(%rbp),%rax
movl   $0x20,0x8(%rax)
mov    -0x8(%rbp),%rax
mov    0x10(%rax),%rax
movl   $0x4,(%rax)
mov    -0x8(%rbp),%rax
mov    0x10(%rax),%rax
movl   $0x0,0x4(%rax)
mov    -0x8(%rbp),%rax
mov    0x10(%rax),%rax
movl   $0x0,0x8(%rax)
mov    -0x1c(%rbp),%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,0x18(%rax)
cmpq   $0x0,-0x18(%rbp)
je     11b2 <ioctl_init+0x92>
mov    -0x8(%rbp),%rax
mov    0x1c(%rax),%edi
mov    -0x18(%rbp),%rsi
mov    $0x4,%edx
call   1030 <strncpy@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ioctl_init>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %ecx,%r15d
mov    %rdx,%r14
mov    %rsi,%rbp
mov    %rdi,%rbx
xor    %esi,%esi
mov    %rbp,%rdx
call   1040 <memset@plt>
mov    %rbp,(%rbx)
movl   $0x20,0x8(%rbx)
mov    0x10(%rbx),%rax
movq   $0x4,(%rax)
movl   $0x0,0x8(%rax)
mov    %r15d,0x18(%rbx)
test   %r14,%r14
je     117c <ioctl_init+0x5c>
mov    0x1c(%rbx),%edi
mov    %r14,%rsi
mov    $0x4,%edx
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <strncpy@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.dm_ioctl = type { i64, i32, i32*, i32, i32 }
define void @ioctl_init(%struct.dm_ioctl* %0, i64 %1, i8* %2, i32 %3) {
%5 = alloca %struct.dm_ioctl*
%6 = alloca i64
%7 = alloca i8*
%8 = alloca i32
store %struct.dm_ioctl* %0, %struct.dm_ioctl** %5
store i64 %1, i64* %6
store i8* %2, i8** %7
store i32 %3, i32* %8
%9 = load %struct.dm_ioctl*, %struct.dm_ioctl** %5
%10 = load i64, i64* %6
%11 = call i32 @memset(%struct.dm_ioctl* %9, i32 0, i64 %10)
%12 = load i64, i64* %6
%13 = load %struct.dm_ioctl*, %struct.dm_ioctl** %5
%14 = getelementptr inbounds %struct.dm_ioctl, %struct.dm_ioctl* %13, i32 0, i32 0
store i64 %12, i64* %14
%15 = load %struct.dm_ioctl*, %struct.dm_ioctl** %5
%16 = getelementptr inbounds %struct.dm_ioctl, %struct.dm_ioctl* %15, i32 0, i32 1
store i32 32, i32* %16
%17 = load %struct.dm_ioctl*, %struct.dm_ioctl** %5
%18 = getelementptr inbounds %struct.dm_ioctl, %struct.dm_ioctl* %17, i32 0, i32 2
%19 = load i32*, i32** %18
%20 = getelementptr inbounds i32, i32* %19, i64 0
store i32 4, i32* %20
%21 = load %struct.dm_ioctl*, %struct.dm_ioctl** %5
%22 = getelementptr inbounds %struct.dm_ioctl, %struct.dm_ioctl* %21, i32 0, i32 2
%23 = load i32*, i32** %22
%24 = getelementptr inbounds i32, i32* %23, i64 1
store i32 0, i32* %24
%25 = load %struct.dm_ioctl*, %struct.dm_ioctl** %5
%26 = getelementptr inbounds %struct.dm_ioctl, %struct.dm_ioctl* %25, i32 0, i32 2
%27 = load i32*, i32** %26
%28 = getelementptr inbounds i32, i32* %27, i64 2
store i32 0, i32* %28
%29 = load i32, i32* %8
%30 = load %struct.dm_ioctl*, %struct.dm_ioctl** %5
%31 = getelementptr inbounds %struct.dm_ioctl, %struct.dm_ioctl* %30, i32 0, i32 3
store i32 %29, i32* %31
%32 = load i8*, i8** %7
%33 = icmp ne i8* %32, null
br i1 %33, label %34, label %40
34: ; preds = %4
%35 = load %struct.dm_ioctl*, %struct.dm_ioctl** %5
%36 = getelementptr inbounds %struct.dm_ioctl, %struct.dm_ioctl* %35, i32 0, i32 4
%37 = load i32, i32* %36
%38 = load i8*, i8** %7
%39 = call i32 @strncpy(i32 %37, i8* %38, i32 4)
br label %40
40: ; preds = %34, %4
ret void
}

LLVM IR (-O2):
%struct.dm_ioctl = type { i64, i32, i32*, i32, i32 }
define void @ioctl_init(%struct.dm_ioctl* %0, i64 %1, i8* %2, i32 %3) {
%5 = tail call i32 @memset(%struct.dm_ioctl* %0, i32 0, i64 %1)
%6 = getelementptr inbounds %struct.dm_ioctl, %struct.dm_ioctl* %0, i64 0, i32 0
store i64 %1, i64* %6
%7 = getelementptr inbounds %struct.dm_ioctl, %struct.dm_ioctl* %0, i64 0, i32 1
store i32 32, i32* %7
%8 = getelementptr inbounds %struct.dm_ioctl, %struct.dm_ioctl* %0, i64 0, i32 2
%9 = load i32*, i32** %8
store i32 4, i32* %9
%10 = getelementptr inbounds i32, i32* %9, i64 1
store i32 0, i32* %10
%11 = getelementptr inbounds i32, i32* %9, i64 2
store i32 0, i32* %11
%12 = getelementptr inbounds %struct.dm_ioctl, %struct.dm_ioctl* %0, i64 0, i32 3
store i32 %3, i32* %12
%13 = icmp eq i8* %2, null
br i1 %13, label %18, label %14
14: ; preds = %4
%15 = getelementptr inbounds %struct.dm_ioctl, %struct.dm_ioctl* %0, i64 0, i32 4
%16 = load i32, i32* %15
%17 = tail call i32 @strncpy(i32 %16, i8* %2, i32 4)
br label %18
18: ; preds = %14, %4
ret void
}