#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 *dagpath(char *path, char *temp, int tempsize) {
  if (!getenv("DAG"))
    return path;
  snprintf(temp, tempsize - 1, "%s/%s", getenv("DAG"), path);
  return temp;
}


x86 assembly (clang, -O0):
<dagpath>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
lea    0xec6(%rip),%rdi
call   1030 <getenv@plt>
cmp    $0x0,%rax
jne    1156 <dagpath+0x36>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1195 <dagpath+0x75>
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x1c(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x20(%rbp)
lea    0xe92(%rip),%rdi
call   1030 <getenv@plt>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%esi
mov    %rax,%rcx
mov    -0x10(%rbp),%r8
lea    0xe7c(%rip),%rdx
call   1040 <snprintf@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dagpath>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%ebp
mov    %rsi,%rbx
mov    %rdi,%r14
lea    0xecd(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     1159 <dagpath+0x39>
add    $0xffffffff,%ebp
lea    0xebd(%rip),%rdx
mov    %rbx,%rdi
mov    %ebp,%esi
mov    %rax,%rcx
mov    %r14,%r8
call   1040 <snprintf@plt>
jmp    115c <dagpath+0x3c>
mov    %r14,%rbx
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"DAG\00"
@.str.1 = [6 x i8] c"%s/%s\00"
define i8* @dagpath(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
%8 = call i8* @getenv(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%9 = icmp ne i8* %8, null
br i1 %9, label %12, label %10
10: ; preds = %3
%11 = load i8*, i8** %5
store i8* %11, i8** %4
br label %20
12: ; preds = %3
%13 = load i8*, i8** %6
%14 = load i32, i32* %7
%15 = sub nsw i32 %14, 1
%16 = call i8* @getenv(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%17 = load i8*, i8** %5
%18 = call i32 @snprintf(i8* %13, i32 %15, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %16, i8* %17)
%19 = load i8*, i8** %6
store i8* %19, i8** %4
br label %20
20: ; preds = %12, %10
%21 = load i8*, i8** %4
ret i8* %21
}

LLVM IR (-O2):
@.str = [4 x i8] c"DAG\00"
@.str.1 = [6 x i8] c"%s/%s\00"
define i8* @dagpath(i8* %0, i8* %1, i32 %2) {
%4 = tail call i8* @getenv(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i8* %4, null
br i1 %5, label %9, label %6
6: ; preds = %3
%7 = add nsw i32 %2, -1
%8 = tail call i32 @snprintf(i8* %1, i32 %7, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %4, i8* %0)
br label %9
9: ; preds = %3, %6
%10 = phi i8* [ %1, %6 ], [ %0, %3 ]
ret i8* %10
}