#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*/ chmod(char *, int);
int /*<<< orphan*/ chown(char *, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ fchmod(int, int);
int /*<<< orphan*/ fchown(int, int /*<<< orphan*/, int /*<<< orphan*/);
scalar_t__ logout(char *);
int /*<<< orphan*/ logwtmp(char *, char *, char *);
void cleanup_session(char *tty, int pty_fd) {
  char *line;
  line = tty;
  if (logout(line))
    logwtmp(line, "", "");
  chmod(tty, 0666);
  chown(tty, 0, 0);
  fchmod(pty_fd, 0666);
  fchown(pty_fd, 0, 0);
}


x86 assembly (clang, -O0):
<cleanup_session>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <logout@plt>
cmp    $0x0,%rax
je     119d <cleanup_session+0x3d>
mov    -0x18(%rbp),%rdi
lea    0xe6b(%rip),%rdx
mov    %rdx,%rsi
call   1040 <logwtmp@plt>
mov    -0x8(%rbp),%rdi
mov    $0x1b6,%esi
call   1070 <chmod@plt>
mov    -0x8(%rbp),%rdi
xor    %edx,%edx
mov    %edx,%esi
call   1050 <chown@plt>
mov    -0xc(%rbp),%edi
mov    $0x1b6,%esi
call   1060 <fchmod@plt>
mov    -0xc(%rbp),%edi
xor    %edx,%edx
mov    %edx,%esi
call   1080 <fchown@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cleanup_session>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%rbx
call   1030 <logout@plt>
test   %rax,%rax
je     1184 <cleanup_session+0x24>
lea    0xe87(%rip),%rdx
mov    %rbx,%rdi
mov    %rdx,%rsi
call   1040 <logwtmp@plt>
mov    %rbx,%rdi
mov    $0x1b6,%esi
call   1070 <chmod@plt>
mov    %rbx,%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1050 <chown@plt>
mov    %ebp,%edi
mov    $0x1b6,%esi
call   1060 <fchmod@plt>
mov    %ebp,%edi
xor    %esi,%esi
xor    %edx,%edx
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1080 <fchown@plt>

LLVM IR (-O0):
@.str = [1 x i8] zeroinitializer
define void @cleanup_session(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8*
store i8* %0, i8** %3
store i32 %1, i32* %4
%6 = load i8*, i8** %3
store i8* %6, i8** %5
%7 = load i8*, i8** %5
%8 = call i64 @logout(i8* %7)
%9 = icmp ne i64 %8, 0
br i1 %9, label %10, label %13
10: ; preds = %2
%11 = load i8*, i8** %5
%12 = call i32 @logwtmp(i8* %11, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
br label %13
13: ; preds = %10, %2
%14 = load i8*, i8** %3
%15 = call i32 @chmod(i8* %14, i32 438)
%16 = load i8*, i8** %3
%17 = call i32 @chown(i8* %16, i32 0, i32 0)
%18 = load i32, i32* %4
%19 = call i32 @fchmod(i32 %18, i32 438)
%20 = load i32, i32* %4
%21 = call i32 @fchown(i32 %20, i32 0, i32 0)
ret void
}

LLVM IR (-O2):
@.str = [1 x i8] zeroinitializer
define void @cleanup_session(i8* %0, i32 %1) {
%3 = tail call i64 @logout(i8* %0)
%4 = icmp eq i64 %3, 0
br i1 %4, label %7, label %5
5: ; preds = %2
%6 = tail call i32 @logwtmp(i8* %0, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
br label %7
7: ; preds = %5, %2
%8 = tail call i32 @chmod(i8* %0, i32 438)
%9 = tail call i32 @chown(i8* %0, i32 0, i32 0)
%10 = tail call i32 @fchmod(i32 %1, i32 438)
%11 = tail call i32 @fchown(i32 %1, i32 0, i32 0)
ret void
}