#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 /*<<< orphan*/ error(char *);
int /*<<< orphan*/ execl(char *, char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ execvp(char *, char **);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int);
char *getenv(char *);
int keyctl_join_session_keyring(char *);
int /*<<< orphan*/ stderr;
scalar_t__ strcmp(char *, char *);
int act_keyctl_session(int argc, char *argv[]) {
  char *p, *q;
  int ret;
  argv++;
  argc--;
  p = NULL;
  if (argc != 0) {
    p = *argv;
    if (strcmp(p, "-") == 0)
      p = NULL;
    argv++;
    argc--;
  }
  ret = keyctl_join_session_keyring(p);
  if (ret < 0)
    error("keyctl_join_session_keyring");
  fprintf(stderr, "Joined session keyring: %d\n", ret);
  if (argc == 0) {
    q = getenv("SHELL");
    if (!q)
      q = "/bin/sh";
    execl(q, q, NULL);
    error(q);
  }
  execvp(argv[0], argv);
  error(argv[0]);
}


x86 assembly (clang, -O0):
<act_keyctl_session>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x8(%rbp)
movq   $0x0,-0x18(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     11e8 <act_keyctl_session+0x78>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe44(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    11d3 <act_keyctl_session+0x63>
movq   $0x0,-0x18(%rbp)
mov    -0x10(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x8(%rbp)
mov    -0x18(%rbp),%rdi
call   1090 <keyctl_join_session_keyring@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    120a <act_keyctl_session+0x9a>
lea    0xdfd(%rip),%rdi
call   1060 <error@plt>
mov    0x2dcf(%rip),%rax
mov    (%rax),%edi
mov    -0x24(%rbp),%edx
lea    0xe01(%rip),%rsi
call   1050 <fprintf@plt>
cmpl   $0x0,-0x8(%rbp)
jne    126c <act_keyctl_session+0xfc>
lea    0xe07(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1252 <act_keyctl_session+0xe2>
lea    0xdf2(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x20(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1080 <execl@plt>
mov    -0x20(%rbp),%rdi
call   1060 <error@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rsi
call   1070 <execvp@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1060 <error@plt>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<act_keyctl_session>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%r14
cmp    $0x1,%edi
jne    1186 <act_keyctl_session+0x16>
add    $0x8,%r14
xor    %ebx,%ebx
xor    %ebp,%ebp
jmp    11a9 <act_keyctl_session+0x39>
mov    %edi,%ebp
mov    0x8(%r14),%rbx
lea    0xe6d(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strcmp@plt>
test   %rax,%rax
cmove  %rax,%rbx
add    $0x10,%r14
add    $0xfffffffe,%ebp
mov    %rbx,%rdi
call   1090 <keyctl_join_session_keyring@plt>
mov    %eax,%ebx
test   %eax,%eax
jns    11c3 <act_keyctl_session+0x53>
lea    0xe44(%rip),%rdi
call   1060 <error@plt>
mov    0x2e16(%rip),%rax
mov    (%rax),%edi
lea    0xe4b(%rip),%rsi
mov    %ebx,%edx
call   1050 <fprintf@plt>
test   %ebp,%ebp
jne    120d <act_keyctl_session+0x9d>
lea    0xe55(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
lea    0xe4c(%rip),%rbx
cmovne %rax,%rbx
mov    %rbx,%rdi
mov    %rbx,%rsi
xor    %edx,%edx
call   1080 <execl@plt>
mov    %rbx,%rdi
call   1060 <error@plt>
mov    (%r14),%rdi
mov    %r14,%rsi
call   1070 <execvp@plt>
mov    (%r14),%rdi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1060 <error@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"-\00"
@.str.1 = [28 x i8] c"keyctl_join_session_keyring\00"
@stderr = global i32 0
@.str.2 = [28 x i8] c"Joined session keyring: %d\0A\00"
@.str.3 = [6 x i8] c"SHELL\00"
@.str.4 = [8 x i8] c"/bin/sh\00"
define i32 @act_keyctl_session(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i8**, i8*** %5
%10 = getelementptr inbounds i8*, i8** %9, i32 1
store i8** %10, i8*** %5
%11 = load i32, i32* %4
%12 = add nsw i32 %11, -1
store i32 %12, i32* %4
store i8* null, i8** %6
%13 = load i32, i32* %4
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %27
15: ; preds = %2
%16 = load i8**, i8*** %5
%17 = load i8*, i8** %16
store i8* %17, i8** %6
%18 = load i8*, i8** %6
%19 = call i64 @strcmp(i8* %18, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %22
21: ; preds = %15
store i8* null, i8** %6
br label %22
22: ; preds = %21, %15
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i32 1
store i8** %24, i8*** %5
%25 = load i32, i32* %4
%26 = add nsw i32 %25, -1
store i32 %26, i32* %4
br label %27
27: ; preds = %22, %2
%28 = load i8*, i8** %6
%29 = call i32 @keyctl_join_session_keyring(i8* %28)
store i32 %29, i32* %8
%30 = load i32, i32* %8
%31 = icmp slt i32 %30, 0
br i1 %31, label %32, label %34
32: ; preds = %27
%33 = call i32 @error(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
br label %34
34: ; preds = %32, %27
%35 = load i32, i32* @stderr
%36 = load i32, i32* %8
%37 = call i32 @fprintf(i32 %35, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i32 %36)
%38 = load i32, i32* %4
%39 = icmp eq i32 %38, 0
br i1 %39, label %40, label %51
40: ; preds = %34
%41 = call i8* @getenv(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
store i8* %41, i8** %7
%42 = load i8*, i8** %7
%43 = icmp ne i8* %42, null
br i1 %43, label %45, label %44
44: ; preds = %40
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i8** %7
br label %45
45: ; preds = %44, %40
%46 = load i8*, i8** %7
%47 = load i8*, i8** %7
%48 = call i32 @execl(i8* %46, i8* %47, i32* null)
%49 = load i8*, i8** %7
%50 = call i32 @error(i8* %49)
br label %51
51: ; preds = %45, %34
%52 = load i8**, i8*** %5
%53 = getelementptr inbounds i8*, i8** %52, i64 0
%54 = load i8*, i8** %53
%55 = load i8**, i8*** %5
%56 = call i32 @execvp(i8* %54, i8** %55)
%57 = load i8**, i8*** %5
%58 = getelementptr inbounds i8*, i8** %57, i64 0
%59 = load i8*, i8** %58
%60 = call i32 @error(i8* %59)
%61 = load i32, i32* %3
ret i32 %61
}

LLVM IR (-O2):
@.str = [2 x i8] c"-\00"
@.str.1 = [28 x i8] c"keyctl_join_session_keyring\00"
@stderr = global i32 0
@.str.2 = [28 x i8] c"Joined session keyring: %d\0A\00"
@.str.3 = [6 x i8] c"SHELL\00"
@.str.4 = [8 x i8] c"/bin/sh\00"
define i32 @act_keyctl_session(i32 %0, i8** %1) {
%3 = getelementptr inbounds i8*, i8** %1, i64 1
%4 = icmp eq i32 %0, 1
br i1 %4, label %12, label %5
5: ; preds = %2
%6 = load i8*, i8** %3
%7 = tail call i64 @strcmp(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i64 %7, 0
%9 = select i1 %8, i8* null, i8* %6
%10 = getelementptr inbounds i8*, i8** %1, i64 2
%11 = add nsw i32 %0, -2
br label %12
12: ; preds = %5, %2
%13 = phi i8* [ %9, %5 ], [ null, %2 ]
%14 = phi i8** [ %10, %5 ], [ %3, %2 ]
%15 = phi i32 [ %11, %5 ], [ 0, %2 ]
%16 = tail call i32 @keyctl_join_session_keyring(i8* %13)
%17 = icmp slt i32 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %12
%19 = tail call i32 @error(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
br label %20
20: ; preds = %18, %12
%21 = load i32, i32* @stderr
%22 = tail call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i32 %16)
%23 = icmp eq i32 %15, 0
br i1 %23, label %24, label %30
24: ; preds = %20
%25 = tail call i8* @getenv(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%26 = icmp eq i8* %25, null
%27 = select i1 %26, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i8* %25
%28 = tail call i32 @execl(i8* %27, i8* %27, i32* null)
%29 = tail call i32 @error(i8* %27)
br label %30
30: ; preds = %24, %20
%31 = load i8*, i8** %14
%32 = tail call i32 @execvp(i8* %31, i8** %14)
%33 = load i8*, i8** %14
%34 = tail call i32 @error(i8* %33)
ret i32 undef
}