#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 */
int /*<<< orphan*/ printf(char *, char *, char *);
int /*<<< orphan*/ strcat(char *, char *);
char *strchr(char *, char);
int /*<<< orphan*/ strcpy(char *, char *);
int /*<<< orphan*/ stripdown(char *);
int strlen(char *);
int /*<<< orphan*/ strncmp(char *, char *, int);
scalar_t__ strspn(char *, char *);
char *getpath(char *buff, int size, char *path, char *source) {
  if (0)
    printf("getpath: %s, %s\n", path, source);
  if (strlen(source) > size)
    return NULL;
  strcpy(buff, source);
  if (buff[strlen(buff) - 1] != '/')
    stripdown(buff);
  if (path[0] == '/') {
    if (strchr(buff + strlen("http://"), '/'))
      strcpy(strchr(buff + strlen("http://"), '/'), path);
    else {
      buff[strlen(buff)] = '/';
      strcpy(buff + strlen(buff), path);
    }
    return buff;
  }
  while (strspn(path, ".") != 0) {
    if (!strncmp(path, "../", 3)) {
      stripdown(buff);
      path += 3;
    } else if (!strncmp(path, "./", 2))
      path += 2;
    else
      break;
  }
  if (strlen(buff) + strlen(path) > size)
    return NULL;
  strcat(buff, path);
  return buff;
}


x86 assembly (clang, -O0):
<getpath>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
call   1050 <strlen@plt>
cmp    -0x14(%rbp),%eax
jle    11a6 <getpath+0x36>
movq   $0x0,-0x8(%rbp)
jmp    1389 <getpath+0x219>
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2f,%eax
je     11e6 <getpath+0x76>
mov    -0x10(%rbp),%rdi
call   1080 <stripdown@plt>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
jne    12ad <getpath+0x13d>
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
lea    0xdfb(%rip),%rdi
call   1050 <strlen@plt>
mov    -0x38(%rbp),%rdi
cltq
add    %rax,%rdi
mov    $0x2f,%esi
call   1060 <strchr@plt>
cmp    $0x0,%rax
je     125f <getpath+0xef>
mov    -0x10(%rbp),%rax
mov    %rax,-0x40(%rbp)
lea    0xdca(%rip),%rdi
call   1050 <strlen@plt>
mov    -0x40(%rbp),%rdi
cltq
add    %rax,%rdi
mov    $0x2f,%esi
call   1060 <strchr@plt>
mov    %rax,%rdi
mov    -0x20(%rbp),%rsi
call   1040 <strcpy@plt>
jmp    12a0 <getpath+0x130>
mov    -0x10(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x50(%rbp),%rax
movslq %ecx,%rcx
movb   $0x2f,(%rax,%rcx,1)
mov    -0x10(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x48(%rbp),%rdi
cltq
add    %rax,%rdi
mov    -0x20(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1389 <getpath+0x219>
jmp    12b2 <getpath+0x142>
mov    -0x20(%rbp),%rdi
lea    0xd4b(%rip),%rsi
call   1070 <strspn@plt>
cmp    $0x0,%rax
je     1342 <getpath+0x1d2>
mov    -0x20(%rbp),%rdi
lea    0xd33(%rip),%rsi
mov    $0x3,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    1304 <getpath+0x194>
mov    -0x10(%rbp),%rdi
call   1080 <stripdown@plt>
mov    -0x20(%rbp),%rax
add    $0x3,%rax
mov    %rax,-0x20(%rbp)
jmp    133d <getpath+0x1cd>
mov    -0x20(%rbp),%rdi
lea    0xcfc(%rip),%rsi
mov    $0x2,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    1333 <getpath+0x1c3>
mov    -0x20(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x20(%rbp)
jmp    1338 <getpath+0x1c8>
jmp    1342 <getpath+0x1d2>
jmp    133d <getpath+0x1cd>
jmp    12b2 <getpath+0x142>
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x54(%rbp)
mov    -0x20(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x54(%rbp),%eax
add    %ecx,%eax
cmp    -0x14(%rbp),%eax
jle    1374 <getpath+0x204>
movq   $0x0,-0x8(%rbp)
jmp    1389 <getpath+0x219>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1090 <strcat@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getpath>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rcx,%rbp
mov    %rdx,%rbx
mov    %esi,%r15d
mov    %rdi,%r14
mov    %rcx,%rdi
call   1050 <strlen@plt>
cmp    %r15d,%eax
jle    119c <getpath+0x2c>
xor    %r14d,%r14d
jmp    12dc <getpath+0x16c>
mov    %r14,%rdi
mov    %rbp,%rsi
call   1040 <strcpy@plt>
mov    %r14,%rdi
call   1050 <strlen@plt>
cltq
cmpb   $0x2f,-0x1(%rax,%r14,1)
je     11c1 <getpath+0x51>
mov    %r14,%rdi
call   1080 <stripdown@plt>
cmpb   $0x2f,(%rbx)
jne    120f <getpath+0x9f>
lea    0xe33(%rip),%rdi
call   1050 <strlen@plt>
movslq %eax,%rdi
add    %r14,%rdi
mov    $0x2f,%esi
call   1060 <strchr@plt>
test   %rax,%rax
je     12b7 <getpath+0x147>
lea    0xe0e(%rip),%rdi
call   1050 <strlen@plt>
movslq %eax,%rdi
add    %r14,%rdi
mov    $0x2f,%esi
call   1060 <strchr@plt>
mov    %rax,%rdi
jmp    12d4 <getpath+0x164>
lea    0xdf2(%rip),%rsi
mov    %rbx,%rdi
call   1070 <strspn@plt>
test   %rax,%rax
je     128d <getpath+0x11d>
lea    0xde0(%rip),%r12
lea    0xdd7(%rip),%rbp
lea    0xdd3(%rip),%r13
jmp    1260 <getpath+0xf0>
nopw   0x0(%rax,%rax,1)
mov    %r14,%rdi
call   1080 <stripdown@plt>
mov    $0x3,%ecx
add    %rcx,%rbx
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1070 <strspn@plt>
test   %rax,%rax
je     128d <getpath+0x11d>
mov    %rbx,%rdi
mov    %r12,%rsi
mov    $0x3,%edx
call   1030 <strncmp@plt>
test   %eax,%eax
je     1240 <getpath+0xd0>
mov    %rbx,%rdi
mov    %r13,%rsi
mov    $0x2,%edx
call   1030 <strncmp@plt>
mov    $0x2,%ecx
test   %eax,%eax
je     124d <getpath+0xdd>
mov    %r14,%rdi
call   1050 <strlen@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1050 <strlen@plt>
add    %ebp,%eax
cmp    %r15d,%eax
jg     1194 <getpath+0x24>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1090 <strcat@plt>
jmp    12dc <getpath+0x16c>
mov    %r14,%rdi
call   1050 <strlen@plt>
cltq
movb   $0x2f,(%r14,%rax,1)
mov    %r14,%rdi
call   1050 <strlen@plt>
movslq %eax,%rdi
add    %r14,%rdi
mov    %rbx,%rsi
call   1040 <strcpy@plt>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [8 x i8] c"http://\00"
@.str.1 = [2 x i8] c".\00"
@.str.2 = [4 x i8] c"../\00"
@.str.3 = [3 x i8] c"./\00"
define i8* @getpath(i8* %0, i32 %1, i8* %2, i8* %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i8*
store i8* %0, i8** %6
store i32 %1, i32* %7
store i8* %2, i8** %8
store i8* %3, i8** %9
%10 = load i8*, i8** %9
%11 = call i32 @strlen(i8* %10)
%12 = load i32, i32* %7
%13 = icmp sgt i32 %11, %12
br i1 %13, label %14, label %15
14: ; preds = %4
store i8* null, i8** %5
br label %105
15: ; preds = %4
%16 = load i8*, i8** %6
%17 = load i8*, i8** %9
%18 = call i32 @strcpy(i8* %16, i8* %17)
%19 = load i8*, i8** %6
%20 = load i8*, i8** %6
%21 = call i32 @strlen(i8* %20)
%22 = sub nsw i32 %21, 1
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %19, i64 %23
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = icmp ne i32 %26, 47
br i1 %27, label %28, label %31
28: ; preds = %15
%29 = load i8*, i8** %6
%30 = call i32 @stripdown(i8* %29)
br label %31
31: ; preds = %28, %15
%32 = load i8*, i8** %8
%33 = getelementptr inbounds i8, i8* %32, i64 0
%34 = load i8, i8* %33
%35 = sext i8 %34 to i32
%36 = icmp eq i32 %35, 47
br i1 %36, label %37, label %67
37: ; preds = %31
%38 = load i8*, i8** %6
%39 = call i32 @strlen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i8, i8* %38, i64 %40
%42 = call i8* @strchr(i8* %41, i8 signext 47)
%43 = icmp ne i8* %42, null
br i1 %43, label %44, label %52
44: ; preds = %37
%45 = load i8*, i8** %6
%46 = call i32 @strlen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds i8, i8* %45, i64 %47
%49 = call i8* @strchr(i8* %48, i8 signext 47)
%50 = load i8*, i8** %8
%51 = call i32 @strcpy(i8* %49, i8* %50)
br label %65
52: ; preds = %37
%53 = load i8*, i8** %6
%54 = load i8*, i8** %6
%55 = call i32 @strlen(i8* %54)
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds i8, i8* %53, i64 %56
store i8 47, i8* %57
%58 = load i8*, i8** %6
%59 = load i8*, i8** %6
%60 = call i32 @strlen(i8* %59)
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds i8, i8* %58, i64 %61
%63 = load i8*, i8** %8
%64 = call i32 @strcpy(i8* %62, i8* %63)
br label %65
65: ; preds = %52, %44
%66 = load i8*, i8** %6
store i8* %66, i8** %5
br label %105
67: ; preds = %31
br label %68
68: ; preds = %90, %67
%69 = load i8*, i8** %8
%70 = call i64 @strspn(i8* %69, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%71 = icmp ne i64 %70, 0
br i1 %71, label %72, label %91
72: ; preds = %68
%73 = load i8*, i8** %8
%74 = call i32 @strncmp(i8* %73, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 3)
%75 = icmp ne i32 %74, 0
br i1 %75, label %81, label %76
76: ; preds = %72
%77 = load i8*, i8** %6
%78 = call i32 @stripdown(i8* %77)
%79 = load i8*, i8** %8
%80 = getelementptr inbounds i8, i8* %79, i64 3
store i8* %80, i8** %8
br label %90
81: ; preds = %72
%82 = load i8*, i8** %8
%83 = call i32 @strncmp(i8* %82, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 2)
%84 = icmp ne i32 %83, 0
br i1 %84, label %88, label %85
85: ; preds = %81
%86 = load i8*, i8** %8
%87 = getelementptr inbounds i8, i8* %86, i64 2
store i8* %87, i8** %8
br label %89
88: ; preds = %81
br label %91
89: ; preds = %85
br label %90
90: ; preds = %89, %76
br label %68
91: ; preds = %88, %68
%92 = load i8*, i8** %6
%93 = call i32 @strlen(i8* %92)
%94 = load i8*, i8** %8
%95 = call i32 @strlen(i8* %94)
%96 = add nsw i32 %93, %95
%97 = load i32, i32* %7
%98 = icmp sgt i32 %96, %97
br i1 %98, label %99, label %100
99: ; preds = %91
store i8* null, i8** %5
br label %105
100: ; preds = %91
%101 = load i8*, i8** %6
%102 = load i8*, i8** %8
%103 = call i32 @strcat(i8* %101, i8* %102)
%104 = load i8*, i8** %6
store i8* %104, i8** %5
br label %105
105: ; preds = %100, %99, %65, %14
%106 = load i8*, i8** %5
ret i8* %106
}

LLVM IR (-O2):
@.str = [8 x i8] c"http://\00"
@.str.1 = [2 x i8] c".\00"
@.str.2 = [4 x i8] c"../\00"
@.str.3 = [3 x i8] c"./\00"
define i8* @getpath(i8* %0, i32 %1, i8* %2, i8* %3) {
%5 = tail call i32 @strlen(i8* %3)
%6 = icmp sgt i32 %5, %1
br i1 %6, label %65, label %7
7: ; preds = %4
%8 = tail call i32 @strcpy(i8* %0, i8* %3)
%9 = tail call i32 @strlen(i8* %0)
%10 = add nsw i32 %9, -1
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds i8, i8* %0, i64 %11
%13 = load i8, i8* %12
%14 = icmp eq i8 %13, 47
br i1 %14, label %17, label %15
15: ; preds = %7
%16 = tail call i32 @stripdown(i8* %0)
br label %17
17: ; preds = %15, %7
%18 = load i8, i8* %2
%19 = icmp eq i8 %18, 47
br i1 %19, label %23, label %20
20: ; preds = %17
%21 = tail call i64 @strspn(i8* %2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%22 = icmp eq i64 %21, 0
br i1 %22, label %57, label %43
23: ; preds = %17
%24 = tail call i32 @strlen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8, i8* %0, i64 %25
%27 = tail call i8* @strchr(i8* dereferenceable(1) %26, i8 signext 47)
%28 = icmp eq i8* %27, null
br i1 %28, label %35, label %29
29: ; preds = %23
%30 = tail call i32 @strlen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i8, i8* %0, i64 %31
%33 = tail call i8* @strchr(i8* dereferenceable(1) %32, i8 signext 47)
%34 = tail call i32 @strcpy(i8* %33, i8* %2)
br label %65
35: ; preds = %23
%36 = tail call i32 @strlen(i8* %0)
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i8, i8* %0, i64 %37
store i8 47, i8* %38
%39 = tail call i32 @strlen(i8* %0)
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i8, i8* %0, i64 %40
%42 = tail call i32 @strcpy(i8* %41, i8* %2)
br label %65
43: ; preds = %20, %52
%44 = phi i8* [ %54, %52 ], [ %2, %20 ]
%45 = tail call i32 @strncmp(i8* %44, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 3)
%46 = icmp eq i32 %45, 0
br i1 %46, label %47, label %49
47: ; preds = %43
%48 = tail call i32 @stripdown(i8* %0)
br label %52
49: ; preds = %43
%50 = tail call i32 @strncmp(i8* %44, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 2)
%51 = icmp eq i32 %50, 0
br i1 %51, label %52, label %57
52: ; preds = %49, %47
%53 = phi i64 [ 3, %47 ], [ 2, %49 ]
%54 = getelementptr inbounds i8, i8* %44, i64 %53
%55 = tail call i64 @strspn(i8* %54, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%56 = icmp eq i64 %55, 0
br i1 %56, label %57, label %43
57: ; preds = %52, %49, %20
%58 = phi i8* [ %2, %20 ], [ %44, %49 ], [ %54, %52 ]
%59 = tail call i32 @strlen(i8* %0)
%60 = tail call i32 @strlen(i8* %58)
%61 = add nsw i32 %60, %59
%62 = icmp sgt i32 %61, %1
br i1 %62, label %65, label %63
63: ; preds = %57
%64 = tail call i32 @strcat(i8* %0, i8* %58)
br label %65
65: ; preds = %57, %29, %35, %4, %63
%66 = phi i8* [ %0, %63 ], [ null, %4 ], [ %0, %35 ], [ %0, %29 ], [ null, %57 ]
ret i8* %66
}