#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 */

/* Variables and functions */
long find_array(char *, int, char *, long, long);
scalar_t__ lvm_find_part(long);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ pv_uuid_print(long, char *);
scalar_t__ vg_name_print(long, char *);
long vg_name_to_uuid(long, char *);
scalar_t__ vg_uuid_print(long, char *);
long int labelone_detect(char *buffer, long int buff_size, long int offset) {
  long int x, pv_uuid_loc, vg_name_loc, vg_uuid_loc;
  char label[8] = "LABELONE";
  x = find_array(label, 8, buffer, buff_size, offset);
  pv_uuid_loc = x + 32;
  vg_name_loc = x + 4096;
  vg_uuid_loc = vg_name_to_uuid(vg_name_loc, buffer);
  if (x >= 0) {
    printf("- LVM LABELONE found at byte %ld\n", x);
    if (pv_uuid_print(pv_uuid_loc, buffer))
      printf("disk_recover: pv_uuid_print failed");
    if (vg_name_print(vg_name_loc, buffer))
      printf("disk_recover: vg_name_print failed");
    if (vg_uuid_print(vg_uuid_loc, buffer))
      printf("disk_recover: vg_uuid_print failed");
    if (lvm_find_part(x))
      printf("disk_recover: lvm_find_part failed");
  }
  return x;
}


x86 assembly (clang, -O0):
<labelone_detect>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    0xe75(%rip),%rax
mov    %rax,-0x40(%rbp)
lea    -0x40(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    -0x10(%rbp),%rcx
mov    -0x18(%rbp),%r8
mov    $0x8,%esi
call   1090 <find_array@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
add    $0x20,%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
add    $0x1000,%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1030 <vg_name_to_uuid@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x20(%rbp)
jl     128a <labelone_detect+0x11a>
mov    -0x20(%rbp),%rsi
lea    0xe1a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x28(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1040 <pv_uuid_print@plt>
cmp    $0x0,%rax
je     121a <labelone_detect+0xaa>
lea    0xe17(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x30(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1070 <vg_name_print@plt>
cmp    $0x0,%rax
je     123f <labelone_detect+0xcf>
lea    0xe15(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x38(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1060 <vg_uuid_print@plt>
cmp    $0x0,%rax
je     1264 <labelone_detect+0xf4>
lea    0xe13(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1080 <lvm_find_part@plt>
cmp    $0x0,%rax
je     1285 <labelone_detect+0x115>
lea    0xe15(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    128a <labelone_detect+0x11a>
mov    -0x20(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<labelone_detect>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rdx,%r8
mov    %rsi,%rcx
mov    %rdi,%r13
movabs $0x454e4f4c4542414c,%rax
4f 4e 45
mov    %rax,0x8(%rsp)
lea    0x8(%rsp),%rdi
mov    $0x8,%esi
mov    %r13,%rdx
call   1090 <find_array@plt>
mov    %rax,%r14
lea    0x1000(%rax),%r12
mov    %r12,%rdi
mov    %r13,%rsi
call   1030 <vg_name_to_uuid@plt>
test   %r14,%r14
js     1255 <labelone_detect+0xe5>
mov    %rax,%r15
mov    %r14,%rbx
add    $0x20,%rbx
lea    0xe2a(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
mov    %r13,%rsi
call   1040 <pv_uuid_print@plt>
test   %rax,%rax
je     11fe <labelone_detect+0x8e>
lea    0xe2b(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r12,%rdi
mov    %r13,%rsi
call   1070 <vg_name_print@plt>
test   %rax,%rax
je     121c <labelone_detect+0xac>
lea    0xe30(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r15,%rdi
mov    %r13,%rsi
call   1060 <vg_uuid_print@plt>
test   %rax,%rax
je     123a <labelone_detect+0xca>
lea    0xe35(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r14,%rdi
call   1080 <lvm_find_part@plt>
test   %rax,%rax
je     1255 <labelone_detect+0xe5>
lea    0xe3d(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r14,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@__const.labelone_detect.label = [8 x i8] c"LABELONE"
@.str = [34 x i8] c"- LVM LABELONE found at byte %ld\0A\00"
@.str.1 = [35 x i8] c"disk_recover: pv_uuid_print failed\00"
@.str.2 = [35 x i8] c"disk_recover: vg_name_print failed\00"
@.str.3 = [35 x i8] c"disk_recover: vg_uuid_print failed\00"
@.str.4 = [35 x i8] c"disk_recover: lvm_find_part failed\00"
define i64 @labelone_detect(i8* %0, i64 %1, i64 %2) {
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i64
%7 = alloca i64
%8 = alloca i64
%9 = alloca i64
%10 = alloca i64
%11 = alloca [8 x i8]
store i8* %0, i8** %4
store i64 %1, i64* %5
store i64 %2, i64* %6
%12 = bitcast [8 x i8]* %11 to i8*
%13 = getelementptr inbounds [8 x i8], [8 x i8]* %11, i64 0, i64 0
%14 = load i8*, i8** %4
%15 = load i64, i64* %5
%16 = load i64, i64* %6
%17 = call i64 @find_array(i8* %13, i32 8, i8* %14, i64 %15, i64 %16)
store i64 %17, i64* %7
%18 = load i64, i64* %7
%19 = add nsw i64 %18, 32
store i64 %19, i64* %8
%20 = load i64, i64* %7
%21 = add nsw i64 %20, 4096
store i64 %21, i64* %9
%22 = load i64, i64* %9
%23 = load i8*, i8** %4
%24 = call i64 @vg_name_to_uuid(i64 %22, i8* %23)
store i64 %24, i64* %10
%25 = load i64, i64* %7
%26 = icmp sge i64 %25, 0
br i1 %26, label %27, label %57
27: ; preds = %3
%28 = load i64, i64* %7
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i64 %28)
%30 = load i64, i64* %8
%31 = load i8*, i8** %4
%32 = call i64 @pv_uuid_print(i64 %30, i8* %31)
%33 = icmp ne i64 %32, 0
br i1 %33, label %34, label %36
34: ; preds = %27
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0))
br label %36
36: ; preds = %34, %27
%37 = load i64, i64* %9
%38 = load i8*, i8** %4
%39 = call i64 @vg_name_print(i64 %37, i8* %38)
%40 = icmp ne i64 %39, 0
br i1 %40, label %41, label %43
41: ; preds = %36
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0))
br label %43
43: ; preds = %41, %36
%44 = load i64, i64* %10
%45 = load i8*, i8** %4
%46 = call i64 @vg_uuid_print(i64 %44, i8* %45)
%47 = icmp ne i64 %46, 0
br i1 %47, label %48, label %50
48: ; preds = %43
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.3, i64 0, i64 0))
br label %50
50: ; preds = %48, %43
%51 = load i64, i64* %7
%52 = call i64 @lvm_find_part(i64 %51)
%53 = icmp ne i64 %52, 0
br i1 %53, label %54, label %56
54: ; preds = %50
%55 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.4, i64 0, i64 0))
br label %56
56: ; preds = %54, %50
br label %57
57: ; preds = %56, %3
%58 = load i64, i64* %7
ret i64 %58
}

LLVM IR (-O2):
@.str = [34 x i8] c"- LVM LABELONE found at byte %ld\0A\00"
@.str.1 = [35 x i8] c"disk_recover: pv_uuid_print failed\00"
@.str.2 = [35 x i8] c"disk_recover: vg_name_print failed\00"
@.str.3 = [35 x i8] c"disk_recover: vg_uuid_print failed\00"
@.str.4 = [35 x i8] c"disk_recover: lvm_find_part failed\00"
define i64 @labelone_detect(i8* %0, i64 %1, i64 %2) {
%4 = alloca i64
%5 = bitcast i64* %4 to i8*
store i64 4994016225798537548, i64* %4
%6 = call i64 @find_array(i8* %5, i32 8, i8* %0, i64 %1, i64 %2)
%7 = add nsw i64 %6, 4096
%8 = call i64 @vg_name_to_uuid(i64 %7, i8* %0)
%9 = icmp sgt i64 %6, -1
br i1 %9, label %10, label %32
10: ; preds = %3
%11 = add nuw nsw i64 %6, 32
%12 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i64 %6)
%13 = call i64 @pv_uuid_print(i64 %11, i8* %0)
%14 = icmp eq i64 %13, 0
br i1 %14, label %17, label %15
15: ; preds = %10
%16 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0))
br label %17
17: ; preds = %15, %10
%18 = call i64 @vg_name_print(i64 %7, i8* %0)
%19 = icmp eq i64 %18, 0
br i1 %19, label %22, label %20
20: ; preds = %17
%21 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0))
br label %22
22: ; preds = %20, %17
%23 = call i64 @vg_uuid_print(i64 %8, i8* %0)
%24 = icmp eq i64 %23, 0
br i1 %24, label %27, label %25
25: ; preds = %22
%26 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.3, i64 0, i64 0))
br label %27
27: ; preds = %25, %22
%28 = call i64 @lvm_find_part(i64 %6)
%29 = icmp eq i64 %28, 0
br i1 %29, label %32, label %30
30: ; preds = %27
%31 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.4, i64 0, i64 0))
br label %32
32: ; preds = %27, %30, %3
ret i64 %6
}