#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 op;
  int datalen;
  struct blkpg_partition *data;
  scalar_t__ flags;
};
typedef int /*<<< orphan*/ p;

/* Variables and functions */
int /*<<< orphan*/ BLKPG;
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 = 1;
  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,-0x58(%rbp)
mov    -0x10(%rbp),%rax
shl    $0x9,%rax
mov    %rax,-0x50(%rbp)
mov    -0x18(%rbp),%rax
shl    $0x9,%rax
mov    %rax,-0x48(%rbp)
mov    -0x38(%rbp),%rax
movq   $0x0,(%rax)
mov    -0x40(%rbp),%rax
movq   $0x0,(%rax)
movl   $0x1,-0x30(%rbp)
movq   $0x0,-0x20(%rbp)
movl   $0x28,-0x2c(%rbp)
lea    -0x58(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e5e(%rip),%rax
mov    (%rax),%esi
lea    -0x30(%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, i32, %struct.blkpg_partition*, i64 }
%struct.blkpg_partition = type { i32, i64, i64, i64*, i64* }
@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 = getelementptr inbounds %struct.blkpg_ioctl_arg, %struct.blkpg_ioctl_arg* %9, i32 0, i32 0
store i32 1, i32* %25
%26 = getelementptr inbounds %struct.blkpg_ioctl_arg, %struct.blkpg_ioctl_arg* %9, i32 0, i32 3
store i64 0, i64* %26
%27 = getelementptr inbounds %struct.blkpg_ioctl_arg, %struct.blkpg_ioctl_arg* %9, i32 0, i32 1
store i32 40, i32* %27
%28 = getelementptr inbounds %struct.blkpg_ioctl_arg, %struct.blkpg_ioctl_arg* %9, i32 0, i32 2
store %struct.blkpg_partition* %10, %struct.blkpg_partition** %28
%29 = load i32, i32* %5
%30 = load i32, i32* @BLKPG
%31 = call i32 @ioctl(i32 %29, i32 %30, %struct.blkpg_ioctl_arg* %9)
ret i32 %31
}

LLVM IR (-O2):