#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*/ strcpy(char *, char *);
size_t strcspn(char *, char *);
char *makeversion(char *buffer, char *revision) {
  char *p = buffer;
  strcpy(buffer, revision);
  p += strcspn(p, "0123456789");
  if (*p) {
    p[strcspn(p, " $")] = '\0';
  }
  if (!*p)
    return NULL;
  return p;
}


x86 assembly (clang, -O0):
<makeversion>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x20(%rbp),%rdi
lea    0xeb0(%rip),%rsi
call   1040 <strcspn@plt>
add    -0x20(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmpb   $0x0,(%rax)
je     118d <makeversion+0x6d>
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xe8e(%rip),%rsi
call   1040 <strcspn@plt>
mov    %rax,%rcx
mov    -0x28(%rbp),%rax
movb   $0x0,(%rax,%rcx,1)
mov    -0x20(%rbp),%rax
cmpb   $0x0,(%rax)
jne    11a7 <makeversion+0x87>
movq   $0x0,-0x8(%rbp)
jmp    11af <makeversion+0x8f>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<makeversion>:
push   %rbx
mov    %rdi,%rbx
call   1030 <strcpy@plt>
lea    0xed0(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strcspn@plt>
cmpb   $0x0,(%rbx,%rax,1)
je     115f <makeversion+0x3f>
add    %rax,%rbx
lea    0xec3(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strcspn@plt>
movb   $0x0,(%rbx,%rax,1)
xor    %eax,%eax
cmpb   $0x0,(%rbx)
cmovne %rbx,%rax
pop    %rbx
ret
xor    %eax,%eax
pop    %rbx
ret

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

LLVM IR (-O2):
@.str = [11 x i8] c"0123456789\00"
@.str.1 = [3 x i8] c" $\00"
define i8* @makeversion(i8* %0, i8* %1) {
%3 = tail call i32 @strcpy(i8* %0, i8* %1)
%4 = tail call i64 @strcspn(i8* %0, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%5 = getelementptr inbounds i8, i8* %0, i64 %4
%6 = load i8, i8* %5
%7 = icmp eq i8 %6, 0
br i1 %7, label %14, label %8
8: ; preds = %2
%9 = tail call i64 @strcspn(i8* %5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%10 = getelementptr inbounds i8, i8* %5, i64 %9
store i8 0, i8* %10
%11 = load i8, i8* %5
%12 = icmp eq i8 %11, 0
%13 = select i1 %12, i8* null, i8* %5
br label %14
14: ; preds = %8, %2
%15 = phi i8* [ %13, %8 ], [ null, %2 ]
ret i8* %15
}