#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 */
int construct_umount_args(int, char **, char ***);
int errno;
int execv(char *, char **);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ free(char **);
int /*<<< orphan*/ stderr;
char *strerror(int);
scalar_t__ unlink_keys_from_keyring(char *);
int /*<<< orphan*/ usage();
int main(int argc, char **argv) {
  char **new_argv;
  int rc;
  if (argc < 2)
    usage();
  if (unlink_keys_from_keyring(argv[1]))
    fprintf(stderr, "Could not unlink the key(s) from your keying. "
                    "Please use `keyctl unlink` if you wish to remove the "
                    "key(s). Proceeding with umount.\n");
  rc = construct_umount_args(argc, argv, &new_argv);
  if (rc) {
    fprintf(stderr, "Failed to construct umount arguments: %s\n", strerror(rc));
    goto out;
  }
  rc = execv("/bin/umount", new_argv);
  if (rc < 0) {
    rc = errno;
    fprintf(stderr, "Failed to execute %s: %m\n", "/bin/umount");
    goto free_out;
  }
  rc = 0;
free_out:
  free(new_argv);
out:
  return rc;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    1197 <main+0x27>
mov    $0x0,%al
call   1050 <usage@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1070 <unlink_keys_from_keyring@plt>
cmp    $0x0,%rax
je     11c5 <main+0x55>
mov    0x2e2b(%rip),%rax
mov    (%rax),%edi
lea    0xe42(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    -0x18(%rbp),%rdx
call   1060 <construct_umount_args@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     120f <main+0x9f>
mov    0x2df7(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%edi
call   1080 <strerror@plt>
mov    -0x20(%rbp),%edi
mov    %rax,%rdx
lea    0xe81(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
jmp    126b <main+0xfb>
mov    -0x18(%rbp),%rsi
lea    0xe94(%rip),%rdi
call   1090 <execv@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    125b <main+0xeb>
mov    0x2da5(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    0x2da1(%rip),%rax
mov    (%rax),%edi
lea    0xe72(%rip),%rsi
lea    0xe5f(%rip),%rdx
mov    $0x0,%al
call   1040 <fprintf@plt>
jmp    1262 <main+0xf2>
movl   $0x0,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x1c(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%ebp
cmp    $0x1,%edi
jg     1184 <main+0x14>
xor    %eax,%eax
call   1050 <usage@plt>
mov    0x8(%rbx),%rdi
call   1070 <unlink_keys_from_keyring@plt>
test   %rax,%rax
je     11a9 <main+0x39>
mov    0x2e47(%rip),%rax
mov    (%rax),%edi
lea    0xe5e(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    %rsp,%rdx
mov    %ebp,%edi
mov    %rbx,%rsi
call   1060 <construct_umount_args@plt>
test   %eax,%eax
je     11e1 <main+0x71>
mov    %eax,%ebx
mov    0x2e1d(%rip),%rax
mov    (%rax),%ebp
mov    %ebx,%edi
call   1080 <strerror@plt>
lea    0xeb1(%rip),%rsi
mov    %ebp,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1040 <fprintf@plt>
jmp    1227 <main+0xb7>
mov    (%rsp),%rsi
lea    0xec2(%rip),%rdi
call   1090 <execv@plt>
xor    %ebx,%ebx
test   %eax,%eax
jns    121e <main+0xae>
mov    0x2dda(%rip),%rax
mov    (%rax),%ebx
mov    0x2dd9(%rip),%rax
mov    (%rax),%edi
lea    0xeaa(%rip),%rsi
lea    0xe97(%rip),%rdx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    (%rsp),%rdi
call   1030 <free@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [132 x i8] c"Could not unlink the key(s) from your keying. Please use `keyctl unlink` if you wish to remove the key(s). Proceeding with umount.\0A\00"
@.str.1 = [42 x i8] c"Failed to construct umount arguments: %s\0A\00"
@.str.2 = [12 x i8] c"/bin/umount\00"
@errno = global i32 0
@.str.3 = [26 x i8] c"Failed to execute %s: %m\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8**
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = icmp slt i32 %8, 2
br i1 %9, label %10, label %12
10: ; preds = %2
%11 = call i32 (...) @usage()
br label %12
12: ; preds = %10, %2
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 1
%15 = load i8*, i8** %14
%16 = call i64 @unlink_keys_from_keyring(i8* %15)
%17 = icmp ne i64 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %12
%19 = load i32, i32* @stderr
%20 = call i32 (i32, i8*, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([132 x i8], [132 x i8]* @.str, i64 0, i64 0))
br label %21
21: ; preds = %18, %12
%22 = load i32, i32* %4
%23 = load i8**, i8*** %5
%24 = call i32 @construct_umount_args(i32 %22, i8** %23, i8*** %6)
store i32 %24, i32* %7
%25 = load i32, i32* %7
%26 = icmp ne i32 %25, 0
br i1 %26, label %27, label %32
27: ; preds = %21
%28 = load i32, i32* @stderr
%29 = load i32, i32* %7
%30 = call i8* @strerror(i32 %29)
%31 = call i32 (i32, i8*, ...) @fprintf(i32 %28, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0), i8* %30)
br label %45
32: ; preds = %21
%33 = load i8**, i8*** %6
%34 = call i32 @execv(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i8** %33)
store i32 %34, i32* %7
%35 = load i32, i32* %7
%36 = icmp slt i32 %35, 0
br i1 %36, label %37, label %41
37: ; preds = %32
%38 = load i32, i32* @errno
store i32 %38, i32* %7
%39 = load i32, i32* @stderr
%40 = call i32 (i32, i8*, ...) @fprintf(i32 %39, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
br label %42
41: ; preds = %32
store i32 0, i32* %7
br label %42
42: ; preds = %41, %37
%43 = load i8**, i8*** %6
%44 = call i32 @free(i8** %43)
br label %45
45: ; preds = %42, %27
%46 = load i32, i32* %7
ret i32 %46
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [132 x i8] c"Could not unlink the key(s) from your keying. Please use `keyctl unlink` if you wish to remove the key(s). Proceeding with umount.\0A\00"
@.str.1 = [42 x i8] c"Failed to construct umount arguments: %s\0A\00"
@.str.2 = [12 x i8] c"/bin/umount\00"
@errno = global i32 0
@.str.3 = [26 x i8] c"Failed to execute %s: %m\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i8**
%4 = bitcast i8*** %3 to i8*
%5 = icmp slt i32 %0, 2
br i1 %5, label %6, label %8
6: ; preds = %2
%7 = tail call i32 (...) @usage()
br label %8
8: ; preds = %6, %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = tail call i64 @unlink_keys_from_keyring(i8* %10)
%12 = icmp eq i64 %11, 0
br i1 %12, label %16, label %13
13: ; preds = %8
%14 = load i32, i32* @stderr
%15 = tail call i32 (i32, i8*, ...) @fprintf(i32 %14, i8* getelementptr inbounds ([132 x i8], [132 x i8]* @.str, i64 0, i64 0))
br label %16
16: ; preds = %13, %8
%17 = call i32 @construct_umount_args(i32 %0, i8** %1, i8*** %3)
%18 = icmp eq i32 %17, 0
br i1 %18, label %23, label %19
19: ; preds = %16
%20 = load i32, i32* @stderr
%21 = call i8* @strerror(i32 %17)
%22 = call i32 (i32, i8*, ...) @fprintf(i32 %20, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0), i8* %21)
br label %35
23: ; preds = %16
%24 = load i8**, i8*** %3
%25 = call i32 @execv(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i8** %24)
%26 = icmp slt i32 %25, 0
br i1 %26, label %27, label %31
27: ; preds = %23
%28 = load i32, i32* @errno
%29 = load i32, i32* @stderr
%30 = call i32 (i32, i8*, ...) @fprintf(i32 %29, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
br label %31
31: ; preds = %23, %27
%32 = phi i32 [ %28, %27 ], [ 0, %23 ]
%33 = load i8**, i8*** %3
%34 = call i32 @free(i8** %33)
br label %35
35: ; preds = %31, %19
%36 = phi i32 [ %17, %19 ], [ %32, %31 ]
ret i32 %36
}