#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 *);
void 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,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x10(%rbp)
mov    -0x4(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x4(%rbp)
movq   $0x0,-0x18(%rbp)
cmpl   $0x0,-0x4(%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    -0x4(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x4(%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,-0x4(%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>
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 void @act_keyctl_session(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
store i32 %0, i32* %3
store i8** %1, i8*** %4
%8 = load i8**, i8*** %4
%9 = getelementptr inbounds i8*, i8** %8, i32 1
store i8** %9, i8*** %4
%10 = load i32, i32* %3
%11 = add nsw i32 %10, -1
store i32 %11, i32* %3
store i8* null, i8** %5
%12 = load i32, i32* %3
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %26
14: ; preds = %2
%15 = load i8**, i8*** %4
%16 = load i8*, i8** %15
store i8* %16, i8** %5
%17 = load i8*, i8** %5
%18 = call i64 @strcmp(i8* %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %21
20: ; preds = %14
store i8* null, i8** %5
br label %21
21: ; preds = %20, %14
%22 = load i8**, i8*** %4
%23 = getelementptr inbounds i8*, i8** %22, i32 1
store i8** %23, i8*** %4
%24 = load i32, i32* %3
%25 = add nsw i32 %24, -1
store i32 %25, i32* %3
br label %26
26: ; preds = %21, %2
%27 = load i8*, i8** %5
%28 = call i32 @keyctl_join_session_keyring(i8* %27)
store i32 %28, i32* %7
%29 = load i32, i32* %7
%30 = icmp slt i32 %29, 0
br i1 %30, label %31, label %33
31: ; preds = %26
%32 = call i32 @error(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
br label %33
33: ; preds = %31, %26
%34 = load i32, i32* @stderr
%35 = load i32, i32* %7
%36 = call i32 @fprintf(i32 %34, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i32 %35)
%37 = load i32, i32* %3
%38 = icmp eq i32 %37, 0
br i1 %38, label %39, label %50
39: ; preds = %33
%40 = call i8* @getenv(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
store i8* %40, i8** %6
%41 = load i8*, i8** %6
%42 = icmp ne i8* %41, null
br i1 %42, label %44, label %43
43: ; preds = %39
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i8** %6
br label %44
44: ; preds = %43, %39
%45 = load i8*, i8** %6
%46 = load i8*, i8** %6
%47 = call i32 @execl(i8* %45, i8* %46, i32* null)
%48 = load i8*, i8** %6
%49 = call i32 @error(i8* %48)
br label %50
50: ; preds = %44, %33
%51 = load i8**, i8*** %4
%52 = getelementptr inbounds i8*, i8** %51, i64 0
%53 = load i8*, i8** %52
%54 = load i8**, i8*** %4
%55 = call i32 @execvp(i8* %53, i8** %54)
%56 = load i8**, i8*** %4
%57 = getelementptr inbounds i8*, i8** %56, i64 0
%58 = load i8*, i8** %57
%59 = call i32 @error(i8* %58)
ret void
}

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 void @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 void
}