#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*/ EXIT_FAILURE;
char *alloc(int, char);
int /*<<< orphan*/ assert(char *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
char *getenv(char *);
int snprintf(char *, int, char *, char *, char *);
int /*<<< orphan*/ stderr;
int strlen(char *);
char *get_pattern_file(int argc, char **argv) {
  char *e = getenv("GLN_FILTER_FILE");
  if (e != NULL) {
    int len = strlen(e);
    char *path, *home;
    if (len > 1 && e[0] == '~' && e[1] == '/') {
      home = getenv("HOME");
      assert(home);
      len = strlen(e) + strlen(home) + 1;
      path = alloc(len, 'p');
      if (len <= snprintf(path, len, "%s/%s", home, e + 2)) {
        fprintf(stderr, "snprintf error\n");
        exit(EXIT_FAILURE);
      }
      return path;
    }
    return e;
  }
  if (argc > 1)
    return argv[1];
  return NULL;
}


x86 assembly (clang, -O0):
<get_pattern_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0xc(%rbp)
mov    %rsi,-0x18(%rbp)
lea    0xe7a(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     128c <get_pattern_file+0x11c>
mov    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x1,-0x24(%rbp)
jle    127f <get_pattern_file+0x10f>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x7e,%eax
jne    127f <get_pattern_file+0x10f>
mov    -0x20(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x2f,%eax
jne    127f <get_pattern_file+0x10f>
lea    0xe38(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
call   1060 <assert@plt>
mov    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x40(%rbp)
mov    -0x38(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x40(%rbp),%eax
add    %ecx,%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%edi
mov    $0x70,%esi
call   1080 <alloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x24(%rbp),%esi
mov    -0x38(%rbp),%rcx
mov    -0x20(%rbp),%r8
add    $0x2,%r8
lea    0xdd8(%rip),%rdx
call   1050 <snprintf@plt>
mov    %eax,%ecx
mov    -0x3c(%rbp),%eax
cmp    %ecx,%eax
jg     1272 <get_pattern_file+0x102>
mov    0x2d8a(%rip),%rax
mov    (%rax),%edi
lea    0xdbc(%rip),%rsi
call   1070 <fprintf@plt>
mov    0x2d6d(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    12af <get_pattern_file+0x13f>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    12af <get_pattern_file+0x13f>
cmpl   $0x1,-0xc(%rbp)
jle    12a7 <get_pattern_file+0x137>
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x8(%rbp)
jmp    12af <get_pattern_file+0x13f>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_pattern_file>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r14
mov    %edi,%ebp
lea    0xe7c(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     1240 <get_pattern_file+0xd0>
mov    %rax,%rbx
mov    %rax,%rdi
call   1040 <strlen@plt>
cmp    $0x2,%eax
jl     124d <get_pattern_file+0xdd>
cmpb   $0x7e,(%rbx)
jne    124d <get_pattern_file+0xdd>
cmpb   $0x2f,0x1(%rbx)
jne    124d <get_pattern_file+0xdd>
lea    0xe50(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%r14
mov    %rax,%rdi
call   1060 <assert@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebp
mov    %r14,%rdi
call   1040 <strlen@plt>
lea    (%rax,%rbp,1),%r12d
add    %eax,%ebp
add    $0x1,%ebp
mov    %ebp,%edi
mov    $0x70,%esi
call   1080 <alloc@plt>
mov    %rax,%r15
add    $0x2,%rbx
lea    0xe10(%rip),%rdx
mov    %rax,%rdi
mov    %ebp,%esi
mov    %r14,%rcx
mov    %rbx,%r8
call   1050 <snprintf@plt>
mov    %r15,%rbx
cmp    %eax,%r12d
jge    124d <get_pattern_file+0xdd>
mov    0x2dbc(%rip),%rax
mov    (%rax),%edi
lea    0xdee(%rip),%rsi
call   1070 <fprintf@plt>
mov    0x2d9f(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
cmp    $0x2,%ebp
jl     124b <get_pattern_file+0xdb>
mov    0x8(%r14),%rbx
jmp    124d <get_pattern_file+0xdd>
xor    %ebx,%ebx
mov    %rbx,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [16 x i8] c"GLN_FILTER_FILE\00"
@.str.1 = [5 x i8] c"HOME\00"
@.str.2 = [6 x i8] c"%s/%s\00"
@stderr = global i32 0
@.str.3 = [16 x i8] c"snprintf error\0A\00"
@EXIT_FAILURE = global i32 0
define i8* @get_pattern_file(i32 %0, i8** %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i8*
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = call i8* @getenv(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
store i8* %10, i8** %6
%11 = load i8*, i8** %6
%12 = icmp ne i8* %11, null
br i1 %12, label %13, label %59
13: ; preds = %2
%14 = load i8*, i8** %6
%15 = call i32 @strlen(i8* %14)
store i32 %15, i32* %7
%16 = load i32, i32* %7
%17 = icmp sgt i32 %16, 1
br i1 %17, label %18, label %57
18: ; preds = %13
%19 = load i8*, i8** %6
%20 = getelementptr inbounds i8, i8* %19, i64 0
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
%23 = icmp eq i32 %22, 126
br i1 %23, label %24, label %57
24: ; preds = %18
%25 = load i8*, i8** %6
%26 = getelementptr inbounds i8, i8* %25, i64 1
%27 = load i8, i8* %26
%28 = sext i8 %27 to i32
%29 = icmp eq i32 %28, 47
br i1 %29, label %30, label %57
30: ; preds = %24
%31 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
store i8* %31, i8** %9
%32 = load i8*, i8** %9
%33 = call i32 @assert(i8* %32)
%34 = load i8*, i8** %6
%35 = call i32 @strlen(i8* %34)
%36 = load i8*, i8** %9
%37 = call i32 @strlen(i8* %36)
%38 = add nsw i32 %35, %37
%39 = add nsw i32 %38, 1
store i32 %39, i32* %7
%40 = load i32, i32* %7
%41 = call i8* @alloc(i32 %40, i8 signext 112)
store i8* %41, i8** %8
%42 = load i32, i32* %7
%43 = load i8*, i8** %8
%44 = load i32, i32* %7
%45 = load i8*, i8** %9
%46 = load i8*, i8** %6
%47 = getelementptr inbounds i8, i8* %46, i64 2
%48 = call i32 @snprintf(i8* %43, i32 %44, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %45, i8* %47)
%49 = icmp sle i32 %42, %48
br i1 %49, label %50, label %55
50: ; preds = %30
%51 = load i32, i32* @stderr
%52 = call i32 @fprintf(i32 %51, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
%53 = load i32, i32* @EXIT_FAILURE
%54 = call i32 @exit(i32 %53)
unreachable
55: ; preds = %30
%56 = load i8*, i8** %8
store i8* %56, i8** %3
br label %67
57: ; preds = %24, %18, %13
%58 = load i8*, i8** %6
store i8* %58, i8** %3
br label %67
59: ; preds = %2
%60 = load i32, i32* %4
%61 = icmp sgt i32 %60, 1
br i1 %61, label %62, label %66
62: ; preds = %59
%63 = load i8**, i8*** %5
%64 = getelementptr inbounds i8*, i8** %63, i64 1
%65 = load i8*, i8** %64
store i8* %65, i8** %3
br label %67
66: ; preds = %59
store i8* null, i8** %3
br label %67
67: ; preds = %66, %62, %57, %55
%68 = load i8*, i8** %3
ret i8* %68
}

LLVM IR (-O2):
@.str = [16 x i8] c"GLN_FILTER_FILE\00"
@.str.1 = [5 x i8] c"HOME\00"
@.str.2 = [6 x i8] c"%s/%s\00"
@stderr = global i32 0
@.str.3 = [16 x i8] c"snprintf error\0A\00"
@EXIT_FAILURE = global i32 0
define i8* @get_pattern_file(i32 %0, i8** nocapture %1) {
%3 = tail call i8* @getenv(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i8* %3, null
br i1 %4, label %31, label %5
5: ; preds = %2
%6 = tail call i32 @strlen(i8* %3)
%7 = icmp sgt i32 %6, 1
br i1 %7, label %8, label %36
8: ; preds = %5
%9 = load i8, i8* %3
%10 = icmp eq i8 %9, 126
br i1 %10, label %11, label %36
11: ; preds = %8
%12 = getelementptr inbounds i8, i8* %3, i64 1
%13 = load i8, i8* %12
%14 = icmp eq i8 %13, 47
br i1 %14, label %15, label %36
15: ; preds = %11
%16 = tail call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%17 = tail call i32 @assert(i8* %16)
%18 = tail call i32 @strlen(i8* %3)
%19 = tail call i32 @strlen(i8* %16)
%20 = add nsw i32 %19, %18
%21 = add nsw i32 %20, 1
%22 = tail call i8* @alloc(i32 %21, i8 signext 112)
%23 = getelementptr inbounds i8, i8* %3, i64 2
%24 = tail call i32 @snprintf(i8* %22, i32 %21, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %16, i8* %23)
%25 = icmp slt i32 %20, %24
br i1 %25, label %26, label %36
26: ; preds = %15
%27 = load i32, i32* @stderr
%28 = tail call i32 @fprintf(i32 %27, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
%29 = load i32, i32* @EXIT_FAILURE
%30 = tail call i32 @exit(i32 %29)
unreachable
31: ; preds = %2
%32 = icmp sgt i32 %0, 1
br i1 %32, label %33, label %36
33: ; preds = %31
%34 = getelementptr inbounds i8*, i8** %1, i64 1
%35 = load i8*, i8** %34
br label %36
36: ; preds = %31, %15, %11, %8, %5, %33
%37 = phi i8* [ %35, %33 ], [ %22, %15 ], [ %3, %11 ], [ %3, %8 ], [ %3, %5 ], [ null, %31 ]
ret i8* %37
}