#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 *malloc(scalar_t__);
int /*<<< orphan*/ sprintf(char *, char *, char const *, char const *, char *,
                           char *);
scalar_t__ strlen(char const *);
char *make_url(const char *url_prefix, const char *path, const char *rev) {
  char *urlbuf =
      malloc(strlen(url_prefix) + strlen(path) + strlen("?rev=") + 32 + 1);
  sprintf(urlbuf, "%s%s%s%s", url_prefix, path, rev ? "?rev=" : "", rev ?: "");
  return urlbuf;
}


x86 assembly (clang, -O0):
<make_url>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x58(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,%rcx
mov    -0x58(%rbp),%rax
add    %rcx,%rax
mov    %rax,-0x50(%rbp)
lea    0xe91(%rip),%rdi
call   1030 <strlen@plt>
mov    -0x50(%rbp),%rdi
add    %rax,%rdi
add    $0x20,%rdi
add    $0x1,%rdi
call   1040 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rdx
lea    0xe56(%rip),%rax
lea    0xe4a(%rip),%rcx
cmp    $0x0,%rdx
cmovne %rcx,%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
je     11e1 <make_url+0xb1>
mov    -0x28(%rbp),%rax
mov    %rax,-0x60(%rbp)
jmp    11f1 <make_url+0xc1>
lea    0xe1d(%rip),%rax
mov    %rax,-0x60(%rbp)
jmp    11f1 <make_url+0xc1>
mov    -0x30(%rbp),%r8
mov    -0x38(%rbp),%rcx
mov    -0x40(%rbp),%rdx
mov    -0x48(%rbp),%rdi
mov    -0x60(%rbp),%r9
lea    0xdfa(%rip),%rsi
call   1050 <sprintf@plt>
mov    -0x20(%rbp),%rax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<make_url>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%rbx
mov    %rsi,%r14
mov    %rdi,%r15
call   1030 <strlen@plt>
mov    %rax,%r12
mov    %r14,%rdi
call   1030 <strlen@plt>
lea    (%r12,%rax,1),%rdi
add    $0x26,%rdi
call   1040 <malloc@plt>
mov    %rax,%r12
test   %rbx,%rbx
lea    0xe9a(%rip),%rax
lea    0xe8e(%rip),%r8
cmove  %rax,%r8
cmove  %rax,%rbx
lea    0xe85(%rip),%rsi
mov    %r12,%rdi
mov    %r15,%rdx
mov    %r14,%rcx
mov    %rbx,%r9
call   1050 <sprintf@plt>
mov    %r12,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [6 x i8] c"?rev=\00"
@.str.1 = [9 x i8] c"%s%s%s%s\00"
@.str.2 = [1 x i8] zeroinitializer
define i8* @make_url(i8* %0, i8* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8* %2, i8** %6
%8 = load i8*, i8** %4
%9 = call i64 @strlen(i8* %8)
%10 = load i8*, i8** %5
%11 = call i64 @strlen(i8* %10)
%12 = add nsw i64 %9, %11
%13 = call i64 @strlen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%14 = add nsw i64 %12, %13
%15 = add nsw i64 %14, 32
%16 = add nsw i64 %15, 1
%17 = call i8* @malloc(i64 %16)
store i8* %17, i8** %7
%18 = load i8*, i8** %7
%19 = load i8*, i8** %4
%20 = load i8*, i8** %5
%21 = load i8*, i8** %6
%22 = icmp ne i8* %21, null
%23 = zext i1 %22 to i64
%24 = select i1 %22, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0)
%25 = load i8*, i8** %6
%26 = icmp ne i8* %25, null
br i1 %26, label %27, label %28
27: ; preds = %3
br label %29
28: ; preds = %3
br label %29
29: ; preds = %28, %27
%30 = phi i8* [ %25, %27 ], [ getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0), %28 ]
%31 = call i32 @sprintf(i8* %18, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* %19, i8* %20, i8* %24, i8* %30)
%32 = load i8*, i8** %7
ret i8* %32
}

LLVM IR (-O2):
@.str = [6 x i8] c"?rev=\00"
@.str.1 = [9 x i8] c"%s%s%s%s\00"
@.str.2 = [1 x i8] zeroinitializer
define noalias i8* @make_url(i8* %0, i8* %1, i8* %2) {
%4 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%5 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%6 = add i64 %4, 38
%7 = add i64 %6, %5
%8 = tail call i8* @malloc(i64 %7)
%9 = icmp eq i8* %2, null
%10 = select i1 %9, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0)
%11 = select i1 %9, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0), i8* %2
%12 = tail call i32 @sprintf(i8* dereferenceable(1) %8, i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* %0, i8* %1, i8* %10, i8* %11)
ret i8* %8
}