#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 blkpg_partition {
  int pno;
  unsigned long start;
  unsigned long length;
  scalar_t__ *volname;
  scalar_t__ *devname;
};
struct blkpg_ioctl_arg {
  int datalen;
  struct blkpg_partition *data;
  scalar_t__ flags;
  int /*<<< orphan*/ op;
};
typedef int /*<<< orphan*/ p;

/* Variables and functions */
int /*<<< orphan*/ BLKPG;
int /*<<< orphan*/ BLKPG_ADD_PARTITION;
int ioctl(int, int /*<<< orphan*/, struct blkpg_ioctl_arg *);
int partx_add_partition(int fd, int partno, unsigned long start,
                        unsigned long size) {
  struct blkpg_ioctl_arg a;
  struct blkpg_partition p;
  p.pno = partno;
  p.start = start << 9;
  p.length = size << 9;
  p.devname[0] = 0;
  p.volname[0] = 0;
  a.op = BLKPG_ADD_PARTITION;
  a.flags = 0;
  a.datalen = sizeof(p);
  a.data = &p;
  return ioctl(fd, BLKPG, &a);
}


x86 assembly (clang, -O0):
<partx_add_partition>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x60(%rbp)
mov    -0x10(%rbp),%rax
shl    $0x9,%rax
mov    %rax,-0x58(%rbp)
mov    -0x18(%rbp),%rax
shl    $0x9,%rax
mov    %rax,-0x50(%rbp)
mov    -0x40(%rbp),%rax
movq   $0x0,(%rax)
mov    -0x48(%rbp),%rax
movq   $0x0,(%rax)
mov    0x2e77(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
movl   $0x28,-0x38(%rbp)
lea    -0x60(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e59(%rip),%rax
mov    (%rax),%esi
lea    -0x38(%rbp),%rdx
call   1030 <ioctl@plt>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
LLVM IR (-O0):
%struct.blkpg_ioctl_arg = type { i32, %struct.blkpg_partition*, i64, i32 }
%struct.blkpg_partition = type { i32, i64, i64, i64*, i64* }
@BLKPG_ADD_PARTITION = global i32 0
@BLKPG = global i32 0
define i32 @partx_add_partition(i32 %0, i32 %1, i64 %2, i64 %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i64
%8 = alloca i64
%9 = alloca %struct.blkpg_ioctl_arg
%10 = alloca %struct.blkpg_partition
store i32 %0, i32* %5
store i32 %1, i32* %6
store i64 %2, i64* %7
store i64 %3, i64* %8
%11 = load i32, i32* %6
%12 = getelementptr inbounds %struct.blkpg_partition, %struct.blkpg_partition* %10, i32 0, i32 0
store i32 %11, i32* %12
%13 = load i64, i64* %7
%14 = shl i64 %13, 9
%15 = getelementptr inbounds %struct.blkpg_partition, %struct.blkpg_partition* %10, i32 0, i32 1
store i64 %14, i64* %15
%16 = load i64, i64* %8
%17 = shl i64 %16, 9
%18 = getelementptr inbounds %struct.blkpg_partition, %struct.blkpg_partition* %10, i32 0, i32 2
store i64 %17, i64* %18
%19 = getelementptr inbounds %struct.blkpg_partition, %struct.blkpg_partition* %10, i32 0, i32 4
%20 = load i64*, i64** %19
%21 = getelementptr inbounds i64, i64* %20, i64 0
store i64 0, i64* %21
%22 = getelementptr inbounds %struct.blkpg_partition, %struct.blkpg_partition* %10, i32 0, i32 3
%23 = load i64*, i64** %22
%24 = getelementptr inbounds i64, i64* %23, i64 0
store i64 0, i64* %24
%25 = load i32, i32* @BLKPG_ADD_PARTITION
%26 = getelementptr inbounds %struct.blkpg_ioctl_arg, %struct.blkpg_ioctl_arg* %9, i32 0, i32 3
store i32 %25, i32* %26
%27 = getelementptr inbounds %struct.blkpg_ioctl_arg, %struct.blkpg_ioctl_arg* %9, i32 0, i32 2
store i64 0, i64* %27
%28 = getelementptr inbounds %struct.blkpg_ioctl_arg, %struct.blkpg_ioctl_arg* %9, i32 0, i32 0
store i32 40, i32* %28
%29 = getelementptr inbounds %struct.blkpg_ioctl_arg, %struct.blkpg_ioctl_arg* %9, i32 0, i32 1
store %struct.blkpg_partition* %10, %struct.blkpg_partition** %29
%30 = load i32, i32* %5
%31 = load i32, i32* @BLKPG
%32 = call i32 @ioctl(i32 %30, i32 %31, %struct.blkpg_ioctl_arg* %9)
ret i32 %32
}

LLVM IR (-O2):