#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 int /*<<< orphan*/ filename;

/* Variables and functions */
int PATH_MAX;
int lv_count();
char *lv_name(int);
int /*<<< orphan*/ mount_lv(char *);
int /*<<< orphan*/ read_kb_file_from(char *);
int /*<<< orphan*/ snprintf(char *, int, char *, char *);
scalar_t__ test_file(char *);
int /*<<< orphan*/ update_lv_lists();
void scan_boot_lvs(void) {
  char filename[PATH_MAX];
  update_lv_lists();
  for (int i = 0; i < lv_count(); ++i) {
    mount_lv(lv_name(i));
    snprintf(filename, sizeof(filename), "/mnt/%s/boot/boot.cfg", lv_name(i));
    if (test_file(filename))
      read_kb_file_from(lv_name(i));
  }
}


x86 assembly (clang, -O0):
<scan_boot_lvs>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    0x2e71(%rip),%rax
mov    (%rax),%eax
mov    %rax,-0x28(%rbp)
mov    %rsp,%rcx
mov    %rcx,-0x8(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x20(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x10(%rbp)
mov    $0x0,%al
call   1090 <update_lv_lists@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    $0x0,%al
call   1070 <lv_count@plt>
mov    %eax,%ecx
mov    -0x2c(%rbp),%eax
cmp    %ecx,%eax
jge    123b <scan_boot_lvs+0xcb>
mov    -0x14(%rbp),%edi
call   1030 <lv_name@plt>
mov    %rax,%rdi
call   1060 <mount_lv@plt>
mov    -0x28(%rbp),%rax
mov    %eax,-0x30(%rbp)
mov    -0x14(%rbp),%edi
call   1030 <lv_name@plt>
mov    -0x30(%rbp),%esi
mov    -0x20(%rbp),%rdi
mov    %rax,%rcx
lea    0xe00(%rip),%rdx
call   1040 <snprintf@plt>
mov    -0x20(%rbp),%rdi
call   1050 <test_file@plt>
cmp    $0x0,%rax
je     1228 <scan_boot_lvs+0xb8>
mov    -0x14(%rbp),%edi
call   1030 <lv_name@plt>
mov    %rax,%rdi
call   1080 <read_kb_file_from@plt>
jmp    122d <scan_boot_lvs+0xbd>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11b6 <scan_boot_lvs+0x46>
mov    -0x8(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<scan_boot_lvs>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    0x2e6e(%rip),%rax
mov    (%rax),%r14d
mov    %rsp,%r12
lea    0xf(%r14),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r12
mov    %r12,%rsp
xor    %eax,%eax
call   1090 <update_lv_lists@plt>
xor    %eax,%eax
call   1070 <lv_count@plt>
test   %eax,%eax
jle    1213 <scan_boot_lvs+0xa3>
lea    0xe51(%rip),%r15
xor    %ebx,%ebx
jmp    11ce <scan_boot_lvs+0x5e>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    $0x1,%ebx
xor    %eax,%eax
call   1070 <lv_count@plt>
cmp    %eax,%ebx
jge    1213 <scan_boot_lvs+0xa3>
mov    %ebx,%edi
call   1030 <lv_name@plt>
mov    %rax,%rdi
call   1060 <mount_lv@plt>
mov    %ebx,%edi
call   1030 <lv_name@plt>
mov    %r12,%rdi
mov    %r14d,%esi
mov    %r15,%rdx
mov    %rax,%rcx
call   1040 <snprintf@plt>
mov    %r12,%rdi
call   1050 <test_file@plt>
test   %rax,%rax
je     11c0 <scan_boot_lvs+0x50>
mov    %ebx,%edi
call   1030 <lv_name@plt>
mov    %rax,%rdi
call   1080 <read_kb_file_from@plt>
jmp    11c0 <scan_boot_lvs+0x50>
lea    -0x20(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@PATH_MAX = global i32 0
@.str = [22 x i8] c"/mnt/%s/boot/boot.cfg\00"
define void @scan_boot_lvs() {
%1 = alloca i8*
%2 = alloca i64
%3 = alloca i32
%4 = load i32, i32* @PATH_MAX
%5 = zext i32 %4 to i64
%6 = call i8* @llvm.stacksave()
store i8* %6, i8** %1
%7 = alloca i8, i64 %5
store i64 %5, i64* %2
%8 = call i32 (...) @update_lv_lists()
store i32 0, i32* %3
br label %9
9: ; preds = %28, %0
%10 = load i32, i32* %3
%11 = call i32 (...) @lv_count()
%12 = icmp slt i32 %10, %11
br i1 %12, label %13, label %31
13: ; preds = %9
%14 = load i32, i32* %3
%15 = call i8* @lv_name(i32 %14)
%16 = call i32 @mount_lv(i8* %15)
%17 = trunc i64 %5 to i32
%18 = load i32, i32* %3
%19 = call i8* @lv_name(i32 %18)
%20 = call i32 @snprintf(i8* %7, i32 %17, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %19)
%21 = call i64 @test_file(i8* %7)
%22 = icmp ne i64 %21, 0
br i1 %22, label %23, label %27
23: ; preds = %13
%24 = load i32, i32* %3
%25 = call i8* @lv_name(i32 %24)
%26 = call i32 @read_kb_file_from(i8* %25)
br label %27
27: ; preds = %23, %13
br label %28
28: ; preds = %27
%29 = load i32, i32* %3
%30 = add nsw i32 %29, 1
store i32 %30, i32* %3
br label %9
31: ; preds = %9
%32 = load i8*, i8** %1
ret void
}

LLVM IR (-O2):
@PATH_MAX = global i32 0
@.str = [22 x i8] c"/mnt/%s/boot/boot.cfg\00"
define void @scan_boot_lvs() {
%1 = load i32, i32* @PATH_MAX
%2 = zext i32 %1 to i64
%3 = alloca i8, i64 %2
%4 = tail call i32 (...) @update_lv_lists()
%5 = call i32 (...) @lv_count()
%6 = icmp sgt i32 %5, 0
br i1 %6, label %8, label %7
7: ; preds = %19, %0
ret void
8: ; preds = %0, %19
%9 = phi i32 [ %20, %19 ], [ 0, %0 ]
%10 = call i8* @lv_name(i32 %9)
%11 = call i32 @mount_lv(i8* %10)
%12 = call i8* @lv_name(i32 %9)
%13 = call i32 @snprintf(i8* %3, i32 %1, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %12)
%14 = call i64 @test_file(i8* %3)
%15 = icmp eq i64 %14, 0
br i1 %15, label %19, label %16
16: ; preds = %8
%17 = call i8* @lv_name(i32 %9)
%18 = call i32 @read_kb_file_from(i8* %17)
br label %19
19: ; preds = %8, %16
%20 = add nuw nsw i32 %9, 1
%21 = call i32 (...) @lv_count()
%22 = icmp slt i32 %20, %21
br i1 %22, label %8, label %7
}