#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 */
char *getenv(char *);
int /*<<< orphan*/ snprintf(char *, int, char *, char *, char *);
char *get_path(int dirtype, char *file) {
  static char path[4095];
  char *ptr = NULL;
  char *dir, *env = NULL;
  switch (dirtype) {
  case 1:
    dir = "/var/local/iptraf";
    env = "IPTRAF_WORK_PATH";
    break;
  case 2:
    dir = "/var/log/iptraf";
    env = "IPTRAF_LOG_PATH";
    break;
  case 3:
    dir = "/usr/local/bin";
    break;
  case 4:
    dir = "/var/run/iptraf";
    break;
  default:
    return file;
  }
  if ((dirtype != 3) && (dirtype != 4) && (ptr = getenv(env)) != NULL)
    dir = ptr;
  if (dir == NULL || *dir == '\0')
    return file;
  snprintf(path, 4095 - 1, "%s/%s", dir, file);
  return path;
}


x86 assembly (clang, -O0):
<get_path>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0xc(%rbp)
mov    %rsi,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x30(%rbp)
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,%ecx
mov    %rcx,-0x38(%rbp)
sub    $0x3,%eax
ja     11be <get_path+0x9e>
mov    -0x38(%rbp),%rax
lea    0xea1(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xea1(%rip),%rax
mov    %rax,-0x28(%rbp)
lea    0xea8(%rip),%rax
mov    %rax,-0x30(%rbp)
jmp    11cb <get_path+0xab>
lea    0xea9(%rip),%rax
mov    %rax,-0x28(%rbp)
lea    0xeae(%rip),%rax
mov    %rax,-0x30(%rbp)
jmp    11cb <get_path+0xab>
lea    0xeae(%rip),%rax
mov    %rax,-0x28(%rbp)
jmp    11cb <get_path+0xab>
lea    0xead(%rip),%rax
mov    %rax,-0x28(%rbp)
jmp    11cb <get_path+0xab>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1251 <get_path+0x131>
cmpl   $0x3,-0xc(%rbp)
je     11fe <get_path+0xde>
cmpl   $0x4,-0xc(%rbp)
je     11fe <get_path+0xde>
mov    -0x30(%rbp),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     11fe <get_path+0xde>
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     1219 <get_path+0xf9>
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    1226 <get_path+0x106>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1251 <get_path+0x131>
mov    -0x28(%rbp),%rcx
mov    -0x18(%rbp),%r8
lea    0x2e0b(%rip),%rdi
mov    $0xffe,%esi
lea    0xe31(%rip),%rdx
call   1040 <snprintf@plt>
lea    0x2df3(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_path>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r15
mov    %edi,%eax
add    $0xffffffff,%eax
cmp    $0x3,%eax
ja     119a <get_path+0x7a>
lea    0xf1a(%rip),%rcx
lea    0xee2(%rip),%rdi
lea    0xec9(%rip),%rbx
lea    0xeb2(%rip),%rdx
movslq (%rdx,%rax,4),%rax
add    %rdx,%rax
jmp    *%rax
lea    0xee5(%rip),%rdi
lea    0xece(%rip),%rbx
call   1030 <getenv@plt>
test   %rax,%rax
cmovne %rax,%rbx
mov    %rbx,%rcx
cmpb   $0x0,(%rcx)
je     119a <get_path+0x7a>
lea    0x2ec0(%rip),%r14
lea    0xeeb(%rip),%rdx
mov    %r14,%rdi
mov    $0xffe,%esi
mov    %r15,%r8
call   1040 <snprintf@plt>
mov    %r14,%r15
mov    %r15,%rax
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xeb8(%rip),%rcx
cmpb   $0x0,(%rcx)
jne    1179 <get_path+0x59>
jmp    119a <get_path+0x7a>

LLVM IR (-O0):
@get_path.path = internal global [4095 x i8] zeroinitializer
@.str = [18 x i8] c"/var/local/iptraf\00"
@.str.1 = [17 x i8] c"IPTRAF_WORK_PATH\00"
@.str.2 = [16 x i8] c"/var/log/iptraf\00"
@.str.3 = [16 x i8] c"IPTRAF_LOG_PATH\00"
@.str.4 = [15 x i8] c"/usr/local/bin\00"
@.str.5 = [16 x i8] c"/var/run/iptraf\00"
@.str.6 = [6 x i8] c"%s/%s\00"
define i8* @get_path(i32 %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
store i32 %0, i32* %4
store i8* %1, i8** %5
store i8* null, i8** %6
store i8* null, i8** %8
%9 = load i32, i32* %4
switch i32 %9, label %14 [
i32 1, label %10
i32 2, label %11
i32 3, label %12
i32 4, label %13
]
10: ; preds = %2
store i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8** %7
store i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8** %8
br label %16
11: ; preds = %2
store i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i8** %7
store i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i8** %8
br label %16
12: ; preds = %2
store i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0), i8** %7
br label %16
13: ; preds = %2
store i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0), i8** %7
br label %16
14: ; preds = %2
%15 = load i8*, i8** %5
store i8* %15, i8** %3
br label %42
16: ; preds = %13, %12, %11, %10
%17 = load i32, i32* %4
%18 = icmp ne i32 %17, 3
br i1 %18, label %19, label %28
19: ; preds = %16
%20 = load i32, i32* %4
%21 = icmp ne i32 %20, 4
br i1 %21, label %22, label %28
22: ; preds = %19
%23 = load i8*, i8** %8
%24 = call i8* @getenv(i8* %23)
store i8* %24, i8** %6
%25 = icmp ne i8* %24, null
br i1 %25, label %26, label %28
26: ; preds = %22
%27 = load i8*, i8** %6
store i8* %27, i8** %7
br label %28
28: ; preds = %26, %22, %19, %16
%29 = load i8*, i8** %7
%30 = icmp eq i8* %29, null
br i1 %30, label %36, label %31
31: ; preds = %28
%32 = load i8*, i8** %7
%33 = load i8, i8* %32
%34 = sext i8 %33 to i32
%35 = icmp eq i32 %34, 0
br i1 %35, label %36, label %38
36: ; preds = %31, %28
%37 = load i8*, i8** %5
store i8* %37, i8** %3
br label %42
38: ; preds = %31
%39 = load i8*, i8** %7
%40 = load i8*, i8** %5
%41 = call i32 @snprintf(i8* getelementptr inbounds ([4095 x i8], [4095 x i8]* @get_path.path, i64 0, i64 0), i32 4094, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0), i8* %39, i8* %40)
store i8* getelementptr inbounds ([4095 x i8], [4095 x i8]* @get_path.path, i64 0, i64 0), i8** %3
br label %42
42: ; preds = %38, %36, %14
%43 = load i8*, i8** %3
ret i8* %43
}

LLVM IR (-O2):
@get_path.path = internal global [4095 x i8] zeroinitializer
@.str = [18 x i8] c"/var/local/iptraf\00"
@.str.1 = [17 x i8] c"IPTRAF_WORK_PATH\00"
@.str.2 = [16 x i8] c"/var/log/iptraf\00"
@.str.3 = [16 x i8] c"IPTRAF_LOG_PATH\00"
@.str.4 = [15 x i8] c"/usr/local/bin\00"
@.str.5 = [16 x i8] c"/var/run/iptraf\00"
@.str.6 = [6 x i8] c"%s/%s\00"
define i8* @get_path(i32 %0, i8* %1) {
switch i32 %0, label %17 [
i32 1, label %5
i32 2, label %3
i32 3, label %11
i32 4, label %4
]
3: ; preds = %2
br label %5
4: ; preds = %2
br label %11
5: ; preds = %2, %3
%6 = phi i8* [ getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), %2 ], [ getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), %3 ]
%7 = phi i8* [ getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), %2 ], [ getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), %3 ]
%8 = tail call i8* @getenv(i8* %7)
%9 = icmp eq i8* %8, null
%10 = select i1 %9, i8* %6, i8* %8
br label %11
11: ; preds = %4, %2, %5
%12 = phi i8* [ %10, %5 ], [ getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0), %4 ], [ getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0), %2 ]
%13 = load i8, i8* %12
%14 = icmp eq i8 %13, 0
br i1 %14, label %17, label %15
15: ; preds = %11
%16 = tail call i32 @snprintf(i8* getelementptr inbounds ([4095 x i8], [4095 x i8]* @get_path.path, i64 0, i64 0), i32 4094, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0), i8* %12, i8* %1)
br label %17
17: ; preds = %11, %2, %15
%18 = phi i8* [ getelementptr inbounds ([4095 x i8], [4095 x i8]* @get_path.path, i64 0, i64 0), %15 ], [ %1, %2 ], [ %1, %11 ]
ret i8* %18
}