#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*/ FILE;

/* Variables and functions */
char *alloca(scalar_t__);
int /*<<< orphan*/ *fopen(char *, char *);
char *getenv(char *);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
scalar_t__ strlen(char *);
FILE *config_open() {
  char *home = getenv("HOME");
  if (home != NULL) {
    FILE *f;
    char *path = alloca(strlen(home) +
                        strlen("/."
                               "mousepad.conf") +
                        1);
    strcpy(path, home);
    strcat(path, "/."
                 "mousepad.conf");
    if ((f = fopen(path, "r")) != NULL)
      return f;
  }
  return fopen("/etc/"
               "mousepad.conf",
               "r");
}


x86 assembly (clang, -O0):
<config_open>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
lea    0xe91(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11fd <config_open+0x9d>
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,-0x28(%rbp)
lea    0xe6e(%rip),%rdi
call   1050 <strlen@plt>
mov    -0x28(%rbp),%rdi
add    %rax,%rdi
add    $0x1,%rdi
call   1060 <alloca@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x20(%rbp),%rdi
lea    0xe3d(%rip),%rsi
call   1080 <strcat@plt>
mov    -0x20(%rbp),%rdi
lea    0xe3d(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     11f8 <config_open+0x98>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1214 <config_open+0xb4>
jmp    11fd <config_open+0x9d>
lea    0xe13(%rip),%rdi
lea    0xe0a(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<config_open>:
push   %r14
push   %rbx
push   %rax
lea    0xe95(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     11c2 <config_open+0x62>
mov    %rax,%rbx
mov    %rax,%rdi
call   1050 <strlen@plt>
lea    0x10(%rax),%rdi
call   1060 <alloca@plt>
mov    %rax,%r14
mov    %rax,%rdi
mov    %rbx,%rsi
call   1040 <strcpy@plt>
lea    0xe67(%rip),%rsi
mov    %r14,%rdi
call   1080 <strcat@plt>
lea    0xe68(%rip),%rsi
mov    %r14,%rdi
call   1070 <fopen@plt>
test   %rax,%rax
je     11c2 <config_open+0x62>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe4e(%rip),%rdi
lea    0xe45(%rip),%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1070 <fopen@plt>

LLVM IR (-O0):
@.str = [5 x i8] c"HOME\00"
@.str.1 = [16 x i8] c"/.mousepad.conf\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [19 x i8] c"/etc/mousepad.conf\00"
define i32* @config_open() {
%1 = alloca i32*
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i8*
%5 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
store i8* %5, i8** %2
%6 = load i8*, i8** %2
%7 = icmp ne i8* %6, null
br i1 %7, label %8, label %26
8: ; preds = %0
%9 = load i8*, i8** %2
%10 = call i64 @strlen(i8* %9)
%11 = call i64 @strlen(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
%12 = add nsw i64 %10, %11
%13 = add nsw i64 %12, 1
%14 = call i8* @alloca(i64 %13)
store i8* %14, i8** %4
%15 = load i8*, i8** %4
%16 = load i8*, i8** %2
%17 = call i32 @strcpy(i8* %15, i8* %16)
%18 = load i8*, i8** %4
%19 = call i32 @strcat(i8* %18, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
%20 = load i8*, i8** %4
%21 = call i32* @fopen(i8* %20, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %21, i32** %3
%22 = icmp ne i32* %21, null
br i1 %22, label %23, label %25
23: ; preds = %8
%24 = load i32*, i32** %3
store i32* %24, i32** %1
br label %28
25: ; preds = %8
br label %26
26: ; preds = %25, %0
%27 = call i32* @fopen(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %27, i32** %1
br label %28
28: ; preds = %26, %23
%29 = load i32*, i32** %1
ret i32* %29
}

LLVM IR (-O2):
@.str = [5 x i8] c"HOME\00"
@.str.1 = [16 x i8] c"/.mousepad.conf\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [19 x i8] c"/etc/mousepad.conf\00"
define noalias i32* @config_open() {
%1 = tail call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%2 = icmp eq i8* %1, null
br i1 %2, label %11, label %3
3: ; preds = %0
%4 = tail call i64 @strlen(i8* %1)
%5 = add nsw i64 %4, 16
%6 = tail call i8* @alloca(i64 %5)
%7 = tail call i32 @strcpy(i8* %6, i8* %1)
%8 = tail call i32 @strcat(i8* %6, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
%9 = tail call i32* @fopen(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %13
11: ; preds = %3, %0
%12 = tail call i32* @fopen(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %13
13: ; preds = %3, %11
%14 = phi i32* [ %12, %11 ], [ %9, %3 ]
ret i32* %14
}