#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 */
struct passwd {
  char *pw_dir;
};

/* Variables and functions */
scalar_t__ ENOENT;
int R_OK;
int X_OK;
int access(char *, int);
scalar_t__ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, ...);
int /*<<< orphan*/ free(char *);
struct passwd *getpwuid(int /*<<< orphan*/);
int /*<<< orphan*/ getuid();
char *malloc(scalar_t__);
scalar_t__ mkdir(char *, int);
int /*<<< orphan*/ sprintf(char *, char *, char *, char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
char *strerror(scalar_t__);
scalar_t__ strlen(char *);
char *get_yanglint_dir(void) {
  int ret;
  struct passwd *pw;
  char *user_home, *yl_dir;
  if (!(pw = getpwuid(getuid()))) {
    fprintf(stderr, "Determining home directory failed (%s).\n",
            strerror(errno));
    return NULL;
  }
  user_home = pw->pw_dir;
  yl_dir = malloc(strlen(user_home) + 1 + strlen(".yanglint") + 1);
  if (!yl_dir) {
    fprintf(stderr, "Memory allocation failed (%s).\n", strerror(errno));
    return NULL;
  }
  sprintf(yl_dir, "%s/%s", user_home, ".yanglint");
  ret = access(yl_dir, R_OK | X_OK);
  if (ret == -1) {
    if (errno == ENOENT) {
      fprintf(stdout,
              "Configuration directory \"%s\" does not exist, creating it.\n",
              yl_dir);
      if (mkdir(yl_dir, 00700)) {
        fprintf(stderr,
                "Configuration directory \"%s\" cannot be created (%s).\n",
                yl_dir, strerror(errno));
        free(yl_dir);
        return NULL;
      }
    } else {
      fprintf(stderr,
              "Configuration directory \"%s\" exists but cannot be accessed "
              "(%s).\n",
              yl_dir, strerror(errno));
      free(yl_dir);
      return NULL;
    }
  }
  return yl_dir;
}


x86 assembly (clang, -O0):
<get_yanglint_dir>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    $0x0,%al
call   1070 <getuid@plt>
mov    %eax,%edi
call   1050 <getpwuid@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    1200 <get_yanglint_dir+0x60>
mov    0x2e0d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    0x2df9(%rip),%rax
mov    (%rax),%rdi
call   10c0 <strerror@plt>
mov    -0x2c(%rbp),%edi
mov    %rax,%rdx
lea    0xe14(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
movq   $0x0,-0x8(%rbp)
jmp    13c7 <get_yanglint_dir+0x227>
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1060 <strlen@plt>
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
lea    0xe06(%rip),%rdi
call   1060 <strlen@plt>
mov    -0x38(%rbp),%rdi
add    %rax,%rdi
add    $0x1,%rdi
call   1090 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1283 <get_yanglint_dir+0xe3>
mov    0x2d8a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x3c(%rbp)
mov    0x2d76(%rip),%rax
mov    (%rax),%rdi
call   10c0 <strerror@plt>
mov    -0x3c(%rbp),%edi
mov    %rax,%rdx
lea    0xdc4(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
movq   $0x0,-0x8(%rbp)
jmp    13c7 <get_yanglint_dir+0x227>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rdx
lea    0xdc1(%rip),%rsi
lea    0xd90(%rip),%rcx
call   10b0 <sprintf@plt>
mov    -0x28(%rbp),%rdi
mov    0x2d17(%rip),%rax
mov    (%rax),%esi
mov    0x2d36(%rip),%rax
or     (%rax),%esi
call   10a0 <access@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0xffffffff,-0xc(%rbp)
jne    13bf <get_yanglint_dir+0x21f>
mov    0x2d03(%rip),%rax
mov    (%rax),%rax
mov    0x2cd9(%rip),%rcx
cmp    (%rcx),%rax
jne    1369 <get_yanglint_dir+0x1c9>
mov    0x2ce1(%rip),%rax
mov    (%rax),%edi
mov    -0x28(%rbp),%rdx
lea    0xd65(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    -0x28(%rbp),%rdi
mov    $0x1c0,%esi
call   1040 <mkdir@plt>
cmp    $0x0,%rax
je     1364 <get_yanglint_dir+0x1c4>
mov    0x2cbe(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4c(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    0x2ca2(%rip),%rax
mov    (%rax),%rdi
call   10c0 <strerror@plt>
mov    -0x4c(%rbp),%edi
mov    -0x48(%rbp),%rdx
mov    %rax,%rcx
lea    0xd4d(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x8(%rbp)
jmp    13c7 <get_yanglint_dir+0x227>
jmp    13ba <get_yanglint_dir+0x21a>
mov    0x2c68(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x5c(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    0x2c4c(%rip),%rax
mov    (%rax),%rdi
call   10c0 <strerror@plt>
mov    -0x5c(%rbp),%edi
mov    -0x58(%rbp),%rdx
mov    %rax,%rcx
lea    0xd2d(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x8(%rbp)
jmp    13c7 <get_yanglint_dir+0x227>
jmp    13bf <get_yanglint_dir+0x21f>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_yanglint_dir>:
push   %rbp
push   %r14
push   %rbx
xor    %eax,%eax
call   1070 <getuid@plt>
mov    %eax,%edi
call   1050 <getpwuid@plt>
test   %rax,%rax
je     1279 <get_yanglint_dir+0xd9>
mov    (%rax),%rbx
mov    %rbx,%rdi
call   1060 <strlen@plt>
lea    0xb(%rax),%rdi
call   1090 <malloc@plt>
test   %rax,%rax
je     129a <get_yanglint_dir+0xfa>
mov    %rax,%r14
lea    0xe71(%rip),%rsi
lea    0xe40(%rip),%rcx
mov    %rax,%rdi
mov    %rbx,%rdx
call   10b0 <sprintf@plt>
mov    0x2dc5(%rip),%rax
mov    0x2de6(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    %r14,%rdi
call   10a0 <access@plt>
cmp    $0xffffffff,%eax
jne    12c8 <get_yanglint_dir+0x128>
mov    0x2db2(%rip),%rbx
mov    (%rbx),%rdi
mov    0x2d88(%rip),%rax
cmp    (%rax),%rdi
jne    12d0 <get_yanglint_dir+0x130>
mov    0x2d90(%rip),%rax
mov    (%rax),%edi
lea    0xe18(%rip),%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    %r14,%rdi
mov    $0x1c0,%esi
call   1040 <mkdir@plt>
test   %rax,%rax
je     12c8 <get_yanglint_dir+0x128>
mov    0x2d74(%rip),%rax
mov    (%rax),%ebp
mov    (%rbx),%rdi
call   10c0 <strerror@plt>
lea    0xe1f(%rip),%rsi
mov    %ebp,%edi
jmp    12e7 <get_yanglint_dir+0x147>
mov    0x2d58(%rip),%rax
mov    (%rax),%ebx
mov    0x2d47(%rip),%rax
mov    (%rax),%rdi
call   10c0 <strerror@plt>
lea    0xd68(%rip),%rsi
jmp    12b9 <get_yanglint_dir+0x119>
mov    0x2d37(%rip),%rax
mov    (%rax),%ebx
mov    0x2d26(%rip),%rax
mov    (%rax),%rdi
call   10c0 <strerror@plt>
lea    0xd7a(%rip),%rsi
xor    %r14d,%r14d
mov    %ebx,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    0x2d01(%rip),%rax
mov    (%rax),%ebx
call   10c0 <strerror@plt>
lea    0xde5(%rip),%rsi
mov    %ebx,%edi
mov    %r14,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    %r14,%rdi
call   1030 <free@plt>
xor    %r14d,%r14d
jmp    12c8 <get_yanglint_dir+0x128>

LLVM IR (-O0):
%struct.passwd = type { i8* }
@stderr = global i32 0
@.str = [41 x i8] c"Determining home directory failed (%s).\0A\00"
@errno = global i64 0
@.str.1 = [10 x i8] c".yanglint\00"
@.str.2 = [32 x i8] c"Memory allocation failed (%s).\0A\00"
@.str.3 = [6 x i8] c"%s/%s\00"
@R_OK = global i32 0
@X_OK = global i32 0
@ENOENT = global i64 0
@stdout = global i32 0
@.str.4 = [59 x i8] c"Configuration directory \22%s\22 does not exist, creating it.\0A\00"
@.str.5 = [54 x i8] c"Configuration directory \22%s\22 cannot be created (%s).\0A\00"
@.str.6 = [66 x i8] c"Configuration directory \22%s\22 exists but cannot be accessed (%s).\0A\00"
define i8* @get_yanglint_dir() {
%1 = alloca i8*
%2 = alloca i32
%3 = alloca %struct.passwd*
%4 = alloca i8*
%5 = alloca i8*
%6 = call i32 (...) @getuid()
%7 = call %struct.passwd* @getpwuid(i32 %6)
store %struct.passwd* %7, %struct.passwd** %3
%8 = icmp ne %struct.passwd* %7, null
br i1 %8, label %14, label %9
9: ; preds = %0
%10 = load i32, i32* @stderr
%11 = load i64, i64* @errno
%12 = call i8* @strerror(i64 %11)
%13 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %10, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i8* %12)
store i8* null, i8** %1
br label %74
14: ; preds = %0
%15 = load %struct.passwd*, %struct.passwd** %3
%16 = getelementptr inbounds %struct.passwd, %struct.passwd* %15, i32 0, i32 0
%17 = load i8*, i8** %16
store i8* %17, i8** %4
%18 = load i8*, i8** %4
%19 = call i64 @strlen(i8* %18)
%20 = add nsw i64 %19, 1
%21 = call i64 @strlen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%22 = add nsw i64 %20, %21
%23 = add nsw i64 %22, 1
%24 = call i8* @malloc(i64 %23)
store i8* %24, i8** %5
%25 = load i8*, i8** %5
%26 = icmp ne i8* %25, null
br i1 %26, label %32, label %27
27: ; preds = %14
%28 = load i32, i32* @stderr
%29 = load i64, i64* @errno
%30 = call i8* @strerror(i64 %29)
%31 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %28, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), i8* %30)
store i8* null, i8** %1
br label %74
32: ; preds = %14
%33 = load i8*, i8** %5
%34 = load i8*, i8** %4
%35 = call i32 @sprintf(i8* %33, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* %34, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%36 = load i8*, i8** %5
%37 = load i32, i32* @R_OK
%38 = load i32, i32* @X_OK
%39 = or i32 %37, %38
%40 = call i32 @access(i8* %36, i32 %39)
store i32 %40, i32* %2
%41 = load i32, i32* %2
%42 = icmp eq i32 %41, -1
br i1 %42, label %43, label %72
43: ; preds = %32
%44 = load i64, i64* @errno
%45 = load i64, i64* @ENOENT
%46 = icmp eq i64 %44, %45
br i1 %46, label %47, label %63
47: ; preds = %43
%48 = load i32, i32* @stdout
%49 = load i8*, i8** %5
%50 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %48, i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.4, i64 0, i64 0), i8* %49)
%51 = load i8*, i8** %5
%52 = call i64 @mkdir(i8* %51, i32 448)
%53 = icmp ne i64 %52, 0
br i1 %53, label %54, label %62
54: ; preds = %47
%55 = load i32, i32* @stderr
%56 = load i8*, i8** %5
%57 = load i64, i64* @errno
%58 = call i8* @strerror(i64 %57)
%59 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %55, i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.5, i64 0, i64 0), i8* %56, i8* %58)
%60 = load i8*, i8** %5
%61 = call i32 @free(i8* %60)
store i8* null, i8** %1
br label %74
62: ; preds = %47
br label %71
63: ; preds = %43
%64 = load i32, i32* @stderr
%65 = load i8*, i8** %5
%66 = load i64, i64* @errno
%67 = call i8* @strerror(i64 %66)
%68 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %64, i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str.6, i64 0, i64 0), i8* %65, i8* %67)
%69 = load i8*, i8** %5
%70 = call i32 @free(i8* %69)
store i8* null, i8** %1
br label %74
71: ; preds = %62
br label %72
72: ; preds = %71, %32
%73 = load i8*, i8** %5
store i8* %73, i8** %1
br label %74
74: ; preds = %72, %63, %54, %27, %9
%75 = load i8*, i8** %1
ret i8* %75
}

LLVM IR (-O2):
%struct.passwd = type { i8* }
@stderr = global i32 0
@.str = [41 x i8] c"Determining home directory failed (%s).\0A\00"
@errno = global i64 0
@.str.1 = [10 x i8] c".yanglint\00"
@.str.2 = [32 x i8] c"Memory allocation failed (%s).\0A\00"
@.str.3 = [6 x i8] c"%s/%s\00"
@R_OK = global i32 0
@X_OK = global i32 0
@ENOENT = global i64 0
@stdout = global i32 0
@.str.4 = [59 x i8] c"Configuration directory \22%s\22 does not exist, creating it.\0A\00"
@.str.5 = [54 x i8] c"Configuration directory \22%s\22 cannot be created (%s).\0A\00"
@.str.6 = [66 x i8] c"Configuration directory \22%s\22 exists but cannot be accessed (%s).\0A\00"
define i8* @get_yanglint_dir() {
%1 = tail call i32 (...) @getuid()
%2 = tail call %struct.passwd* @getpwuid(i32 %1)
%3 = icmp eq %struct.passwd* %2, null
br i1 %3, label %4, label %9
4: ; preds = %0
%5 = load i32, i32* @stderr
%6 = load i64, i64* @errno
%7 = tail call i8* @strerror(i64 %6)
%8 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %5, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i8* %7)
br label %48
9: ; preds = %0
%10 = getelementptr inbounds %struct.passwd, %struct.passwd* %2, i64 0, i32 0
%11 = load i8*, i8** %10
%12 = tail call i64 @strlen(i8* dereferenceable(1) %11)
%13 = add nsw i64 %12, 11
%14 = tail call i8* @malloc(i64 %13)
%15 = icmp eq i8* %14, null
br i1 %15, label %16, label %21
16: ; preds = %9
%17 = load i32, i32* @stderr
%18 = load i64, i64* @errno
%19 = tail call i8* @strerror(i64 %18)
%20 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), i8* %19)
br label %48
21: ; preds = %9
%22 = tail call i32 @sprintf(i8* %14, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* %11, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%23 = load i32, i32* @R_OK
%24 = load i32, i32* @X_OK
%25 = or i32 %24, %23
%26 = tail call i32 @access(i8* %14, i32 %25)
%27 = icmp eq i32 %26, -1
br i1 %27, label %28, label %48
28: ; preds = %21
%29 = load i64, i64* @errno
%30 = load i64, i64* @ENOENT
%31 = icmp eq i64 %29, %30
br i1 %31, label %32, label %43
32: ; preds = %28
%33 = load i32, i32* @stdout
%34 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %33, i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.4, i64 0, i64 0), i8* %14)
%35 = tail call i64 @mkdir(i8* %14, i32 448)
%36 = icmp eq i64 %35, 0
br i1 %36, label %48, label %37
37: ; preds = %32
%38 = load i32, i32* @stderr
%39 = load i64, i64* @errno
%40 = tail call i8* @strerror(i64 %39)
%41 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %38, i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.5, i64 0, i64 0), i8* %14, i8* %40)
%42 = tail call i32 @free(i8* %14)
br label %48
43: ; preds = %28
%44 = load i32, i32* @stderr
%45 = tail call i8* @strerror(i64 %29)
%46 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %44, i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str.6, i64 0, i64 0), i8* %14, i8* %45)
%47 = tail call i32 @free(i8* %14)
br label %48
48: ; preds = %21, %32, %43, %37, %16, %4
%49 = phi i8* [ null, %37 ], [ null, %43 ], [ null, %16 ], [ null, %4 ], [ %14, %32 ], [ %14, %21 ]
ret i8* %49
}