#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 */
struct passwd {
  char *pw_dir;
};

/* Variables and functions */
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ free(char *);
struct passwd *getpwuid(int /*<<< orphan*/);
int /*<<< orphan*/ getuid();
scalar_t__ malloc(int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
void subTelda(char **str) {
  struct passwd *pw;
  char *buff;
  int len;
  assert(str && *str);
  if ((*str)[0] == '~' && ((*str)[1] == 0 || (*str)[1] == '/')) {
    pw = getpwuid(getuid());
    len = strlen(pw->pw_dir) + strlen(*str);
    buff = (char *)malloc(len);
    if (buff) {
      memset(buff, 0, len);
      strcpy(buff, pw->pw_dir);
      strcat(buff, (*str) + 1);
      free(*str);
      *str = buff;
    }
  }
}


x86 assembly (clang, -O0):
<subTelda>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x8(%rbp)
mov    %al,-0x1d(%rbp)
je     11ba <subTelda+0x2a>
mov    -0x8(%rbp),%rax
cmpq   $0x0,(%rax)
setne  %al
mov    %al,-0x1d(%rbp)
mov    -0x1d(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1090 <assert@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
movsbl (%rax),%eax
cmp    $0x7e,%eax
jne    129e <subTelda+0x10e>
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
movsbl 0x1(%rax),%eax
cmp    $0x0,%eax
je     1202 <subTelda+0x72>
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
movsbl 0x1(%rax),%eax
cmp    $0x2f,%eax
jne    129e <subTelda+0x10e>
mov    $0x0,%al
call   1070 <getuid@plt>
mov    %eax,%edi
call   1050 <getpwuid@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1060 <strlen@plt>
mov    %eax,-0x24(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
call   1060 <strlen@plt>
mov    %eax,%ecx
mov    -0x24(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%edi
call   10a0 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1299 <subTelda+0x109>
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%edx
xor    %esi,%esi
call   1080 <memset@plt>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
call   1040 <strcpy@plt>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rax
mov    (%rax),%rsi
add    $0x1,%rsi
call   10b0 <strcat@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
jmp    129e <subTelda+0x10e>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<subTelda>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
test   %rdi,%rdi
je     11ab <subTelda+0x1b>
xor    %edi,%edi
cmpq   $0x0,(%rbx)
setne  %dil
jmp    11ad <subTelda+0x1d>
xor    %edi,%edi
call   1090 <assert@plt>
mov    (%rbx),%rax
cmpb   $0x7e,(%rax)
jne    122e <subTelda+0x9e>
mov    0x1(%rax),%al
cmp    $0x2f,%al
je     11c5 <subTelda+0x35>
test   %al,%al
jne    122e <subTelda+0x9e>
xor    %eax,%eax
call   1070 <getuid@plt>
mov    %eax,%edi
call   1050 <getpwuid@plt>
mov    %rax,%r14
mov    (%rax),%rdi
call   1060 <strlen@plt>
mov    %eax,%r15d
mov    (%rbx),%rdi
call   1060 <strlen@plt>
mov    %eax,%ebp
add    %r15d,%ebp
mov    %ebp,%edi
call   10a0 <malloc@plt>
test   %rax,%rax
je     122e <subTelda+0x9e>
mov    %rax,%r15
mov    %rax,%rdi
xor    %esi,%esi
mov    %ebp,%edx
call   1080 <memset@plt>
mov    (%r14),%rsi
mov    %r15,%rdi
call   1040 <strcpy@plt>
mov    (%rbx),%rsi
add    $0x1,%rsi
mov    %r15,%rdi
call   10b0 <strcat@plt>
mov    (%rbx),%rdi
call   1030 <free@plt>
mov    %r15,(%rbx)
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.passwd = type { i8* }
define void @subTelda(i8** %0) {
%2 = alloca i8**
%3 = alloca %struct.passwd*
%4 = alloca i8*
%5 = alloca i32
store i8** %0, i8*** %2
%6 = load i8**, i8*** %2
%7 = icmp ne i8** %6, null
br i1 %7, label %8, label %12
8: ; preds = %1
%9 = load i8**, i8*** %2
%10 = load i8*, i8** %9
%11 = icmp ne i8* %10, null
br label %12
12: ; preds = %8, %1
%13 = phi i1 [ false, %1 ], [ %11, %8 ]
%14 = zext i1 %13 to i32
%15 = call i32 @assert(i32 %14)
%16 = load i8**, i8*** %2
%17 = load i8*, i8** %16
%18 = getelementptr inbounds i8, i8* %17, i64 0
%19 = load i8, i8* %18
%20 = sext i8 %19 to i32
%21 = icmp eq i32 %20, 126
br i1 %21, label %22, label %72
22: ; preds = %12
%23 = load i8**, i8*** %2
%24 = load i8*, i8** %23
%25 = getelementptr inbounds i8, i8* %24, i64 1
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
%28 = icmp eq i32 %27, 0
br i1 %28, label %36, label %29
29: ; preds = %22
%30 = load i8**, i8*** %2
%31 = load i8*, i8** %30
%32 = getelementptr inbounds i8, i8* %31, i64 1
%33 = load i8, i8* %32
%34 = sext i8 %33 to i32
%35 = icmp eq i32 %34, 47
br i1 %35, label %36, label %72
36: ; preds = %29, %22
%37 = call i32 (...) @getuid()
%38 = call %struct.passwd* @getpwuid(i32 %37)
store %struct.passwd* %38, %struct.passwd** %3
%39 = load %struct.passwd*, %struct.passwd** %3
%40 = getelementptr inbounds %struct.passwd, %struct.passwd* %39, i32 0, i32 0
%41 = load i8*, i8** %40
%42 = call i32 @strlen(i8* %41)
%43 = load i8**, i8*** %2
%44 = load i8*, i8** %43
%45 = call i32 @strlen(i8* %44)
%46 = add nsw i32 %42, %45
store i32 %46, i32* %5
%47 = load i32, i32* %5
%48 = call i64 @malloc(i32 %47)
%49 = inttoptr i64 %48 to i8*
store i8* %49, i8** %4
%50 = load i8*, i8** %4
%51 = icmp ne i8* %50, null
br i1 %51, label %52, label %71
52: ; preds = %36
%53 = load i8*, i8** %4
%54 = load i32, i32* %5
%55 = call i32 @memset(i8* %53, i32 0, i32 %54)
%56 = load i8*, i8** %4
%57 = load %struct.passwd*, %struct.passwd** %3
%58 = getelementptr inbounds %struct.passwd, %struct.passwd* %57, i32 0, i32 0
%59 = load i8*, i8** %58
%60 = call i32 @strcpy(i8* %56, i8* %59)
%61 = load i8*, i8** %4
%62 = load i8**, i8*** %2
%63 = load i8*, i8** %62
%64 = getelementptr inbounds i8, i8* %63, i64 1
%65 = call i32 @strcat(i8* %61, i8* %64)
%66 = load i8**, i8*** %2
%67 = load i8*, i8** %66
%68 = call i32 @free(i8* %67)
%69 = load i8*, i8** %4
%70 = load i8**, i8*** %2
store i8* %69, i8** %70
br label %71
71: ; preds = %52, %36
br label %72
72: ; preds = %71, %29, %12
ret void
}

LLVM IR (-O2):
%struct.passwd = type { i8* }
define void @subTelda(i8** %0) {
%2 = icmp eq i8** %0, null
br i1 %2, label %7, label %3
3: ; preds = %1
%4 = load i8*, i8** %0
%5 = icmp ne i8* %4, null
%6 = zext i1 %5 to i32
br label %7
7: ; preds = %3, %1
%8 = phi i32 [ 0, %1 ], [ %6, %3 ]
%9 = tail call i32 @assert(i32 %8)
%10 = load i8*, i8** %0
%11 = load i8, i8* %10
%12 = icmp eq i8 %11, 126
br i1 %12, label %13, label %37
13: ; preds = %7
%14 = getelementptr inbounds i8, i8* %10, i64 1
%15 = load i8, i8* %14
switch i8 %15, label %37 [
i8 0, label %16
i8 47, label %16
]
16: ; preds = %13, %13
%17 = tail call i32 (...) @getuid()
%18 = tail call %struct.passwd* @getpwuid(i32 %17)
%19 = getelementptr inbounds %struct.passwd, %struct.passwd* %18, i64 0, i32 0
%20 = load i8*, i8** %19
%21 = tail call i32 @strlen(i8* %20)
%22 = load i8*, i8** %0
%23 = tail call i32 @strlen(i8* %22)
%24 = add nsw i32 %23, %21
%25 = tail call i64 @malloc(i32 %24)
%26 = inttoptr i64 %25 to i8*
%27 = icmp eq i64 %25, 0
br i1 %27, label %37, label %28
28: ; preds = %16
%29 = tail call i32 @memset(i8* %26, i32 0, i32 %24)
%30 = load i8*, i8** %19
%31 = tail call i32 @strcpy(i8* %26, i8* %30)
%32 = load i8*, i8** %0
%33 = getelementptr inbounds i8, i8* %32, i64 1
%34 = tail call i32 @strcat(i8* %26, i8* %33)
%35 = load i8*, i8** %0
%36 = tail call i32 @free(i8* %35)
store i8* %26, i8** %0
br label %37
37: ; preds = %13, %16, %28, %7
ret void
}