#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 */
typedef int /*<<< orphan*/ *nis_name;

/* Variables and functions */
int /*<<< orphan*/ free(char *);
char *getenv(char *);
int /*<<< orphan*/ nis_local_principal();
char *searchowner(char *);
int /*<<< orphan*/ *strdup(int /*<<< orphan*/);
char *strdupa(char *);
char *strstr(char *, char *);
nis_name __nis_default_owner(char *defaults) {
  char *default_owner = NULL;
  char *cptr = defaults;
  if (cptr == NULL)
    cptr = getenv("NIS_DEFAULTS");
  if (cptr != NULL) {
    char *dptr = strstr(cptr, "owner=");
    if (dptr != NULL) {
      char *p = searchowner(dptr);
      if (p == NULL)
        return NULL;
      default_owner = strdupa(p);
      free(p);
    }
  }
  return strdup(default_owner ?: nis_local_principal());
}


x86 assembly (clang, -O0):
<__nis_default_owner>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11a7 <__nis_default_owner+0x37>
lea    0xe62(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1211 <__nis_default_owner+0xa1>
mov    -0x20(%rbp),%rdi
lea    0xe50(%rip),%rsi
call   1090 <strstr@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     120c <__nis_default_owner+0x9c>
mov    -0x28(%rbp),%rdi
call   1050 <searchowner@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    11f6 <__nis_default_owner+0x86>
movq   $0x0,-0x8(%rbp)
jmp    124c <__nis_default_owner+0xdc>
mov    -0x30(%rbp),%rdi
call   1060 <strdupa@plt>
mov    %rax,-0x18(%rbp)
mov    -0x30(%rbp),%rdi
call   1040 <free@plt>
jmp    1211 <__nis_default_owner+0xa1>
mov    -0x18(%rbp),%rax
mov    %rax,-0x38(%rbp)
cmp    $0x0,%rax
je     1230 <__nis_default_owner+0xc0>
mov    -0x38(%rbp),%rax
mov    %rax,-0x40(%rbp)
jmp    123d <__nis_default_owner+0xcd>
mov    $0x0,%al
call   1070 <nis_local_principal@plt>
cltq
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rax
mov    %eax,%edi
call   1080 <strdup@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<__nis_default_owner>:
push   %r14
push   %rbx
push   %rax
test   %rdi,%rdi
jne    118d <__nis_default_owner+0x1d>
lea    0xe80(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rdi
test   %rax,%rax
je     11c6 <__nis_default_owner+0x56>
lea    0xe79(%rip),%rsi
call   1090 <strstr@plt>
test   %rax,%rax
je     11c6 <__nis_default_owner+0x56>
mov    %rax,%rdi
call   1050 <searchowner@plt>
test   %rax,%rax
je     11de <__nis_default_owner+0x6e>
mov    %rax,%r14
mov    %rax,%rdi
call   1060 <strdupa@plt>
mov    %rax,%rbx
mov    %r14,%rdi
call   1040 <free@plt>
test   %rbx,%rbx
jne    11d0 <__nis_default_owner+0x60>
xor    %eax,%eax
call   1070 <nis_local_principal@plt>
movslq %eax,%rbx
mov    %ebx,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1080 <strdup@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [13 x i8] c"NIS_DEFAULTS\00"
@.str.1 = [7 x i8] c"owner=\00"
define i32* @__nis_default_owner(i8* %0) {
%2 = alloca i32*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
store i8* %0, i8** %3
store i8* null, i8** %4
%8 = load i8*, i8** %3
store i8* %8, i8** %5
%9 = load i8*, i8** %5
%10 = icmp eq i8* %9, null
br i1 %10, label %11, label %13
11: ; preds = %1
%12 = call i8* @getenv(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
store i8* %12, i8** %5
br label %13
13: ; preds = %11, %1
%14 = load i8*, i8** %5
%15 = icmp ne i8* %14, null
br i1 %15, label %16, label %33
16: ; preds = %13
%17 = load i8*, i8** %5
%18 = call i8* @strstr(i8* %17, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
store i8* %18, i8** %6
%19 = load i8*, i8** %6
%20 = icmp ne i8* %19, null
br i1 %20, label %21, label %32
21: ; preds = %16
%22 = load i8*, i8** %6
%23 = call i8* @searchowner(i8* %22)
store i8* %23, i8** %7
%24 = load i8*, i8** %7
%25 = icmp eq i8* %24, null
br i1 %25, label %26, label %27
26: ; preds = %21
store i32* null, i32** %2
br label %45
27: ; preds = %21
%28 = load i8*, i8** %7
%29 = call i8* @strdupa(i8* %28)
store i8* %29, i8** %4
%30 = load i8*, i8** %7
%31 = call i32 @free(i8* %30)
br label %32
32: ; preds = %27, %16
br label %33
33: ; preds = %32, %13
%34 = load i8*, i8** %4
%35 = icmp ne i8* %34, null
br i1 %35, label %36, label %37
36: ; preds = %33
br label %41
37: ; preds = %33
%38 = call i32 (...) @nis_local_principal()
%39 = sext i32 %38 to i64
%40 = inttoptr i64 %39 to i8*
br label %41
41: ; preds = %37, %36
%42 = phi i8* [ %34, %36 ], [ %40, %37 ]
%43 = ptrtoint i8* %42 to i32
%44 = call i32* @strdup(i32 %43)
store i32* %44, i32** %2
br label %45
45: ; preds = %41, %26
%46 = load i32*, i32** %2
ret i32* %46
}

LLVM IR (-O2):
@.str = [13 x i8] c"NIS_DEFAULTS\00"
@.str.1 = [7 x i8] c"owner=\00"
define i32* @__nis_default_owner(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %3, label %6
3: ; preds = %1
%4 = tail call i8* @getenv(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i8* %4, null
br i1 %5, label %17, label %6
6: ; preds = %1, %3
%7 = phi i8* [ %4, %3 ], [ %0, %1 ]
%8 = tail call i8* @strstr(i8* %7, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%9 = icmp eq i8* %8, null
br i1 %9, label %17, label %10
10: ; preds = %6
%11 = tail call i8* @searchowner(i8* %8)
%12 = icmp eq i8* %11, null
br i1 %12, label %26, label %13
13: ; preds = %10
%14 = tail call i8* @strdupa(i8* %11)
%15 = tail call i32 @free(i8* %11)
%16 = icmp eq i8* %14, null
br i1 %16, label %17, label %21
17: ; preds = %6, %3, %13
%18 = tail call i32 (...) @nis_local_principal()
%19 = sext i32 %18 to i64
%20 = inttoptr i64 %19 to i8*
br label %21
21: ; preds = %13, %17
%22 = phi i8* [ %20, %17 ], [ %14, %13 ]
%23 = ptrtoint i8* %22 to i64
%24 = trunc i64 %23 to i32
%25 = tail call i32* @strdup(i32 %24)
br label %26
26: ; preds = %10, %21
%27 = phi i32* [ %25, %21 ], [ null, %10 ]
ret i32* %27
}