#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 */
typedef unsigned long long __u64;

/* Variables and functions */
int EINVAL;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int get_dev_geometry(int, int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                     int /*<<< orphan*/ *, unsigned long long *,
                     int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
char *strdup(char const *);
int strlen(char *);
int abort_if_not_full_device(int fd, __u64 lba, const char *devname,
                             const char *msg) {
  __u64 start_lba;
  int i, err, shortened = 0;
  char *fdevname = strdup(devname);
  err = get_dev_geometry(fd, NULL, NULL, NULL, &start_lba, NULL);
  if (err)
    exit(err);
  for (i = strlen(fdevname);
       --i > 2 && (fdevname[i] >= '0' && fdevname[i] <= '9');) {
    fdevname[i] = '\0';
    shortened = 1;
  }
  if (!shortened)
    fdevname = strdup("the full disk");
  if (start_lba == 0ULL)
    return 0;
  if (msg) {
    fprintf(stderr, "%s\n", msg);
  } else {
    fprintf(stderr, "Device %s has non-zero LBA starting offset of %llu.\n",
            devname, start_lba);
    fprintf(stderr, "Please use an absolute LBA with the /dev/ entry for the "
                    "full device, rather than a partition name.\n");
    fprintf(stderr, "%s is probably a partition of %s (?)\n", devname,
            fdevname);
    fprintf(stderr, "The absolute LBA of sector %llu from %s should be %llu\n",
            lba, devname, start_lba + lba);
  }
  fprintf(stderr, "Aborting.\n");
  exit(EINVAL);
}


x86 assembly (clang, -O0):
<abort_if_not_full_device>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x18(%rbp),%rdi
call   1070 <strdup@plt>
mov    %rax,-0x40(%rbp)
mov    -0x4(%rbp),%edi
xor    %eax,%eax
mov    %eax,%r9d
lea    -0x28(%rbp),%r8
mov    %r9,%rsi
mov    %r9,%rdx
mov    %r9,%rcx
call   1050 <get_dev_geometry@plt>
mov    %eax,-0x30(%rbp)
cmpl   $0x0,-0x30(%rbp)
je     11aa <abort_if_not_full_device+0x5a>
mov    -0x30(%rbp),%edi
call   1060 <exit@plt>
mov    -0x40(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x2c(%rbp)
xor    %eax,%eax
cmp    $0x2,%ecx
mov    %al,-0x41(%rbp)
jle    1202 <abort_if_not_full_device+0xb2>
mov    -0x40(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsbl (%rax,%rcx,1),%ecx
xor    %eax,%eax
cmp    $0x30,%ecx
mov    %al,-0x42(%rbp)
jl     11fc <abort_if_not_full_device+0xac>
mov    -0x40(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x39,%eax
setle  %al
mov    %al,-0x42(%rbp)
mov    -0x42(%rbp),%al
mov    %al,-0x41(%rbp)
mov    -0x41(%rbp),%al
test   $0x1,%al
jne    1212 <abort_if_not_full_device+0xc2>
jmp    122a <abort_if_not_full_device+0xda>
mov    -0x40(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
movl   $0x1,-0x34(%rbp)
jmp    11b6 <abort_if_not_full_device+0x66>
cmpl   $0x0,-0x34(%rbp)
jne    1244 <abort_if_not_full_device+0xf4>
lea    0xdc5(%rip),%rdi
call   1070 <strdup@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1257 <abort_if_not_full_device+0x107>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret
cmpq   $0x0,-0x20(%rbp)
je     1282 <abort_if_not_full_device+0x132>
mov    0x2d77(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rdx
lea    0xd98(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
jmp    12fe <abort_if_not_full_device+0x1ae>
mov    0x2d57(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
mov    -0x28(%rbp),%rcx
lea    0xd78(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    0x2d38(%rip),%rax
mov    (%rax),%edi
lea    0xd96(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    0x2d21(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
mov    -0x40(%rbp),%rcx
lea    0xddb(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    0x2d02(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
mov    -0x28(%rbp),%r8
add    -0x10(%rbp),%r8
lea    0xdda(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    0x2cdb(%rip),%rax
mov    (%rax),%edi
lea    0xdfb(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    0x2cbc(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>

x86 assembly (clang, -O2):
<abort_if_not_full_device>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rcx,%r12
mov    %rdx,%r15
mov    %rsi,%r14
mov    %edi,%ebp
mov    %rdx,%rdi
call   1070 <strdup@plt>
mov    %rax,%rbx
lea    0x8(%rsp),%r8
mov    %ebp,%edi
xor    %esi,%esi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %r9d,%r9d
call   1050 <get_dev_geometry@plt>
test   %eax,%eax
jne    1201 <abort_if_not_full_device+0xb1>
mov    %rbx,%rdi
call   1030 <strlen@plt>
cmp    $0x4,%eax
jl     11d9 <abort_if_not_full_device+0x89>
lea    -0x1(%rax),%edx
mov    (%rbx,%rdx,1),%dil
add    $0xd0,%dil
cmp    $0x9,%dil
ja     11d9 <abort_if_not_full_device+0x89>
add    %rbx,%rdx
mov    %eax,%eax
xchg   %ax,%ax
movb   $0x0,(%rdx)
cmp    $0x4,%rax
jle    11e8 <abort_if_not_full_device+0x98>
lea    -0x1(%rax),%rsi
add    $0xfffffffe,%eax
lea    (%rbx,%rax,1),%rdx
movzbl (%rbx,%rax,1),%ecx
add    $0xd0,%cl
mov    %rsi,%rax
cmp    $0x9,%cl
jbe    11b0 <abort_if_not_full_device+0x60>
cmp    $0xa,%dil
jb     11e8 <abort_if_not_full_device+0x98>
lea    0xe20(%rip),%rdi
call   1070 <strdup@plt>
mov    %rax,%rbx
mov    0x8(%rsp),%rcx
test   %rcx,%rcx
jne    1208 <abort_if_not_full_device+0xb8>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %eax,%edi
call   1060 <exit@plt>
mov    0x2dd1(%rip),%rbp
mov    0x0(%rbp),%edi
test   %r12,%r12
jne    1271 <abort_if_not_full_device+0x121>
lea    0xdf4(%rip),%rsi
mov    %r15,%rdx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    0x0(%rbp),%edi
lea    0xe15(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    0x0(%rbp),%edi
lea    0xe68(%rip),%rsi
mov    %r15,%rdx
mov    %rbx,%rcx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    0x0(%rbp),%edi
mov    0x8(%rsp),%r8
add    %r14,%r8
lea    0xe6f(%rip),%rsi
mov    %r14,%rdx
mov    %r15,%rcx
xor    %eax,%eax
call   1040 <fprintf@plt>
jmp    1282 <abort_if_not_full_device+0x132>
lea    0xd96(%rip),%rsi
mov    %r12,%rdx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    0x0(%rbp),%edi
lea    0xe7d(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    0x2d3e(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [14 x i8] c"the full disk\00"
@stderr = global i32 0
@.str.1 = [4 x i8] c"%s\0A\00"
@.str.2 = [53 x i8] c"Device %s has non-zero LBA starting offset of %llu.\0A\00"
@.str.3 = [100 x i8] c"Please use an absolute LBA with the /dev/ entry for the full device, rather than a partition name.\0A\00"
@.str.4 = [38 x i8] c"%s is probably a partition of %s (?)\0A\00"
@.str.5 = [56 x i8] c"The absolute LBA of sector %llu from %s should be %llu\0A\00"
@.str.6 = [11 x i8] c"Aborting.\0A\00"
@EINVAL = global i32 0
define i32 @abort_if_not_full_device(i32 %0, i64 %1, i8* %2, i8* %3) {
%5 = alloca i32
%6 = alloca i64
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i8*
store i32 %0, i32* %5
store i64 %1, i64* %6
store i8* %2, i8** %7
store i8* %3, i8** %8
store i32 0, i32* %12
%14 = load i8*, i8** %7
%15 = call i8* @strdup(i8* %14)
store i8* %15, i8** %13
%16 = load i32, i32* %5
%17 = call i32 @get_dev_geometry(i32 %16, i32* null, i32* null, i32* null, i64* %9, i32* null)
store i32 %17, i32* %11
%18 = load i32, i32* %11
%19 = icmp ne i32 %18, 0
br i1 %19, label %20, label %23
20: ; preds = %4
%21 = load i32, i32* %11
%22 = call i32 @exit(i32 %21)
unreachable
23: ; preds = %4
%24 = load i8*, i8** %13
%25 = call i32 @strlen(i8* %24)
store i32 %25, i32* %10
br label %26
26: ; preds = %50, %23
%27 = load i32, i32* %10
%28 = add nsw i32 %27, -1
store i32 %28, i32* %10
%29 = icmp sgt i32 %28, 2
br i1 %29, label %30, label %48
30: ; preds = %26
%31 = load i8*, i8** %13
%32 = load i32, i32* %10
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8, i8* %31, i64 %33
%35 = load i8, i8* %34
%36 = sext i8 %35 to i32
%37 = icmp sge i32 %36, 48
br i1 %37, label %38, label %46
38: ; preds = %30
%39 = load i8*, i8** %13
%40 = load i32, i32* %10
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i8, i8* %39, i64 %41
%43 = load i8, i8* %42
%44 = sext i8 %43 to i32
%45 = icmp sle i32 %44, 57
br label %46
46: ; preds = %38, %30
%47 = phi i1 [ false, %30 ], [ %45, %38 ]
br label %48
48: ; preds = %46, %26
%49 = phi i1 [ false, %26 ], [ %47, %46 ]
br i1 %49, label %50, label %55
50: ; preds = %48
%51 = load i8*, i8** %13
%52 = load i32, i32* %10
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds i8, i8* %51, i64 %53
store i8 0, i8* %54
store i32 1, i32* %12
br label %26
55: ; preds = %48
%56 = load i32, i32* %12
%57 = icmp ne i32 %56, 0
br i1 %57, label %60, label %58
58: ; preds = %55
%59 = call i8* @strdup(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
store i8* %59, i8** %13
br label %60
60: ; preds = %58, %55
%61 = load i64, i64* %9
%62 = icmp eq i64 %61, 0
br i1 %62, label %63, label %64
63: ; preds = %60
ret i32 0
64: ; preds = %60
%65 = load i8*, i8** %8
%66 = icmp ne i8* %65, null
br i1 %66, label %67, label %71
67: ; preds = %64
%68 = load i32, i32* @stderr
%69 = load i8*, i8** %8
%70 = call i32 (i32, i8*, ...) @fprintf(i32 %68, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %69)
br label %89
71: ; preds = %64
%72 = load i32, i32* @stderr
%73 = load i8*, i8** %7
%74 = load i64, i64* %9
%75 = call i32 (i32, i8*, ...) @fprintf(i32 %72, i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.2, i64 0, i64 0), i8* %73, i64 %74)
%76 = load i32, i32* @stderr
%77 = call i32 (i32, i8*, ...) @fprintf(i32 %76, i8* getelementptr inbounds ([100 x i8], [100 x i8]* @.str.3, i64 0, i64 0))
%78 = load i32, i32* @stderr
%79 = load i8*, i8** %7
%80 = load i8*, i8** %13
%81 = call i32 (i32, i8*, ...) @fprintf(i32 %78, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.4, i64 0, i64 0), i8* %79, i8* %80)
%82 = load i32, i32* @stderr
%83 = load i64, i64* %6
%84 = load i8*, i8** %7
%85 = load i64, i64* %9
%86 = load i64, i64* %6
%87 = add i64 %85, %86
%88 = call i32 (i32, i8*, ...) @fprintf(i32 %82, i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.5, i64 0, i64 0), i64 %83, i8* %84, i64 %87)
br label %89
89: ; preds = %71, %67
%90 = load i32, i32* @stderr
%91 = call i32 (i32, i8*, ...) @fprintf(i32 %90, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0))
%92 = load i32, i32* @EINVAL
%93 = call i32 @exit(i32 %92)
unreachable
}

LLVM IR (-O2):
@.str = [14 x i8] c"the full disk\00"
@stderr = global i32 0
@.str.1 = [4 x i8] c"%s\0A\00"
@.str.2 = [53 x i8] c"Device %s has non-zero LBA starting offset of %llu.\0A\00"
@.str.3 = [100 x i8] c"Please use an absolute LBA with the /dev/ entry for the full device, rather than a partition name.\0A\00"
@.str.4 = [38 x i8] c"%s is probably a partition of %s (?)\0A\00"
@.str.5 = [56 x i8] c"The absolute LBA of sector %llu from %s should be %llu\0A\00"
@.str.6 = [11 x i8] c"Aborting.\0A\00"
@EINVAL = global i32 0
define i32 @abort_if_not_full_device(i32 %0, i64 %1, i8* %2, i8* %3) {
%5 = alloca i64
%6 = bitcast i64* %5 to i8*
%7 = tail call i8* @strdup(i8* %2)
%8 = call i32 @get_dev_geometry(i32 %0, i32* null, i32* null, i32* null, i64* %5, i32* null)
%9 = icmp eq i32 %8, 0
br i1 %9, label %12, label %10
10: ; preds = %4
%11 = call i32 @exit(i32 %8)
unreachable
12: ; preds = %4
%13 = call i32 @strlen(i8* %7)
%14 = icmp sgt i32 %13, 3
br i1 %14, label %15, label %38
15: ; preds = %12
%16 = add nsw i32 %13, -1
%17 = zext i32 %16 to i64
%18 = getelementptr inbounds i8, i8* %7, i64 %17
%19 = load i8, i8* %18
%20 = add i8 %19, -48
%21 = icmp ult i8 %20, 10
br i1 %21, label %22, label %38
22: ; preds = %15
%23 = zext i32 %13 to i64
br label %32
24: ; preds = %32
%25 = add nsw i64 %35, -1
%26 = add nsw i32 %34, -1
%27 = zext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %7, i64 %27
%29 = load i8, i8* %28
%30 = add i8 %29, -48
%31 = icmp ult i8 %30, 10
br i1 %31, label %32, label %37
32: ; preds = %22, %24
%33 = phi i8* [ %18, %22 ], [ %28, %24 ]
%34 = phi i32 [ %16, %22 ], [ %26, %24 ]
%35 = phi i64 [ %23, %22 ], [ %25, %24 ]
store i8 0, i8* %33
%36 = icmp sgt i64 %35, 4
br i1 %36, label %24, label %40
37: ; preds = %24
br i1 %21, label %40, label %38
38: ; preds = %15, %12, %37
%39 = call dereferenceable_or_null(14) i8* @strdup(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %40
40: ; preds = %32, %38, %37
%41 = phi i8* [ %7, %37 ], [ %39, %38 ], [ %7, %32 ]
%42 = load i64, i64* %5
%43 = icmp eq i64 %42, 0
br i1 %43, label %44, label %45
44: ; preds = %40
ret i32 0
45: ; preds = %40
%46 = icmp eq i8* %3, null
%47 = load i32, i32* @stderr
br i1 %46, label %50, label %48
48: ; preds = %45
%49 = call i32 (i32, i8*, ...) @fprintf(i32 %47, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %3)
br label %60
50: ; preds = %45
%51 = call i32 (i32, i8*, ...) @fprintf(i32 %47, i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.2, i64 0, i64 0), i8* %2, i64 %42)
%52 = load i32, i32* @stderr
%53 = call i32 (i32, i8*, ...) @fprintf(i32 %52, i8* getelementptr inbounds ([100 x i8], [100 x i8]* @.str.3, i64 0, i64 0))
%54 = load i32, i32* @stderr
%55 = call i32 (i32, i8*, ...) @fprintf(i32 %54, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.4, i64 0, i64 0), i8* %2, i8* %41)
%56 = load i32, i32* @stderr
%57 = load i64, i64* %5
%58 = add i64 %57, %1
%59 = call i32 (i32, i8*, ...) @fprintf(i32 %56, i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.5, i64 0, i64 0), i64 %1, i8* %2, i64 %58)
br label %60
60: ; preds = %50, %48
%61 = load i32, i32* @stderr
%62 = call i32 (i32, i8*, ...) @fprintf(i32 %61, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0))
%63 = load i32, i32* @EINVAL
%64 = call i32 @exit(i32 %63)
unreachable
}