#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 */
int BUFSIZ;
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
char *getenv(char *);
scalar_t__ isspace(char);
char *malloc(int);
int /*<<< orphan*/ pclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ *popen(char *, char *);
int /*<<< orphan*/ sprintf(char *, char *, char *, char *, char *);
char *strchr(char *, char);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
char *_DtCliSrvGetDtUserSession() {
  char *envVar = getenv("DTUSERSESSION");
  char *ret_envVar = NULL;
  if (envVar == NULL) {
    char pipedata[BUFSIZ];
    char logname_local[8];
    char *logname = getenv("LOGNAME");
    if (logname == NULL) {
      strcpy(logname_local, "generic");
      logname = logname_local;
    }
    {
      char screen[BUFSIZ];
      char *display = NULL;
      char *localDisplayVar = getenv("DISPLAY");
      if (localDisplayVar == NULL) {
        FILE *pp;
        display = pipedata;
        pp = popen("uname -n", "r");
        if (NULL == pp) {
          perror("uname -n");
          return NULL;
        }
        *display = 0;
        if (NULL == fgets(display, BUFSIZ, pp)) {
          perror("fgets() failed to read");
          return NULL;
        }
        while (isspace(display[strlen(display) - 1]))
          display[strlen(display) - 1] = 0;
        pclose(pp);
      } else {
        display = malloc(strlen(localDisplayVar) + 1);
        strcpy(display, localDisplayVar);
      }
      {
        char *s = strchr(display, ':');
        if (s && strlen(s) < (size_t)BUFSIZ) {
          strcpy(screen, s + 1);
          *s = 0;
          if ((s = strchr(screen, '.')) && *(s + 1) == '0')
            *s = 0;
        } else {
          strcpy(screen, "0");
        }
      }
      envVar = malloc(strlen(logname) + strlen(display) + strlen(screen) + 3);
      if (envVar)
        sprintf(envVar, "%s-%s-%s", logname, display, screen);
      return envVar;
    }
  }
  ret_envVar = malloc(strlen(envVar) + 1);
  if (ret_envVar)
    strcpy(ret_envVar, envVar);
  return ret_envVar;
}


x86 assembly (clang, -O0):
<_DtCliSrvGetDtUserSession>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
lea    0xe3e(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    14e5 <_DtCliSrvGetDtUserSession+0x335>
mov    0x2dfb(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x78(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x28(%rbp)
lea    0xdfd(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    123d <_DtCliSrvGetDtUserSession+0x8d>
lea    -0x30(%rbp),%rdi
lea    0xde6(%rip),%rsi
call   1040 <strcpy@plt>
lea    -0x30(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    0x2d9c(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x40(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x80(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x48(%rbp)
movq   $0x0,-0x50(%rbp)
lea    0xda6(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x58(%rbp)
cmpq   $0x0,-0x58(%rbp)
jne    1397 <_DtCliSrvGetDtUserSession+0x1e7>
mov    -0x78(%rbp),%rax
mov    %rax,-0x50(%rbp)
lea    0xd8b(%rip),%rdi
lea    0xd8d(%rip),%rsi
call   10b0 <popen@plt>
mov    %rax,-0x60(%rbp)
xor    %eax,%eax
cmp    -0x60(%rbp),%rax
jne    12d7 <_DtCliSrvGetDtUserSession+0x127>
lea    0xd68(%rip),%rdi
call   10c0 <perror@plt>
movq   $0x0,-0x8(%rbp)
movl   $0x1,-0x64(%rbp)
jmp    14d2 <_DtCliSrvGetDtUserSession+0x322>
mov    -0x50(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x50(%rbp),%rdi
mov    0x2cf7(%rip),%rax
mov    (%rax),%esi
mov    -0x60(%rbp),%rdx
call   1090 <fgets@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    1322 <_DtCliSrvGetDtUserSession+0x172>
lea    0xd28(%rip),%rdi
call   10c0 <perror@plt>
movq   $0x0,-0x8(%rbp)
movl   $0x1,-0x64(%rbp)
jmp    14d2 <_DtCliSrvGetDtUserSession+0x322>
jmp    1327 <_DtCliSrvGetDtUserSession+0x177>
mov    -0x50(%rbp),%rax
mov    %rax,-0x88(%rbp)
mov    -0x50(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x88(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%edi
call   1080 <isspace@plt>
cmp    $0x0,%rax
je     1389 <_DtCliSrvGetDtUserSession+0x1d9>
mov    -0x50(%rbp),%rax
mov    %rax,-0x90(%rbp)
mov    -0x50(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x90(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    1327 <_DtCliSrvGetDtUserSession+0x177>
mov    -0x60(%rbp),%rdi
call   1070 <pclose@plt>
jmp    13bb <_DtCliSrvGetDtUserSession+0x20b>
mov    -0x58(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%edi
add    $0x1,%edi
call   10a0 <malloc@plt>
mov    %rax,-0x50(%rbp)
mov    -0x50(%rbp),%rdi
mov    -0x58(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x50(%rbp),%rdi
mov    $0x3a,%esi
call   1060 <strchr@plt>
mov    %rax,-0x70(%rbp)
cmpq   $0x0,-0x70(%rbp)
je     1447 <_DtCliSrvGetDtUserSession+0x297>
mov    -0x70(%rbp),%rdi
call   1050 <strlen@plt>
cltq
mov    0x2bf6(%rip),%rcx
movslq (%rcx),%rcx
cmp    %rcx,%rax
jae    1447 <_DtCliSrvGetDtUserSession+0x297>
mov    -0x80(%rbp),%rdi
mov    -0x70(%rbp),%rsi
add    $0x1,%rsi
call   1040 <strcpy@plt>
mov    -0x80(%rbp),%rdi
mov    -0x70(%rbp),%rax
movb   $0x0,(%rax)
mov    $0x2e,%esi
call   1060 <strchr@plt>
mov    %rax,-0x70(%rbp)
cmp    $0x0,%rax
je     1442 <_DtCliSrvGetDtUserSession+0x292>
mov    -0x70(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x30,%eax
jne    1442 <_DtCliSrvGetDtUserSession+0x292>
mov    -0x70(%rbp),%rax
movb   $0x0,(%rax)
jmp    1457 <_DtCliSrvGetDtUserSession+0x2a7>
mov    -0x80(%rbp),%rdi
lea    0xbf6(%rip),%rsi
call   1040 <strcpy@plt>
mov    -0x38(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x98(%rbp)
mov    -0x50(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x80(%rbp),%rdi
mov    %eax,%ecx
mov    -0x98(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x94(%rbp)
call   1050 <strlen@plt>
mov    -0x94(%rbp),%edi
add    %eax,%edi
add    $0x3,%edi
call   10a0 <malloc@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     14c3 <_DtCliSrvGetDtUserSession+0x313>
mov    -0x80(%rbp),%r8
mov    -0x10(%rbp),%rdi
mov    -0x38(%rbp),%rdx
mov    -0x50(%rbp),%rcx
lea    0xb8c(%rip),%rsi
call   10d0 <sprintf@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
movl   $0x1,-0x64(%rbp)
mov    -0x40(%rbp),%rax
mov    %rax,%rsp
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
jmp    151c <_DtCliSrvGetDtUserSession+0x36c>
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%edi
add    $0x1,%edi
call   10a0 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1514 <_DtCliSrvGetDtUserSession+0x364>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_DtCliSrvGetDtUserSession>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
lea    0xe38(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     1201 <_DtCliSrvGetDtUserSession+0x51>
mov    %rax,%rbx
mov    %rax,%rdi
call   1050 <strlen@plt>
lea    0x1(%rax),%edi
call   10a0 <malloc@plt>
test   %rax,%rax
je     1295 <_DtCliSrvGetDtUserSession+0xe5>
mov    %rax,%r12
mov    %rax,%rdi
mov    %rbx,%rsi
call   1040 <strcpy@plt>
jmp    13ea <_DtCliSrvGetDtUserSession+0x23a>
mov    %rsp,-0x38(%rbp)
mov    0x2dd4(%rip),%r13
mov    0x0(%r13),%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
lea    0xde6(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%r14
test   %rax,%rax
jne    1248 <_DtCliSrvGetDtUserSession+0x98>
lea    -0x40(%rbp),%r14
lea    0xdd6(%rip),%rsi
mov    %r14,%rdi
call   1040 <strcpy@plt>
mov    %rsp,-0x30(%rbp)
mov    0x0(%r13),%eax
mov    %rsp,%r15
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r15
mov    %r15,%rsp
lea    0xdb6(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     129d <_DtCliSrvGetDtUserSession+0xed>
mov    %rax,%r12
mov    %rax,%rdi
call   1050 <strlen@plt>
lea    0x1(%rax),%edi
call   10a0 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r12,%rsi
call   1040 <strcpy@plt>
jmp    1312 <_DtCliSrvGetDtUserSession+0x162>
xor    %r12d,%r12d
jmp    13ea <_DtCliSrvGetDtUserSession+0x23a>
lea    0xd82(%rip),%rdi
lea    0xd84(%rip),%rsi
call   10b0 <popen@plt>
test   %rax,%rax
je     13c4 <_DtCliSrvGetDtUserSession+0x214>
mov    %rax,%r12
movb   $0x0,(%rbx)
mov    0x0(%r13),%esi
mov    %rbx,%rdi
mov    %rax,%rdx
call   1090 <fgets@plt>
test   %rax,%rax
je     13cd <_DtCliSrvGetDtUserSession+0x21d>
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1050 <strlen@plt>
cltq
movsbl -0x1(%rax,%rbx,1),%edi
call   1080 <isspace@plt>
test   %rax,%rax
je     130a <_DtCliSrvGetDtUserSession+0x15a>
mov    %rbx,%rdi
call   1050 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%rbx,1)
jmp    12e0 <_DtCliSrvGetDtUserSession+0x130>
mov    %r12,%rdi
call   1070 <pclose@plt>
mov    %rbx,%rdi
mov    $0x3a,%esi
call   1060 <strchr@plt>
test   %rax,%rax
je     1366 <_DtCliSrvGetDtUserSession+0x1b6>
mov    %rax,%r12
mov    %rax,%rdi
call   1050 <strlen@plt>
cmp    0x0(%r13),%eax
jae    1366 <_DtCliSrvGetDtUserSession+0x1b6>
mov    %r12,%rsi
add    $0x1,%rsi
mov    %r15,%rdi
call   1040 <strcpy@plt>
movb   $0x0,(%r12)
mov    %r15,%rdi
mov    $0x2e,%esi
call   1060 <strchr@plt>
test   %rax,%rax
je     1375 <_DtCliSrvGetDtUserSession+0x1c5>
cmpb   $0x30,0x1(%rax)
jne    1375 <_DtCliSrvGetDtUserSession+0x1c5>
movb   $0x0,(%rax)
jmp    1375 <_DtCliSrvGetDtUserSession+0x1c5>
lea    0xcdb(%rip),%rsi
mov    %r15,%rdi
call   1040 <strcpy@plt>
mov    %r14,%rdi
call   1050 <strlen@plt>
mov    %eax,%r12d
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %eax,%r13d
mov    %r15,%rdi
call   1050 <strlen@plt>
add    %r12d,%r13d
lea    (%rax,%r13,1),%edi
add    $0x3,%edi
call   10a0 <malloc@plt>
test   %rax,%rax
je     13d9 <_DtCliSrvGetDtUserSession+0x229>
mov    %rax,%r12
lea    0xc99(%rip),%rsi
mov    %rax,%rdi
mov    %r14,%rdx
mov    %rbx,%rcx
mov    %r15,%r8
call   10d0 <sprintf@plt>
jmp    13dc <_DtCliSrvGetDtUserSession+0x22c>
lea    0xc5b(%rip),%rdi
jmp    13d4 <_DtCliSrvGetDtUserSession+0x224>
lea    0xc5d(%rip),%rdi
call   10c0 <perror@plt>
xor    %r12d,%r12d
mov    -0x38(%rbp),%rax
mov    -0x30(%rbp),%rcx
mov    %rcx,%rsp
mov    %rax,%rsp
mov    %r12,%rax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [14 x i8] c"DTUSERSESSION\00"
@BUFSIZ = global i32 0
@.str.1 = [8 x i8] c"LOGNAME\00"
@.str.2 = [8 x i8] c"generic\00"
@.str.3 = [8 x i8] c"DISPLAY\00"
@.str.4 = [9 x i8] c"uname -n\00"
@.str.5 = [2 x i8] c"r\00"
@.str.6 = [23 x i8] c"fgets() failed to read\00"
@.str.7 = [2 x i8] c"0\00"
@.str.8 = [9 x i8] c"%s-%s-%s\00"
define i8* @_DtCliSrvGetDtUserSession() {
%1 = alloca i8*
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i64
%6 = alloca [8 x i8]
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i32*
%13 = alloca i32
%14 = alloca i8*
%15 = call i8* @getenv(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
store i8* %15, i8** %2
store i8* null, i8** %3
%16 = load i8*, i8** %2
%17 = icmp eq i8* %16, null
br i1 %17, label %18, label %134
18: ; preds = %0
%19 = load i32, i32* @BUFSIZ
%20 = zext i32 %19 to i64
%21 = call i8* @llvm.stacksave()
store i8* %21, i8** %4
%22 = alloca i8, i64 %20
store i64 %20, i64* %5
%23 = call i8* @getenv(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
store i8* %23, i8** %7
%24 = load i8*, i8** %7
%25 = icmp eq i8* %24, null
br i1 %25, label %26, label %30
26: ; preds = %18
%27 = getelementptr inbounds [8 x i8], [8 x i8]* %6, i64 0, i64 0
%28 = call i32 @strcpy(i8* %27, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%29 = getelementptr inbounds [8 x i8], [8 x i8]* %6, i64 0, i64 0
store i8* %29, i8** %7
br label %30
30: ; preds = %26, %18
%31 = load i32, i32* @BUFSIZ
%32 = zext i32 %31 to i64
%33 = call i8* @llvm.stacksave()
store i8* %33, i8** %8
%34 = alloca i8, i64 %32
store i64 %32, i64* %9
store i8* null, i8** %10
%35 = call i8* @getenv(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
store i8* %35, i8** %11
%36 = load i8*, i8** %11
%37 = icmp eq i8* %36, null
br i1 %37, label %38, label %74
38: ; preds = %30
store i8* %22, i8** %10
%39 = call i32* @popen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
store i32* %39, i32** %12
%40 = load i32*, i32** %12
%41 = icmp eq i32* null, %40
br i1 %41, label %42, label %44
42: ; preds = %38
%43 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0))
store i8* null, i8** %1
store i32 1, i32* %13
br label %131
44: ; preds = %38
%45 = load i8*, i8** %10
store i8 0, i8* %45
%46 = load i8*, i8** %10
%47 = load i32, i32* @BUFSIZ
%48 = load i32*, i32** %12
%49 = call i32* @fgets(i8* %46, i32 %47, i32* %48)
%50 = icmp eq i32* null, %49
br i1 %50, label %51, label %53
51: ; preds = %44
%52 = call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.6, i64 0, i64 0))
store i8* null, i8** %1
store i32 1, i32* %13
br label %131
53: ; preds = %44
br label %54
54: ; preds = %64, %53
%55 = load i8*, i8** %10
%56 = load i8*, i8** %10
%57 = call i32 @strlen(i8* %56)
%58 = sub nsw i32 %57, 1
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds i8, i8* %55, i64 %59
%61 = load i8, i8* %60
%62 = call i64 @isspace(i8 signext %61)
%63 = icmp ne i64 %62, 0
br i1 %63, label %64, label %71
64: ; preds = %54
%65 = load i8*, i8** %10
%66 = load i8*, i8** %10
%67 = call i32 @strlen(i8* %66)
%68 = sub nsw i32 %67, 1
%69 = sext i32 %68 to i64
%70 = getelementptr inbounds i8, i8* %65, i64 %69
store i8 0, i8* %70
br label %54
71: ; preds = %54
%72 = load i32*, i32** %12
%73 = call i32 @pclose(i32* %72)
br label %82
74: ; preds = %30
%75 = load i8*, i8** %11
%76 = call i32 @strlen(i8* %75)
%77 = add nsw i32 %76, 1
%78 = call i8* @malloc(i32 %77)
store i8* %78, i8** %10
%79 = load i8*, i8** %10
%80 = load i8*, i8** %11
%81 = call i32 @strcpy(i8* %79, i8* %80)
br label %82
82: ; preds = %74, %71
%83 = load i8*, i8** %10
%84 = call i8* @strchr(i8* %83, i8 signext 58)
store i8* %84, i8** %14
%85 = load i8*, i8** %14
%86 = icmp ne i8* %85, null
br i1 %86, label %87, label %110
87: ; preds = %82
%88 = load i8*, i8** %14
%89 = call i32 @strlen(i8* %88)
%90 = sext i32 %89 to i64
%91 = load i32, i32* @BUFSIZ
%92 = sext i32 %91 to i64
%93 = icmp ult i64 %90, %92
br i1 %93, label %94, label %110
94: ; preds = %87
%95 = load i8*, i8** %14
%96 = getelementptr inbounds i8, i8* %95, i64 1
%97 = call i32 @strcpy(i8* %34, i8* %96)
%98 = load i8*, i8** %14
store i8 0, i8* %98
%99 = call i8* @strchr(i8* %34, i8 signext 46)
store i8* %99, i8** %14
%100 = icmp ne i8* %99, null
br i1 %100, label %101, label %109
101: ; preds = %94
%102 = load i8*, i8** %14
%103 = getelementptr inbounds i8, i8* %102, i64 1
%104 = load i8, i8* %103
%105 = sext i8 %104 to i32
%106 = icmp eq i32 %105, 48
br i1 %106, label %107, label %109
107: ; preds = %101
%108 = load i8*, i8** %14
store i8 0, i8* %108
br label %109
109: ; preds = %107, %101, %94
br label %112
110: ; preds = %87, %82
%111 = call i32 @strcpy(i8* %34, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
br label %112
112: ; preds = %110, %109
%113 = load i8*, i8** %7
%114 = call i32 @strlen(i8* %113)
%115 = load i8*, i8** %10
%116 = call i32 @strlen(i8* %115)
%117 = add nsw i32 %114, %116
%118 = call i32 @strlen(i8* %34)
%119 = add nsw i32 %117, %118
%120 = add nsw i32 %119, 3
%121 = call i8* @malloc(i32 %120)
store i8* %121, i8** %2
%122 = load i8*, i8** %2
%123 = icmp ne i8* %122, null
br i1 %123, label %124, label %129
124: ; preds = %112
%125 = load i8*, i8** %2
%126 = load i8*, i8** %7
%127 = load i8*, i8** %10
%128 = call i32 @sprintf(i8* %125, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.8, i64 0, i64 0), i8* %126, i8* %127, i8* %34)
br label %129
129: ; preds = %124, %112
%130 = load i8*, i8** %2
store i8* %130, i8** %1
store i32 1, i32* %13
br label %131
131: ; preds = %129, %51, %42
%132 = load i8*, i8** %8
%133 = load i8*, i8** %4
br label %147
134: ; preds = %0
%135 = load i8*, i8** %2
%136 = call i32 @strlen(i8* %135)
%137 = add nsw i32 %136, 1
%138 = call i8* @malloc(i32 %137)
store i8* %138, i8** %3
%139 = load i8*, i8** %3
%140 = icmp ne i8* %139, null
br i1 %140, label %141, label %145
141: ; preds = %134
%142 = load i8*, i8** %3
%143 = load i8*, i8** %2
%144 = call i32 @strcpy(i8* %142, i8* %143)
br label %145
145: ; preds = %141, %134
%146 = load i8*, i8** %3
store i8* %146, i8** %1
br label %147
147: ; preds = %145, %131
%148 = load i8*, i8** %1
ret i8* %148
}

LLVM IR (-O2):
@.str = [14 x i8] c"DTUSERSESSION\00"
@BUFSIZ = global i32 0
@.str.1 = [8 x i8] c"LOGNAME\00"
@.str.2 = [8 x i8] c"generic\00"
@.str.3 = [8 x i8] c"DISPLAY\00"
@.str.4 = [9 x i8] c"uname -n\00"
@.str.5 = [2 x i8] c"r\00"
@.str.6 = [23 x i8] c"fgets() failed to read\00"
@.str.7 = [2 x i8] c"0\00"
@.str.8 = [9 x i8] c"%s-%s-%s\00"
define i8* @_DtCliSrvGetDtUserSession() {
%1 = alloca [8 x i8]
%2 = tail call i8* @getenv(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq i8* %2, null
br i1 %3, label %4, label %93
4: ; preds = %0
%5 = load i32, i32* @BUFSIZ
%6 = zext i32 %5 to i64
%7 = tail call i8* @llvm.stacksave()
%8 = alloca i8, i64 %6
%9 = getelementptr inbounds [8 x i8], [8 x i8]* %1, i64 0, i64 0
%10 = tail call i8* @getenv(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%11 = icmp eq i8* %10, null
br i1 %11, label %12, label %14
12: ; preds = %4
%13 = call i32 @strcpy(i8* %9, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
br label %14
14: ; preds = %12, %4
%15 = phi i8* [ %9, %12 ], [ %10, %4 ]
%16 = load i32, i32* @BUFSIZ
%17 = zext i32 %16 to i64
%18 = call i8* @llvm.stacksave()
%19 = alloca i8, i64 %17
%20 = call i8* @getenv(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
%21 = icmp eq i8* %20, null
br i1 %21, label %22, label %55
22: ; preds = %14
%23 = call i32* @popen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%24 = icmp eq i32* %23, null
br i1 %24, label %25, label %27
25: ; preds = %22
%26 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0))
br label %91
27: ; preds = %22
store i8 0, i8* %8
%28 = load i32, i32* @BUFSIZ
%29 = call i32* @fgets(i8* %8, i32 %28, i32* %23)
%30 = icmp eq i32* %29, null
br i1 %30, label %39, label %31
31: ; preds = %27
%32 = call i32 @strlen(i8* %8)
%33 = add nsw i32 %32, -1
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i8, i8* %8, i64 %34
%36 = load i8, i8* %35
%37 = call i64 @isspace(i8 signext %36)
%38 = icmp eq i64 %37, 0
br i1 %38, label %53, label %41
39: ; preds = %27
%40 = call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.6, i64 0, i64 0))
br label %91
41: ; preds = %31, %41
%42 = call i32 @strlen(i8* %8)
%43 = add nsw i32 %42, -1
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds i8, i8* %8, i64 %44
store i8 0, i8* %45
%46 = call i32 @strlen(i8* %8)
%47 = add nsw i32 %46, -1
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds i8, i8* %8, i64 %48
%50 = load i8, i8* %49
%51 = call i64 @isspace(i8 signext %50)
%52 = icmp eq i64 %51, 0
br i1 %52, label %53, label %41
53: ; preds = %41, %31
%54 = call i32 @pclose(i32* %23)
br label %60
55: ; preds = %14
%56 = call i32 @strlen(i8* %20)
%57 = add nsw i32 %56, 1
%58 = call i8* @malloc(i32 %57)
%59 = call i32 @strcpy(i8* %58, i8* %20)
br label %60
60: ; preds = %53, %55
%61 = phi i8* [ %58, %55 ], [ %8, %53 ]
%62 = call i8* @strchr(i8* dereferenceable(1) %61, i8 signext 58)
%63 = icmp eq i8* %62, null
br i1 %63, label %78, label %64
64: ; preds = %60
%65 = call i32 @strlen(i8* %62)
%66 = load i32, i32* @BUFSIZ
%67 = icmp ult i32 %65, %66
br i1 %67, label %68, label %78
68: ; preds = %64
%69 = getelementptr inbounds i8, i8* %62, i64 1
%70 = call i32 @strcpy(i8* %19, i8* %69)
store i8 0, i8* %62
%71 = call i8* @strchr(i8* %19, i8 signext 46)
%72 = icmp eq i8* %71, null
br i1 %72, label %80, label %73
73: ; preds = %68
%74 = getelementptr inbounds i8, i8* %71, i64 1
%75 = load i8, i8* %74
%76 = icmp eq i8 %75, 48
br i1 %76, label %77, label %80
77: ; preds = %73
store i8 0, i8* %71
br label %80
78: ; preds = %64, %60
%79 = call i32 @strcpy(i8* %19, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
br label %80
80: ; preds = %68, %73, %77, %78
%81 = call i32 @strlen(i8* %15)
%82 = call i32 @strlen(i8* %61)
%83 = call i32 @strlen(i8* %19)
%84 = add i32 %81, 3
%85 = add i32 %84, %82
%86 = add i32 %85, %83
%87 = call i8* @malloc(i32 %86)
%88 = icmp eq i8* %87, null
br i1 %88, label %91, label %89
89: ; preds = %80
%90 = call i32 @sprintf(i8* %87, i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.8, i64 0, i64 0), i8* %15, i8* %61, i8* %19)
br label %91
91: ; preds = %80, %89, %25, %39
%92 = phi i8* [ null, %39 ], [ null, %25 ], [ %87, %89 ], [ null, %80 ]
br label %100
93: ; preds = %0
%94 = tail call i32 @strlen(i8* %2)
%95 = add nsw i32 %94, 1
%96 = tail call i8* @malloc(i32 %95)
%97 = icmp eq i8* %96, null
br i1 %97, label %100, label %98
98: ; preds = %93
%99 = tail call i32 @strcpy(i8* %96, i8* %2)
br label %100
100: ; preds = %93, %98, %91
%101 = phi i8* [ %92, %91 ], [ %96, %98 ], [ null, %93 ]
ret i8* %101
}