#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 *);
scalar_t__ strlen(char *);
int /*<<< orphan*/ strncat(char *, char *, int);
void GetFolderPathForID(int folderID, char *path, int maxPath) {
  char *s = NULL;
  path[0] = 0;
  s = getenv("HOME");
  if ((s == NULL) || (strlen(s) == 0))
    return;
  strncat(path, s, maxPath);
  if (folderID == 1)
    return;
  if (folderID == 2)
    strncat(path, "/Desktop", maxPath);
  if (folderID == 4)
    strncat(path, "/Pictures", maxPath);
  if (folderID == 5)
    strncat(path, "/Music", maxPath);
  if (folderID == 3) {
    s = getenv("SUGAR_ACTIVITY_ROOT");
    if (s != NULL) {
      strncat(path, s, maxPath);
      strncat(path, "/data", maxPath);
    } else {
      strncat(path, "/Documents", maxPath);
    }
  }
}


x86 assembly (clang, -O0):
<GetFolderPathForID>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
lea    0xea8(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     117f <GetFolderPathForID+0x4f>
mov    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x0,%rax
jne    1184 <GetFolderPathForID+0x54>
jmp    125f <GetFolderPathForID+0x12f>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1050 <strncat@plt>
cmpl   $0x1,-0x4(%rbp)
jne    11a3 <GetFolderPathForID+0x73>
jmp    125f <GetFolderPathForID+0x12f>
cmpl   $0x2,-0x4(%rbp)
jne    11c0 <GetFolderPathForID+0x90>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%edx
lea    0xe4a(%rip),%rsi
call   1050 <strncat@plt>
cmpl   $0x4,-0x4(%rbp)
jne    11dd <GetFolderPathForID+0xad>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%edx
lea    0xe36(%rip),%rsi
call   1050 <strncat@plt>
cmpl   $0x5,-0x4(%rbp)
jne    11fa <GetFolderPathForID+0xca>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%edx
lea    0xe23(%rip),%rsi
call   1050 <strncat@plt>
cmpl   $0x3,-0x4(%rbp)
jne    125f <GetFolderPathForID+0x12f>
lea    0xe14(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1247 <GetFolderPathForID+0x117>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1050 <strncat@plt>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%edx
lea    0xdf6(%rip),%rsi
call   1050 <strncat@plt>
jmp    125a <GetFolderPathForID+0x12a>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%edx
lea    0xde4(%rip),%rsi
call   1050 <strncat@plt>
jmp    125f <GetFolderPathForID+0x12f>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<GetFolderPathForID>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%r14d
mov    %rsi,%rbx
mov    %edi,%ebp
movb   $0x0,(%rsi)
lea    0xeda(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     119a <GetFolderPathForID+0x7a>
cmpb   $0x0,(%rax)
je     119a <GetFolderPathForID+0x7a>
mov    %rbx,%rdi
mov    %rax,%rsi
mov    %r14d,%edx
call   1040 <strncat@plt>
add    $0xfffffffe,%ebp
cmp    $0x3,%ebp
ja     119a <GetFolderPathForID+0x7a>
lea    0xeb3(%rip),%rsi
lea    0xe97(%rip),%rax
movslq (%rax,%rbp,4),%rcx
add    %rax,%rcx
jmp    *%rcx
lea    0xeb6(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     11b1 <GetFolderPathForID+0x91>
mov    %rbx,%rdi
mov    %rax,%rsi
mov    %r14d,%edx
call   1040 <strncat@plt>
lea    0xeab(%rip),%rsi
jmp    11b8 <GetFolderPathForID+0x98>
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xe78(%rip),%rsi
jmp    11b8 <GetFolderPathForID+0x98>
lea    0xe79(%rip),%rsi
jmp    11b8 <GetFolderPathForID+0x98>
lea    0xe91(%rip),%rsi
mov    %rbx,%rdi
mov    %r14d,%edx
pop    %rbx
pop    %r14
pop    %rbp
jmp    1040 <strncat@plt>

LLVM IR (-O0):
@.str = [5 x i8] c"HOME\00"
@.str.1 = [9 x i8] c"/Desktop\00"
@.str.2 = [10 x i8] c"/Pictures\00"
@.str.3 = [7 x i8] c"/Music\00"
@.str.4 = [20 x i8] c"SUGAR_ACTIVITY_ROOT\00"
@.str.5 = [6 x i8] c"/data\00"
@.str.6 = [11 x i8] c"/Documents\00"
define void @GetFolderPathForID(i32 %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
store i32 %0, i32* %4
store i8* %1, i8** %5
store i32 %2, i32* %6
store i8* null, i8** %7
%8 = load i8*, i8** %5
%9 = getelementptr inbounds i8, i8* %8, i64 0
store i8 0, i8* %9
%10 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
store i8* %10, i8** %7
%11 = load i8*, i8** %7
%12 = icmp eq i8* %11, null
br i1 %12, label %17, label %13
13: ; preds = %3
%14 = load i8*, i8** %7
%15 = call i64 @strlen(i8* %14)
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %18
17: ; preds = %13, %3
br label %67
18: ; preds = %13
%19 = load i8*, i8** %5
%20 = load i8*, i8** %7
%21 = load i32, i32* %6
%22 = call i32 @strncat(i8* %19, i8* %20, i32 %21)
%23 = load i32, i32* %4
%24 = icmp eq i32 %23, 1
br i1 %24, label %25, label %26
25: ; preds = %18
br label %67
26: ; preds = %18
%27 = load i32, i32* %4
%28 = icmp eq i32 %27, 2
br i1 %28, label %29, label %33
29: ; preds = %26
%30 = load i8*, i8** %5
%31 = load i32, i32* %6
%32 = call i32 @strncat(i8* %30, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %31)
br label %33
33: ; preds = %29, %26
%34 = load i32, i32* %4
%35 = icmp eq i32 %34, 4
br i1 %35, label %36, label %40
36: ; preds = %33
%37 = load i8*, i8** %5
%38 = load i32, i32* %6
%39 = call i32 @strncat(i8* %37, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i32 %38)
br label %40
40: ; preds = %36, %33
%41 = load i32, i32* %4
%42 = icmp eq i32 %41, 5
br i1 %42, label %43, label %47
43: ; preds = %40
%44 = load i8*, i8** %5
%45 = load i32, i32* %6
%46 = call i32 @strncat(i8* %44, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 %45)
br label %47
47: ; preds = %43, %40
%48 = load i32, i32* %4
%49 = icmp eq i32 %48, 3
br i1 %49, label %50, label %67
50: ; preds = %47
%51 = call i8* @getenv(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0))
store i8* %51, i8** %7
%52 = load i8*, i8** %7
%53 = icmp ne i8* %52, null
br i1 %53, label %54, label %62
54: ; preds = %50
%55 = load i8*, i8** %5
%56 = load i8*, i8** %7
%57 = load i32, i32* %6
%58 = call i32 @strncat(i8* %55, i8* %56, i32 %57)
%59 = load i8*, i8** %5
%60 = load i32, i32* %6
%61 = call i32 @strncat(i8* %59, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i32 %60)
br label %66
62: ; preds = %50
%63 = load i8*, i8** %5
%64 = load i32, i32* %6
%65 = call i32 @strncat(i8* %63, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0), i32 %64)
br label %66
66: ; preds = %62, %54
br label %67
67: ; preds = %17, %25, %66, %47
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c"HOME\00"
@.str.1 = [9 x i8] c"/Desktop\00"
@.str.2 = [10 x i8] c"/Pictures\00"
@.str.3 = [7 x i8] c"/Music\00"
@.str.4 = [20 x i8] c"SUGAR_ACTIVITY_ROOT\00"
@.str.5 = [6 x i8] c"/data\00"
@.str.6 = [11 x i8] c"/Documents\00"
define void @GetFolderPathForID(i32 %0, i8* %1, i32 %2) {
store i8 0, i8* %1
%4 = tail call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i8* %4, null
br i1 %5, label %21, label %6
6: ; preds = %3
%7 = load i8, i8* %4
%8 = icmp eq i8 %7, 0
br i1 %8, label %21, label %9
9: ; preds = %6
%10 = tail call i32 @strncat(i8* %1, i8* %4, i32 %2)
switch i32 %0, label %21 [
i32 3, label %13
i32 2, label %18
i32 4, label %11
i32 5, label %12
]
11: ; preds = %9
br label %18
12: ; preds = %9
br label %18
13: ; preds = %9
%14 = tail call i8* @getenv(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0))
%15 = icmp eq i8* %14, null
br i1 %15, label %18, label %16
16: ; preds = %13
%17 = tail call i32 @strncat(i8* %1, i8* %14, i32 %2)
br label %18
18: ; preds = %13, %9, %16, %11, %12
%19 = phi i8* [ getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), %12 ], [ getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), %11 ], [ getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), %16 ], [ getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), %9 ], [ getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0), %13 ]
%20 = tail call i32 @strncat(i8* %1, i8* %19, i32 %2)
br label %21
21: ; preds = %18, %9, %3, %6
ret void
}