#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 start;
  int length;
  scalar_t__ *volname;
  scalar_t__ *devname;
  int /*<<< orphan*/ pno;
};
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 /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ atoi(char *);
scalar_t__ atol(char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int ioctl(int, int /*<<< orphan*/, struct blkpg_ioctl_arg *);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  int fd;
  struct blkpg_ioctl_arg a;
  struct blkpg_partition p;
  if (argc != 5) {
    fprintf(stderr, "usage: %s diskdevice partitionnr start length\n", argv[0]);
    exit(1);
  }
  if ((fd = open(argv[1], O_RDONLY)) < 0) {
    perror(argv[1]);
    exit(1);
  }
  p.pno = atoi(argv[2]);
  p.start = 512 * ((long long)atol(argv[3]));
  p.length = 512 * ((long long)atol(argv[4]));
  p.devname[0] = 0;
  p.volname[0] = 0;
  a.op = BLKPG_ADD_PARTITION;
  a.flags = 0;
  a.datalen = sizeof(p);
  a.data = &p;
  if (ioctl(fd, BLKPG, &a) == -1) {
    perror("BLKPG");
    exit(1);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x5,-0x8(%rbp)
je     11b6 <main+0x46>
mov    0x2e39(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe59(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e23(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    11ef <main+0x7f>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1080 <atoi@plt>
mov    %eax,-0x40(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   1050 <atol@plt>
shl    $0x9,%rax
mov    %eax,-0x58(%rbp)
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rdi
call   1050 <atol@plt>
shl    $0x9,%rax
mov    %eax,-0x54(%rbp)
mov    -0x48(%rbp),%rax
movq   $0x0,(%rax)
mov    -0x50(%rbp),%rax
movq   $0x0,(%rax)
mov    0x2d84(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
movl   $0x20,-0x38(%rbp)
lea    -0x58(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x14(%rbp),%edi
mov    0x2d6e(%rip),%rax
mov    (%rax),%esi
lea    -0x38(%rbp),%rdx
call   1030 <ioctl@plt>
cmp    $0xffffffff,%eax
jne    1294 <main+0x124>
lea    0xdaa(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    %rsi,%rbx
cmp    $0x5,%edi
jne    116e <main+0x2e>
mov    0x8(%rbx),%rdi
mov    0x2e94(%rip),%rax
mov    (%rax),%esi
call   1040 <open@plt>
mov    0x8(%rbx),%rdi
call   1050 <perror@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    0x2e63(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xe7f(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
%struct.blkpg_ioctl_arg = type { i32, %struct.blkpg_partition*, i64, i32 }
%struct.blkpg_partition = type { i32, i32, i64*, i64*, i32 }
@stderr = global i32 0
@.str = [47 x i8] c"usage: %s diskdevice partitionnr start length\0A\00"
@O_RDONLY = global i32 0
@BLKPG_ADD_PARTITION = global i32 0
@BLKPG = global i32 0
@.str.1 = [6 x i8] c"BLKPG\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca %struct.blkpg_ioctl_arg
%8 = alloca %struct.blkpg_partition
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp ne i32 %9, 5
br i1 %10, label %11, label %18
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 0
%15 = load i8*, i8** %14
%16 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0), i8* %15)
%17 = call i32 @exit(i32 1)
unreachable
18: ; preds = %2
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 1
%21 = load i8*, i8** %20
%22 = load i32, i32* @O_RDONLY
%23 = call i32 @open(i8* %21, i32 %22)
store i32 %23, i32* %6
%24 = icmp slt i32 %23, 0
br i1 %24, label %25, label %31
25: ; preds = %18
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 1
%28 = load i8*, i8** %27
%29 = call i32 @perror(i8* %28)
%30 = call i32 @exit(i32 1)
unreachable
31: ; preds = %18
%32 = load i8**, i8*** %5
%33 = getelementptr inbounds i8*, i8** %32, i64 2
%34 = load i8*, i8** %33
%35 = call i32 @atoi(i8* %34)
%36 = getelementptr inbounds %struct.blkpg_partition, %struct.blkpg_partition* %8, i32 0, i32 4
store i32 %35, i32* %36
%37 = load i8**, i8*** %5
%38 = getelementptr inbounds i8*, i8** %37, i64 3
%39 = load i8*, i8** %38
%40 = call i64 @atol(i8* %39)
%41 = mul nsw i64 512, %40
%42 = trunc i64 %41 to i32
%43 = getelementptr inbounds %struct.blkpg_partition, %struct.blkpg_partition* %8, i32 0, i32 0
store i32 %42, i32* %43
%44 = load i8**, i8*** %5
%45 = getelementptr inbounds i8*, i8** %44, i64 4
%46 = load i8*, i8** %45
%47 = call i64 @atol(i8* %46)
%48 = mul nsw i64 512, %47
%49 = trunc i64 %48 to i32
%50 = getelementptr inbounds %struct.blkpg_partition, %struct.blkpg_partition* %8, i32 0, i32 1
store i32 %49, i32* %50
%51 = getelementptr inbounds %struct.blkpg_partition, %struct.blkpg_partition* %8, i32 0, i32 3
%52 = load i64*, i64** %51
%53 = getelementptr inbounds i64, i64* %52, i64 0
store i64 0, i64* %53
%54 = getelementptr inbounds %struct.blkpg_partition, %struct.blkpg_partition* %8, i32 0, i32 2
%55 = load i64*, i64** %54
%56 = getelementptr inbounds i64, i64* %55, i64 0
store i64 0, i64* %56
%57 = load i32, i32* @BLKPG_ADD_PARTITION
%58 = getelementptr inbounds %struct.blkpg_ioctl_arg, %struct.blkpg_ioctl_arg* %7, i32 0, i32 3
store i32 %57, i32* %58
%59 = getelementptr inbounds %struct.blkpg_ioctl_arg, %struct.blkpg_ioctl_arg* %7, i32 0, i32 2
store i64 0, i64* %59
%60 = getelementptr inbounds %struct.blkpg_ioctl_arg, %struct.blkpg_ioctl_arg* %7, i32 0, i32 0
store i32 32, i32* %60
%61 = getelementptr inbounds %struct.blkpg_ioctl_arg, %struct.blkpg_ioctl_arg* %7, i32 0, i32 1
store %struct.blkpg_partition* %8, %struct.blkpg_partition** %61
%62 = load i32, i32* %6
%63 = load i32, i32* @BLKPG
%64 = call i32 @ioctl(i32 %62, i32 %63, %struct.blkpg_ioctl_arg* %7)
%65 = icmp eq i32 %64, -1
br i1 %65, label %66, label %69
66: ; preds = %31
%67 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%68 = call i32 @exit(i32 1)
unreachable
69: ; preds = %31
ret i32 0
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [47 x i8] c"usage: %s diskdevice partitionnr start length\0A\00"
@O_RDONLY = global i32 0
@BLKPG_ADD_PARTITION = global i32 0
@BLKPG = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 5
br i1 %3, label %9, label %4
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = load i8*, i8** %1
%7 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0), i8* %6)
%8 = tail call i32 @exit(i32 1)
unreachable
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = load i32, i32* @O_RDONLY
%13 = tail call i32 @open(i8* %11, i32 %12)
%14 = icmp slt i32 %13, 0
%15 = load i8*, i8** %10
%16 = tail call i32 @perror(i8* %15)
%17 = tail call i32 @exit(i32 1)
unreachable
}