#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(size_t);
char *strchr(char const *, char);
char *strdup(char *);
size_t strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, size_t);
char *ssl_wildcardify(const char *hostname) {
  char *dot, *wildcarded;
  size_t dotsz;
  if (!(dot = strchr(hostname, '.')))
    return strdup("*");
  dotsz = strlen(dot);
  if (!(wildcarded = malloc(dotsz + 2)))
    return NULL;
  wildcarded[0] = '*';
  strncpy(wildcarded + 1, dot, dotsz);
  wildcarded[dotsz + 1] = '\0';
  return wildcarded;
}


x86 assembly (clang, -O0):
<ssl_wildcardify>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x2e,%esi
call   1050 <strchr@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    118d <ssl_wildcardify+0x3d>
lea    0xe81(%rip),%rdi
call   1070 <strdup@plt>
mov    %rax,-0x8(%rbp)
jmp    11f3 <ssl_wildcardify+0xa3>
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
add    $0x2,%rdi
call   1060 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    11c2 <ssl_wildcardify+0x72>
movq   $0x0,-0x8(%rbp)
jmp    11f3 <ssl_wildcardify+0xa3>
mov    -0x20(%rbp),%rax
movb   $0x2a,(%rax)
mov    -0x20(%rbp),%rdi
add    $0x1,%rdi
mov    -0x18(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1030 <strncpy@plt>
mov    -0x20(%rbp),%rax
mov    -0x28(%rbp),%rcx
movb   $0x0,0x1(%rax,%rcx,1)
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ssl_wildcardify>:
push   %r15
push   %r14
push   %rbx
mov    $0x2e,%esi
call   1050 <strchr@plt>
test   %rax,%rax
je     11a0 <ssl_wildcardify+0x50>
mov    %rax,%r14
mov    %rax,%rdi
call   1040 <strlen@plt>
mov    %rax,%r15
lea    0x2(%rax),%rdi
call   1060 <malloc@plt>
test   %rax,%rax
je     11b1 <ssl_wildcardify+0x61>
mov    %rax,%rbx
movb   $0x2a,(%rax)
mov    %rax,%rdi
add    $0x1,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   1030 <strncpy@plt>
movb   $0x0,0x1(%r15,%rbx,1)
jmp    11b3 <ssl_wildcardify+0x63>
lea    0xe59(%rip),%rdi
pop    %rbx
pop    %r14
pop    %r15
jmp    1070 <strdup@plt>
xor    %ebx,%ebx
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [2 x i8] c"*\00"
define i8* @ssl_wildcardify(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
store i8* %0, i8** %3
%7 = load i8*, i8** %3
%8 = call i8* @strchr(i8* %7, i8 signext 46)
store i8* %8, i8** %4
%9 = icmp ne i8* %8, null
br i1 %9, label %12, label %10
10: ; preds = %1
%11 = call i8* @strdup(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %11, i8** %2
br label %33
12: ; preds = %1
%13 = load i8*, i8** %4
%14 = call i64 @strlen(i8* %13)
store i64 %14, i64* %6
%15 = load i64, i64* %6
%16 = add i64 %15, 2
%17 = call i8* @malloc(i64 %16)
store i8* %17, i8** %5
%18 = icmp ne i8* %17, null
br i1 %18, label %20, label %19
19: ; preds = %12
store i8* null, i8** %2
br label %33
20: ; preds = %12
%21 = load i8*, i8** %5
%22 = getelementptr inbounds i8, i8* %21, i64 0
store i8 42, i8* %22
%23 = load i8*, i8** %5
%24 = getelementptr inbounds i8, i8* %23, i64 1
%25 = load i8*, i8** %4
%26 = load i64, i64* %6
%27 = call i32 @strncpy(i8* %24, i8* %25, i64 %26)
%28 = load i8*, i8** %5
%29 = load i64, i64* %6
%30 = add i64 %29, 1
%31 = getelementptr inbounds i8, i8* %28, i64 %30
store i8 0, i8* %31
%32 = load i8*, i8** %5
store i8* %32, i8** %2
br label %33
33: ; preds = %20, %19, %10
%34 = load i8*, i8** %2
ret i8* %34
}

LLVM IR (-O2):
@.str = [2 x i8] c"*\00"
define i8* @ssl_wildcardify(i8* %0) {
%2 = tail call i8* @strchr(i8* dereferenceable(1) %0, i8 signext 46)
%3 = icmp eq i8* %2, null
br i1 %3, label %4, label %6
4: ; preds = %1
%5 = tail call dereferenceable_or_null(2) i8* @strdup(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %16
6: ; preds = %1
%7 = tail call i64 @strlen(i8* %2)
%8 = add i64 %7, 2
%9 = tail call i8* @malloc(i64 %8)
%10 = icmp eq i8* %9, null
br i1 %10, label %16, label %11
11: ; preds = %6
store i8 42, i8* %9
%12 = getelementptr inbounds i8, i8* %9, i64 1
%13 = tail call i32 @strncpy(i8* %12, i8* %2, i64 %7)
%14 = add i64 %7, 1
%15 = getelementptr inbounds i8, i8* %9, i64 %14
store i8 0, i8* %15
br label %16
16: ; preds = %6, %11, %4
%17 = phi i8* [ %9, %11 ], [ %5, %4 ], [ null, %6 ]
ret i8* %17
}