#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__ EISDIR;
int /*<<< orphan*/ O_RDWR;
scalar_t__ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, char *);
struct passwd *getpwuid(int /*<<< orphan*/);
int /*<<< orphan*/ getuid();
char *my_strinit(scalar_t__);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
char *strcat(char *, char *);
scalar_t__ strlen(char *);
int open_rc(char *progname) {
  int rc;
  char *path;
  struct passwd *pwd;
  pwd = getpwuid(getuid());
  path = my_strinit(strlen(pwd->pw_dir) + strlen(".42shrc") + 2);
  path = strcat(path, pwd->pw_dir);
  path = strcat(path, "/");
  path = strcat(path, ".42shrc");
  rc = open(path, O_RDWR);
  if (errno == EISDIR)
    fprintf(stderr, "%s: %s: Is a directory\n", progname, path);
  return (rc);
}


x86 assembly (clang, -O0):
<open_rc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x0,%al
call   1050 <getuid@plt>
mov    %eax,%edi
call   1030 <getpwuid@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    (%rax),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x28(%rbp)
lea    0xe5b(%rip),%rdi
call   1040 <strlen@plt>
mov    -0x28(%rbp),%rdi
add    %rax,%rdi
add    $0x2,%rdi
call   1070 <my_strinit@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rax
mov    (%rax),%rsi
call   1090 <strcat@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe2b(%rip),%rsi
call   1090 <strcat@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe0f(%rip),%rsi
call   1090 <strcat@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    0x2de3(%rip),%rax
mov    (%rax),%esi
call   1080 <open@plt>
mov    %eax,-0xc(%rbp)
mov    0x2db2(%rip),%rax
mov    (%rax),%rax
mov    0x2dc0(%rip),%rcx
cmp    (%rcx),%rax
jne    1246 <open_rc+0xd6>
mov    0x2da0(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
mov    -0x18(%rbp),%rcx
lea    0xdc9(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0xc(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<open_rc>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%r14
xor    %eax,%eax
call   1050 <getuid@plt>
mov    %eax,%edi
call   1030 <getpwuid@plt>
mov    %rax,%rbp
mov    (%rax),%rdi
call   1040 <strlen@plt>
lea    0x9(%rax),%rdi
call   1070 <my_strinit@plt>
mov    %rax,%rbx
mov    0x0(%rbp),%rsi
mov    %rax,%rdi
call   1090 <strcat@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
movw   $0x2f,(%rbx,%rax,1)
mov    %rbx,%rdi
call   1040 <strlen@plt>
movabs $0x6372687332342e,%rcx
mov    %rcx,(%rbx,%rax,1)
mov    0x2e15(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1080 <open@plt>
mov    %eax,%ebp
mov    0x2de2(%rip),%rax
mov    (%rax),%rax
mov    0x2df0(%rip),%rcx
cmp    (%rcx),%rax
jne    1210 <open_rc+0xa0>
mov    0x2dd4(%rip),%rax
mov    (%rax),%edi
lea    0xdfb(%rip),%rsi
mov    %r14,%rdx
mov    %rbx,%rcx
call   1060 <fprintf@plt>
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.passwd = type { i8* }
@.str = [8 x i8] c".42shrc\00"
@.str.1 = [2 x i8] c"/\00"
@O_RDWR = global i32 0
@errno = global i64 0
@EISDIR = global i64 0
@stderr = global i32 0
@.str.2 = [24 x i8] c"%s: %s: Is a directory\0A\00"
define i32 @open_rc(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i8*
%5 = alloca %struct.passwd*
store i8* %0, i8** %2
%6 = call i32 (...) @getuid()
%7 = call %struct.passwd* @getpwuid(i32 %6)
store %struct.passwd* %7, %struct.passwd** %5
%8 = load %struct.passwd*, %struct.passwd** %5
%9 = getelementptr inbounds %struct.passwd, %struct.passwd* %8, i32 0, i32 0
%10 = load i8*, i8** %9
%11 = call i64 @strlen(i8* %10)
%12 = call i64 @strlen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%13 = add nsw i64 %11, %12
%14 = add nsw i64 %13, 2
%15 = call i8* @my_strinit(i64 %14)
store i8* %15, i8** %4
%16 = load i8*, i8** %4
%17 = load %struct.passwd*, %struct.passwd** %5
%18 = getelementptr inbounds %struct.passwd, %struct.passwd* %17, i32 0, i32 0
%19 = load i8*, i8** %18
%20 = call i8* @strcat(i8* %16, i8* %19)
store i8* %20, i8** %4
%21 = load i8*, i8** %4
%22 = call i8* @strcat(i8* %21, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i8* %22, i8** %4
%23 = load i8*, i8** %4
%24 = call i8* @strcat(i8* %23, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
store i8* %24, i8** %4
%25 = load i8*, i8** %4
%26 = load i32, i32* @O_RDWR
%27 = call i32 @open(i8* %25, i32 %26)
store i32 %27, i32* %3
%28 = load i64, i64* @errno
%29 = load i64, i64* @EISDIR
%30 = icmp eq i64 %28, %29
br i1 %30, label %31, label %36
31: ; preds = %1
%32 = load i32, i32* @stderr
%33 = load i8*, i8** %2
%34 = load i8*, i8** %4
%35 = call i32 @fprintf(i32 %32, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i8* %33, i8* %34)
br label %36
36: ; preds = %31, %1
%37 = load i32, i32* %3
ret i32 %37
}

LLVM IR (-O2):
%struct.passwd = type { i8* }
@O_RDWR = global i32 0
@errno = global i64 0
@EISDIR = global i64 0
@stderr = global i32 0
@.str.2 = [24 x i8] c"%s: %s: Is a directory\0A\00"
define i32 @open_rc(i8* %0) {
%2 = tail call i32 (...) @getuid()
%3 = tail call %struct.passwd* @getpwuid(i32 %2)
%4 = getelementptr inbounds %struct.passwd, %struct.passwd* %3, i64 0, i32 0
%5 = load i8*, i8** %4
%6 = tail call i64 @strlen(i8* dereferenceable(1) %5)
%7 = add nsw i64 %6, 9
%8 = tail call i8* @my_strinit(i64 %7)
%9 = load i8*, i8** %4
%10 = tail call i8* @strcat(i8* dereferenceable(1) %8, i8* dereferenceable(1) %9)
%11 = tail call i64 @strlen(i8* dereferenceable(1) %8)
%12 = getelementptr i8, i8* %8, i64 %11
%13 = bitcast i8* %12 to i16*
store i16 47, i16* %13
%14 = tail call i64 @strlen(i8* dereferenceable(1) %8)
%15 = getelementptr i8, i8* %8, i64 %14
%16 = bitcast i8* %15 to i64*
store i64 27991815629190190, i64* %16
%17 = load i32, i32* @O_RDWR
%18 = tail call i32 @open(i8* %8, i32 %17)
%19 = load i64, i64* @errno
%20 = load i64, i64* @EISDIR
%21 = icmp eq i64 %19, %20
br i1 %21, label %22, label %25
22: ; preds = %1
%23 = load i32, i32* @stderr
%24 = tail call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i8* %0, i8* %8)
br label %25
25: ; preds = %22, %1
ret i32 %18
}