#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(int);
int /*<<< orphan*/ sprintf(char *, char *, char const *);
int /*<<< orphan*/ strcat(char *, char *);
int strlen(char const *);
int /*<<< orphan*/ strncpy(char *, char const *, size_t);
char *strrchr(char const *, char);
char *options_name_thumb(const char *name) {
  char *thumb = malloc(strlen(name) + sizeof("-thumb"));
  char *dot = strrchr(name, '.');
  if (dot != NULL) {
    strncpy(thumb, name, (size_t)(dot - name));
    strcat(thumb, "-thumb");
    strcat(thumb, dot);
  } else {
    sprintf(thumb, "%s-thumb", name);
  }
  return thumb;
}


x86 assembly (clang, -O0):
<options_name_thumb>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
cltq
add    $0x7,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x2e,%esi
call   1050 <strrchr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11dd <options_name_thumb+0x7d>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x8(%rbp),%rax
sub    %rax,%rdx
call   1030 <strncpy@plt>
mov    -0x10(%rbp),%rdi
lea    0xe3c(%rip),%rsi
call   1070 <strcat@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1070 <strcat@plt>
jmp    11f1 <options_name_thumb+0x91>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rdx
lea    0xe14(%rip),%rsi
call   1080 <sprintf@plt>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<options_name_thumb>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%rbx
call   1040 <strlen@plt>
lea    0x7(%rax),%edi
call   1060 <malloc@plt>
mov    %rax,%r14
mov    %rbx,%rdi
mov    $0x2e,%esi
call   1050 <strrchr@plt>
test   %rax,%rax
je     11ba <options_name_thumb+0x5a>
mov    %rax,%r15
mov    %rax,%rdx
sub    %rbx,%rdx
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <strncpy@plt>
lea    0xe5d(%rip),%rsi
mov    %r14,%rdi
call   1070 <strcat@plt>
mov    %r14,%rdi
mov    %r15,%rsi
call   1070 <strcat@plt>
jmp    11cc <options_name_thumb+0x6c>
lea    0xe3f(%rip),%rsi
mov    %r14,%rdi
mov    %rbx,%rdx
call   1080 <sprintf@plt>
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str = [7 x i8] c"-thumb\00"
@.str.1 = [9 x i8] c"%s-thumb\00"
define i8* @options_name_thumb(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = add i32 %2, 7
%4 = tail call i8* @malloc(i32 %3)
%5 = tail call i8* @strrchr(i8* dereferenceable(1) %0, i8 signext 46)
%6 = icmp eq i8* %5, null
br i1 %6, label %14, label %7
7: ; preds = %1
%8 = ptrtoint i8* %5 to i64
%9 = ptrtoint i8* %0 to i64
%10 = sub i64 %8, %9
%11 = tail call i32 @strncpy(i8* %4, i8* %0, i64 %10)
%12 = tail call i32 @strcat(i8* %4, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%13 = tail call i32 @strcat(i8* %4, i8* %5)
br label %16
14: ; preds = %1
%15 = tail call i32 @sprintf(i8* dereferenceable(1) %4, i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %16
16: ; preds = %14, %7
ret i8* %4
}