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

/* Variables and functions */
int PATH_MAX;
char *get_lv_fstype(char const *);
int /*<<< orphan*/ is_lv_mounted(char *);
int /*<<< orphan*/ logprintf(char *, ...);
int /*<<< orphan*/ mount_lv(char *);
int /*<<< orphan*/ snprintf(char *, int, char *, char const *);
int /*<<< orphan*/ strcmp(char const *, char *);
int /*<<< orphan*/ system_logged(char *);
int /*<<< orphan*/ umount_lv(char const *);
void wipe_lv(const char *lv) {
  char cmd[PATH_MAX], *type;
  int code;
  if (!strcmp(lv, "root")) {
    logprintf("2root volume may not be wiped");
    return;
  }
  if (!is_lv_mounted("root"))
    mount_lv("root");
  type = get_lv_fstype(lv);
  umount_lv(lv);
  if (!strcmp(type, "swap"))
    snprintf(cmd, sizeof(cmd), "mkswap /dev/store/%s", lv);
  else if (!strcmp(type, "msdos") || !strcmp(type, "vfat"))
    snprintf(cmd, sizeof(cmd), "mkdosfs /dev/store/%s", lv);
  else
    snprintf(cmd, sizeof(cmd), "mke2fs -t ext4 /dev/store/%s", lv);
  logprintf("0making %s filesystem on volume %s", type, lv);
  system_logged(cmd);
}


x86 assembly (clang, -O0):
<wipe_lv>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    0x2e5d(%rip),%rax
mov    (%rax),%eax
mov    %rax,-0x38(%rbp)
mov    %rsp,%rcx
mov    %rcx,-0x10(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x30(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe39(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%eax
jne    11ef <wipe_lv+0x6f>
lea    0xe29(%rip),%rdi
mov    $0x0,%al
call   10a0 <logprintf@plt>
movl   $0x1,-0x28(%rbp)
jmp    12f4 <wipe_lv+0x174>
lea    0xe0a(%rip),%rdi
call   1030 <is_lv_mounted@plt>
cmp    $0x0,%eax
jne    1210 <wipe_lv+0x90>
lea    0xdf5(%rip),%rdi
call   1060 <mount_lv@plt>
mov    -0x8(%rbp),%rdi
call   1040 <get_lv_fstype@plt>
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
call   1090 <umount_lv@plt>
mov    -0x20(%rbp),%rdi
lea    0xdf2(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%eax
jne    125e <wipe_lv+0xde>
mov    -0x30(%rbp),%rdi
mov    -0x38(%rbp),%rax
mov    %eax,%esi
mov    -0x8(%rbp),%rcx
lea    0xdd4(%rip),%rdx
call   1050 <snprintf@plt>
jmp    12ce <wipe_lv+0x14e>
mov    -0x20(%rbp),%rdi
lea    0xdd4(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%eax
je     1290 <wipe_lv+0x110>
mov    -0x20(%rbp),%rdi
lea    0xdc1(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%eax
jne    12af <wipe_lv+0x12f>
mov    -0x30(%rbp),%rdi
mov    -0x38(%rbp),%rax
mov    %eax,%esi
mov    -0x8(%rbp),%rcx
lea    0xda3(%rip),%rdx
call   1050 <snprintf@plt>
jmp    12c9 <wipe_lv+0x149>
mov    -0x30(%rbp),%rdi
mov    -0x38(%rbp),%rax
mov    %eax,%esi
mov    -0x8(%rbp),%rcx
lea    0xd9a(%rip),%rdx
call   1050 <snprintf@plt>
jmp    12ce <wipe_lv+0x14e>
mov    -0x20(%rbp),%rsi
mov    -0x8(%rbp),%rdx
lea    0xd9e(%rip),%rdi
mov    $0x0,%al
call   10a0 <logprintf@plt>
mov    -0x30(%rbp),%rdi
call   1080 <system_logged@plt>
movl   $0x0,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<wipe_lv>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdi,%r14
mov    0x2e5b(%rip),%rax
mov    (%rax),%r15d
mov    %rsp,%rbx
lea    0xf(%r15),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
lea    0xe50(%rip),%rsi
call   1070 <strcmp@plt>
test   %eax,%eax
je     1233 <wipe_lv+0xb3>
lea    0xe40(%rip),%rdi
call   1030 <is_lv_mounted@plt>
test   %eax,%eax
jne    11d5 <wipe_lv+0x55>
lea    0xe30(%rip),%rdi
call   1060 <mount_lv@plt>
mov    %r14,%rdi
call   1040 <get_lv_fstype@plt>
mov    %rax,%r12
mov    %r14,%rdi
call   1090 <umount_lv@plt>
lea    0xe34(%rip),%rsi
mov    %r12,%rdi
call   1070 <strcmp@plt>
test   %eax,%eax
je     124d <wipe_lv+0xcd>
lea    0xe3b(%rip),%rsi
mov    %r12,%rdi
call   1070 <strcmp@plt>
test   %eax,%eax
je     1256 <wipe_lv+0xd6>
lea    0xe2e(%rip),%rsi
mov    %r12,%rdi
call   1070 <strcmp@plt>
test   %eax,%eax
lea    0xe22(%rip),%rax
lea    0xe31(%rip),%rdx
cmove  %rax,%rdx
jmp    125d <wipe_lv+0xdd>
lea    0xdcb(%rip),%rdi
xor    %eax,%eax
lea    -0x20(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    10a0 <logprintf@plt>
lea    0xdd4(%rip),%rdx
jmp    125d <wipe_lv+0xdd>
lea    0xdeb(%rip),%rdx
mov    %rbx,%rdi
mov    %r15d,%esi
mov    %r14,%rcx
call   1050 <snprintf@plt>
lea    0xe09(%rip),%rdi
mov    %r12,%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   10a0 <logprintf@plt>
mov    %rbx,%rdi
call   1080 <system_logged@plt>
lea    -0x20(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@PATH_MAX = global i32 0
@.str = [5 x i8] c"root\00"
@.str.1 = [30 x i8] c"2root volume may not be wiped\00"
@.str.2 = [5 x i8] c"swap\00"
@.str.3 = [21 x i8] c"mkswap /dev/store/%s\00"
@.str.4 = [6 x i8] c"msdos\00"
@.str.5 = [5 x i8] c"vfat\00"
@.str.6 = [22 x i8] c"mkdosfs /dev/store/%s\00"
@.str.7 = [29 x i8] c"mke2fs -t ext4 /dev/store/%s\00"
@.str.8 = [35 x i8] c"0making %s filesystem on volume %s\00"
define void @wipe_lv(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %2
%8 = load i32, i32* @PATH_MAX
%9 = zext i32 %8 to i64
%10 = call i8* @llvm.stacksave()
store i8* %10, i8** %3
%11 = alloca i8, i64 %9
store i64 %9, i64* %4
%12 = load i8*, i8** %2
%13 = call i32 @strcmp(i8* %12, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%14 = icmp ne i32 %13, 0
br i1 %14, label %17, label %15
15: ; preds = %1
%16 = call i32 (i8*, ...) @logprintf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %7
br label %56
17: ; preds = %1
%18 = call i32 @is_lv_mounted(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%19 = icmp ne i32 %18, 0
br i1 %19, label %22, label %20
20: ; preds = %17
%21 = call i32 @mount_lv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %22
22: ; preds = %20, %17
%23 = load i8*, i8** %2
%24 = call i8* @get_lv_fstype(i8* %23)
store i8* %24, i8** %5
%25 = load i8*, i8** %2
%26 = call i32 @umount_lv(i8* %25)
%27 = load i8*, i8** %5
%28 = call i32 @strcmp(i8* %27, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%29 = icmp ne i32 %28, 0
br i1 %29, label %34, label %30
30: ; preds = %22
%31 = trunc i64 %9 to i32
%32 = load i8*, i8** %2
%33 = call i32 @snprintf(i8* %11, i32 %31, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i8* %32)
br label %51
34: ; preds = %22
%35 = load i8*, i8** %5
%36 = call i32 @strcmp(i8* %35, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
%37 = icmp ne i32 %36, 0
br i1 %37, label %38, label %42
38: ; preds = %34
%39 = load i8*, i8** %5
%40 = call i32 @strcmp(i8* %39, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
%41 = icmp ne i32 %40, 0
br i1 %41, label %46, label %42
42: ; preds = %38, %34
%43 = trunc i64 %9 to i32
%44 = load i8*, i8** %2
%45 = call i32 @snprintf(i8* %11, i32 %43, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.6, i64 0, i64 0), i8* %44)
br label %50
46: ; preds = %38
%47 = trunc i64 %9 to i32
%48 = load i8*, i8** %2
%49 = call i32 @snprintf(i8* %11, i32 %47, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.7, i64 0, i64 0), i8* %48)
br label %50
50: ; preds = %46, %42
br label %51
51: ; preds = %50, %30
%52 = load i8*, i8** %5
%53 = load i8*, i8** %2
%54 = call i32 (i8*, ...) @logprintf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.8, i64 0, i64 0), i8* %52, i8* %53)
%55 = call i32 @system_logged(i8* %11)
store i32 0, i32* %7
br label %56
56: ; preds = %51, %15
%57 = load i8*, i8** %3
%58 = load i32, i32* %7
switch i32 %58, label %60 [
i32 0, label %59
i32 1, label %59
]
59: ; preds = %56, %56
ret void
60: ; preds = %56
unreachable
}

LLVM IR (-O2):
@PATH_MAX = global i32 0
@.str = [5 x i8] c"root\00"
@.str.1 = [30 x i8] c"2root volume may not be wiped\00"
@.str.2 = [5 x i8] c"swap\00"
@.str.3 = [21 x i8] c"mkswap /dev/store/%s\00"
@.str.4 = [6 x i8] c"msdos\00"
@.str.5 = [5 x i8] c"vfat\00"
@.str.6 = [22 x i8] c"mkdosfs /dev/store/%s\00"
@.str.7 = [29 x i8] c"mke2fs -t ext4 /dev/store/%s\00"
@.str.8 = [35 x i8] c"0making %s filesystem on volume %s\00"
define void @wipe_lv(i8* %0) {
%2 = load i32, i32* @PATH_MAX
%3 = zext i32 %2 to i64
%4 = alloca i8, i64 %3
%5 = tail call i32 @strcmp(i8* dereferenceable(1) %0, i8* dereferenceable(5) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i32 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %1
%8 = tail call i32 (i8*, ...) @logprintf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0))
br label %31
9: ; preds = %1
%10 = tail call i32 @is_lv_mounted(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %9
%13 = tail call i32 @mount_lv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %14
14: ; preds = %12, %9
%15 = tail call i8* @get_lv_fstype(i8* %0)
%16 = tail call i32 @umount_lv(i8* %0)
%17 = tail call i32 @strcmp(i8* dereferenceable(1) %15, i8* dereferenceable(5) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%18 = icmp eq i32 %17, 0
br i1 %18, label %26, label %19
19: ; preds = %14
%20 = tail call i32 @strcmp(i8* dereferenceable(1) %15, i8* dereferenceable(6) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
%21 = icmp eq i32 %20, 0
br i1 %21, label %26, label %22
22: ; preds = %19
%23 = tail call i32 @strcmp(i8* dereferenceable(1) %15, i8* dereferenceable(5) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
%24 = icmp eq i32 %23, 0
%25 = select i1 %24, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.7, i64 0, i64 0)
br label %26
26: ; preds = %22, %19, %14
%27 = phi i8* [ getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), %14 ], [ getelementptr inbounds ([22 x i8], [22 x i8]* @.str.6, i64 0, i64 0), %19 ], [ %25, %22 ]
%28 = call i32 @snprintf(i8* %4, i32 %2, i8* %27, i8* %0)
%29 = call i32 (i8*, ...) @logprintf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.8, i64 0, i64 0), i8* %15, i8* %0)
%30 = call i32 @system_logged(i8* %4)
br label %31
31: ; preds = %26, %7
ret void
}