#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*/ get_method_path(char const *, char const **, unsigned int *,
                                   char const **);
char *malloc(scalar_t__);
int /*<<< orphan*/ memcpy(char *, char const *, unsigned int);
int /*<<< orphan*/ rfc2045_enomem();
int /*<<< orphan*/ strcat(char *, char const *);
char *strchr(char *, char);
char *strcpy(char *, char const *);
scalar_t__ strlen(char const *);
char *rfc2045_append_url(const char *base, const char *loc) {
  const char *base_method;
  unsigned base_method_l;
  const char *base_path;
  const char *loc_method;
  unsigned loc_method_l;
  const char *loc_path;
  char *buf, *q;
  get_method_path(base, &base_method, &base_method_l, &base_path);
  get_method_path(loc, &loc_method, &loc_method_l, &loc_path);
  if (loc_method_l) {
    buf = malloc(strlen(loc) + 1);
    if (!buf)
      rfc2045_enomem();
    else
      strcpy(buf, loc);
    return (buf);
  }
  loc_method = base_method;
  loc_method_l = base_method_l;
  if (!base_path)
    base_path = "";
  if (!loc_path)
    loc_path = "";
  buf = malloc(loc_method_l + strlen(base_path) + strlen(loc_path) + 3);
  if (!buf) {
    rfc2045_enomem();
    return (0);
  }
  if (loc_method_l)
    memcpy(buf, loc_method, loc_method_l);
  buf[loc_method_l] = 0;
  q = buf + loc_method_l;
  strcat(strcpy(q, base_path), "/");
  if (loc_path[0] == '/') {
    char *r;
    if (loc_path[1] == '/') {
      *q = 0;
    } else if (q[0] == '/' && q[1] == '/' && (r = strchr(q + 2, '/')) != 0) {
      *r = 0;
    } else
      *q = 0;
  }
  strcat(q, loc_path);
  return (buf);
}


x86 assembly (clang, -O0):
<rfc2045_append_url>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x20(%rbp),%rsi
lea    -0x24(%rbp),%rdx
lea    -0x30(%rbp),%rcx
call   1080 <get_method_path@plt>
mov    -0x18(%rbp),%rdi
lea    -0x38(%rbp),%rsi
lea    -0x3c(%rbp),%rdx
lea    -0x48(%rbp),%rcx
call   1080 <get_method_path@plt>
cmpl   $0x0,-0x3c(%rbp)
je     120e <rfc2045_append_url+0x8e>
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rdi
add    $0x1,%rdi
call   1070 <malloc@plt>
mov    %rax,-0x50(%rbp)
cmpq   $0x0,-0x50(%rbp)
jne    11f4 <rfc2045_append_url+0x74>
mov    $0x0,%al
call   10a0 <rfc2045_enomem@plt>
jmp    1201 <rfc2045_append_url+0x81>
mov    -0x50(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x50(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1391 <rfc2045_append_url+0x211>
mov    -0x20(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x3c(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1232 <rfc2045_append_url+0xb2>
lea    0xdd3(%rip),%rax
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x48(%rbp)
jne    1248 <rfc2045_append_url+0xc8>
lea    0xdbd(%rip),%rax
mov    %rax,-0x48(%rbp)
mov    -0x3c(%rbp),%eax
mov    %rax,-0x70(%rbp)
mov    -0x30(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rcx
mov    -0x70(%rbp),%rax
add    %rcx,%rax
mov    %rax,-0x68(%rbp)
mov    -0x48(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x68(%rbp),%rdi
add    %rax,%rdi
add    $0x3,%rdi
call   1070 <malloc@plt>
mov    %rax,-0x50(%rbp)
cmpq   $0x0,-0x50(%rbp)
jne    12a2 <rfc2045_append_url+0x122>
mov    $0x0,%al
call   10a0 <rfc2045_enomem@plt>
movq   $0x0,-0x8(%rbp)
jmp    1391 <rfc2045_append_url+0x211>
cmpl   $0x0,-0x3c(%rbp)
je     12bc <rfc2045_append_url+0x13c>
mov    -0x50(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    -0x3c(%rbp),%edx
call   1060 <memcpy@plt>
mov    -0x50(%rbp),%rax
mov    -0x3c(%rbp),%ecx
movb   $0x0,(%rax,%rcx,1)
mov    -0x50(%rbp),%rax
mov    -0x3c(%rbp),%ecx
add    %rcx,%rax
mov    %rax,-0x58(%rbp)
mov    -0x58(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1030 <strcpy@plt>
mov    %rax,%rdi
lea    0xd14(%rip),%rsi
call   1090 <strcat@plt>
mov    -0x48(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
jne    137c <rfc2045_append_url+0x1fc>
mov    -0x48(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x2f,%eax
jne    131e <rfc2045_append_url+0x19e>
mov    -0x58(%rbp),%rax
movb   $0x0,(%rax)
jmp    1377 <rfc2045_append_url+0x1f7>
mov    -0x58(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
jne    136b <rfc2045_append_url+0x1eb>
mov    -0x58(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x2f,%eax
jne    136b <rfc2045_append_url+0x1eb>
mov    -0x58(%rbp),%rdi
add    $0x2,%rdi
mov    $0x2f,%esi
call   1050 <strchr@plt>
mov    %rax,-0x60(%rbp)
cmp    $0x0,%rax
je     136b <rfc2045_append_url+0x1eb>
mov    -0x60(%rbp),%rax
movb   $0x0,(%rax)
jmp    1372 <rfc2045_append_url+0x1f2>
mov    -0x58(%rbp),%rax
movb   $0x0,(%rax)
jmp    1377 <rfc2045_append_url+0x1f7>
jmp    137c <rfc2045_append_url+0x1fc>
mov    -0x58(%rbp),%rdi
mov    -0x48(%rbp),%rsi
call   1090 <strcat@plt>
mov    -0x50(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rfc2045_append_url>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %rsi,%rbx
lea    0x30(%rsp),%rsi
lea    0x24(%rsp),%rdx
lea    0x18(%rsp),%rcx
call   1080 <get_method_path@plt>
lea    0x28(%rsp),%rsi
lea    0xc(%rsp),%rdx
lea    0x10(%rsp),%rcx
mov    %rbx,%rdi
call   1080 <get_method_path@plt>
cmpl   $0x0,0xc(%rsp)
je     11f0 <rfc2045_append_url+0x70>
mov    %rbx,%rdi
call   1040 <strlen@plt>
lea    0x1(%rax),%rdi
call   1070 <malloc@plt>
test   %rax,%rax
je     127c <rfc2045_append_url+0xfc>
mov    %rax,%rbp
mov    %rax,%rdi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
jmp    12f4 <rfc2045_append_url+0x174>
mov    0x30(%rsp),%r12
mov    %r12,0x28(%rsp)
mov    0x24(%rsp),%r13d
mov    %r13d,0xc(%rsp)
mov    0x18(%rsp),%r15
test   %r15,%r15
jne    121a <rfc2045_append_url+0x9a>
lea    0xdec(%rip),%r15
mov    %r15,0x18(%rsp)
mov    0x10(%rsp),%rbx
test   %rbx,%rbx
jne    1230 <rfc2045_append_url+0xb0>
lea    0xdd6(%rip),%rbx
mov    %rbx,0x10(%rsp)
mov    %r15,%rdi
call   1040 <strlen@plt>
mov    %rax,%rbp
mov    %rbx,%rdi
call   1040 <strlen@plt>
add    %r13,%rbp
lea    (%rax,%rbp,1),%rdi
add    $0x3,%rdi
call   1070 <malloc@plt>
test   %rax,%rax
je     127c <rfc2045_append_url+0xfc>
mov    %rax,%r14
mov    %rax,%rbp
test   %r13,%r13
je     1287 <rfc2045_append_url+0x107>
mov    %rbp,%rdi
mov    %r12,%rsi
mov    %r13d,%edx
call   1060 <memcpy@plt>
mov    0xc(%rsp),%eax
mov    0x18(%rsp),%r15
jmp    1289 <rfc2045_append_url+0x109>
xor    %ebp,%ebp
xor    %eax,%eax
call   10a0 <rfc2045_enomem@plt>
jmp    12f4 <rfc2045_append_url+0x174>
xor    %eax,%eax
add    %rax,%r14
movb   $0x0,0x0(%rbp,%rax,1)
mov    %r14,%rdi
mov    %r15,%rsi
call   1030 <strcpy@plt>
lea    0xd5d(%rip),%rsi
mov    %r14,%rdi
call   1090 <strcat@plt>
mov    0x10(%rsp),%rbx
cmpb   $0x2f,(%rbx)
jne    12e9 <rfc2045_append_url+0x169>
cmpb   $0x2f,0x1(%rbx)
je     12e5 <rfc2045_append_url+0x165>
cmpb   $0x2f,(%r14)
jne    12e5 <rfc2045_append_url+0x165>
cmpb   $0x2f,0x1(%r14)
jne    12e5 <rfc2045_append_url+0x165>
lea    0x2(%r14),%rdi
mov    $0x2f,%esi
call   1050 <strchr@plt>
test   %rax,%rax
je     12e5 <rfc2045_append_url+0x165>
movb   $0x0,(%rax)
mov    0x10(%rsp),%rbx
jmp    12e9 <rfc2045_append_url+0x169>
movb   $0x0,(%r14)
mov    %r14,%rdi
mov    %rbx,%rsi
call   1090 <strcat@plt>
mov    %rbp,%rax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [1 x i8] zeroinitializer
@.str.1 = [2 x i8] c"/\00"
define i8* @rfc2045_append_url(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
%9 = bitcast i8** %3 to i8*
%10 = bitcast i32* %4 to i8*
%11 = bitcast i8** %5 to i8*
%12 = bitcast i8** %6 to i8*
%13 = bitcast i32* %7 to i8*
%14 = bitcast i8** %8 to i8*
%15 = call i32 @get_method_path(i8* %0, i8** %3, i32* %4, i8** %5)
%16 = call i32 @get_method_path(i8* %1, i8** %6, i32* %7, i8** %8)
%17 = load i32, i32* %7
%18 = icmp eq i32 %17, 0
br i1 %18, label %28, label %19
19: ; preds = %2
%20 = call i64 @strlen(i8* dereferenceable(1) %1)
%21 = add nsw i64 %20, 1
%22 = call i8* @malloc(i64 %21)
%23 = icmp eq i8* %22, null
br i1 %23, label %24, label %26
24: ; preds = %19
%25 = call i32 (...) @rfc2045_enomem()
br label %89
26: ; preds = %19
%27 = call i8* @strcpy(i8* %22, i8* dereferenceable(1) %1)
br label %89
28: ; preds = %2
%29 = load i8*, i8** %3
store i8* %29, i8** %6
%30 = load i32, i32* %4
store i32 %30, i32* %7
%31 = load i8*, i8** %5
%32 = icmp eq i8* %31, null
br i1 %32, label %33, label %34
33: ; preds = %28
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8** %5
br label %34
34: ; preds = %33, %28
%35 = phi i8* [ getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), %33 ], [ %31, %28 ]
%36 = load i8*, i8** %8
%37 = icmp eq i8* %36, null
br i1 %37, label %38, label %39
38: ; preds = %34
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8** %8
br label %39
39: ; preds = %38, %34
%40 = phi i8* [ getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), %38 ], [ %36, %34 ]
%41 = zext i32 %30 to i64
%42 = call i64 @strlen(i8* dereferenceable(1) %35)
%43 = call i64 @strlen(i8* dereferenceable(1) %40)
%44 = add nuw nsw i64 %41, 3
%45 = add i64 %44, %42
%46 = add i64 %45, %43
%47 = call i8* @malloc(i64 %46)
%48 = icmp eq i8* %47, null
br i1 %48, label %49, label %51
49: ; preds = %39
%50 = call i32 (...) @rfc2045_enomem()
br label %89
51: ; preds = %39
%52 = icmp eq i32 %30, 0
br i1 %52, label %58, label %53
53: ; preds = %51
%54 = call i32 @memcpy(i8* %47, i8* %29, i32 %30)
%55 = load i32, i32* %7
%56 = load i8*, i8** %5
%57 = zext i32 %55 to i64
br label %58
58: ; preds = %53, %51
%59 = phi i8* [ %56, %53 ], [ %35, %51 ]
%60 = phi i64 [ %57, %53 ], [ 0, %51 ]
%61 = getelementptr inbounds i8, i8* %47, i64 %60
store i8 0, i8* %61
%62 = call i8* @strcpy(i8* %61, i8* dereferenceable(1) %59)
%63 = call i32 @strcat(i8* %61, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%64 = load i8*, i8** %8
%65 = load i8, i8* %64
%66 = icmp eq i8 %65, 47
br i1 %66, label %67, label %86
67: ; preds = %58
%68 = getelementptr inbounds i8, i8* %64, i64 1
%69 = load i8, i8* %68
%70 = icmp eq i8 %69, 47
br i1 %70, label %71, label %72
71: ; preds = %67
store i8 0, i8* %61
br label %86
72: ; preds = %67
%73 = load i8, i8* %61
%74 = icmp eq i8 %73, 47
br i1 %74, label %75, label %85
75: ; preds = %72
%76 = getelementptr inbounds i8, i8* %61, i64 1
%77 = load i8, i8* %76
%78 = icmp eq i8 %77, 47
br i1 %78, label %79, label %85
79: ; preds = %75
%80 = getelementptr inbounds i8, i8* %61, i64 2
%81 = call i8* @strchr(i8* %80, i8 signext 47)
%82 = icmp eq i8* %81, null
br i1 %82, label %85, label %83
83: ; preds = %79
store i8 0, i8* %81
%84 = load i8*, i8** %8
br label %86
85: ; preds = %79, %75, %72
store i8 0, i8* %61
br label %86
86: ; preds = %71, %85, %83, %58
%87 = phi i8* [ %64, %71 ], [ %64, %85 ], [ %84, %83 ], [ %64, %58 ]
%88 = call i32 @strcat(i8* %61, i8* %87)
br label %89
89: ; preds = %24, %26, %86, %49
%90 = phi i8* [ %47, %86 ], [ null, %49 ], [ %22, %26 ], [ null, %24 ]
ret i8* %90
}