#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);
size_t strlen(char const *);
char *strrchr(char const *, char);
char toupper(char const);
char *genhead_macro_name(const char *name) {
  char *extension = strrchr(name, '.');
  size_t name_len;
  if (extension != NULL) {
    name_len = extension - name;
  } else {
    name_len = strlen(name);
  }
  char *macro_name = malloc(name_len + 3);
  if (macro_name == NULL) {
    return NULL;
  }
  size_t i;
  for (i = 0; i < name_len; ++i) {
    macro_name[i] = toupper(name[i]);
  }
  macro_name[i++] = '_';
  macro_name[i++] = 'H';
  macro_name[i++] = '\0';
  return macro_name;
}


x86 assembly (clang, -O0):
<genhead_macro_name>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x2e,%esi
call   1050 <strrchr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     117d <genhead_macro_name+0x3d>
mov    -0x18(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
mov    %rax,-0x20(%rbp)
jmp    118a <genhead_macro_name+0x4a>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
add    $0x3,%rdi
call   1060 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11b3 <genhead_macro_name+0x73>
movq   $0x0,-0x8(%rbp)
jmp    1245 <genhead_macro_name+0x105>
movq   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%rax
cmp    -0x20(%rbp),%rax
jae    11f8 <genhead_macro_name+0xb8>
mov    -0x10(%rbp),%rax
mov    -0x30(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1030 <toupper@plt>
mov    %al,%dl
mov    -0x28(%rbp),%rax
mov    -0x30(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    11bb <genhead_macro_name+0x7b>
mov    -0x28(%rbp),%rax
mov    -0x30(%rbp),%rcx
mov    %rcx,%rdx
add    $0x1,%rdx
mov    %rdx,-0x30(%rbp)
movb   $0x5f,(%rax,%rcx,1)
mov    -0x28(%rbp),%rax
mov    -0x30(%rbp),%rcx
mov    %rcx,%rdx
add    $0x1,%rdx
mov    %rdx,-0x30(%rbp)
movb   $0x48,(%rax,%rcx,1)
mov    -0x28(%rbp),%rax
mov    -0x30(%rbp),%rcx
mov    %rcx,%rdx
add    $0x1,%rdx
mov    %rdx,-0x30(%rbp)
movb   $0x0,(%rax,%rcx,1)
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<genhead_macro_name>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
mov    $0x2e,%esi
call   1050 <strrchr@plt>
test   %rax,%rax
je     1162 <genhead_macro_name+0x22>
mov    %rax,%r15
sub    %r14,%r15
jmp    116d <genhead_macro_name+0x2d>
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %rax,%r15
lea    0x3(%r15),%rdi
call   1060 <malloc@plt>
mov    %rax,%r12
test   %rax,%rax
je     11b4 <genhead_macro_name+0x74>
test   %r15,%r15
je     11a7 <genhead_macro_name+0x67>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nop
movsbl (%r14,%rbx,1),%edi
call   1030 <toupper@plt>
mov    %al,(%r12,%rbx,1)
add    $0x1,%rbx
cmp    %rbx,%r15
jne    1190 <genhead_macro_name+0x50>
movw   $0x485f,(%r12,%r15,1)
movb   $0x0,0x2(%r12,%r15,1)
mov    %r12,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @genhead_macro_name(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i8*
%7 = alloca i64
store i8* %0, i8** %3
%8 = load i8*, i8** %3
%9 = call i8* @strrchr(i8* %8, i8 signext 46)
store i8* %9, i8** %4
%10 = load i8*, i8** %4
%11 = icmp ne i8* %10, null
br i1 %11, label %12, label %18
12: ; preds = %1
%13 = load i8*, i8** %4
%14 = load i8*, i8** %3
%15 = ptrtoint i8* %13 to i64
%16 = ptrtoint i8* %14 to i64
%17 = sub i64 %15, %16
store i64 %17, i64* %5
br label %21
18: ; preds = %1
%19 = load i8*, i8** %3
%20 = call i64 @strlen(i8* %19)
store i64 %20, i64* %5
br label %21
21: ; preds = %18, %12
%22 = load i64, i64* %5
%23 = add i64 %22, 3
%24 = call i8* @malloc(i64 %23)
store i8* %24, i8** %6
%25 = load i8*, i8** %6
%26 = icmp eq i8* %25, null
br i1 %26, label %27, label %28
27: ; preds = %21
store i8* null, i8** %2
br label %59
28: ; preds = %21
store i64 0, i64* %7
br label %29
29: ; preds = %42, %28
%30 = load i64, i64* %7
%31 = load i64, i64* %5
%32 = icmp ult i64 %30, %31
br i1 %32, label %33, label %45
33: ; preds = %29
%34 = load i8*, i8** %3
%35 = load i64, i64* %7
%36 = getelementptr inbounds i8, i8* %34, i64 %35
%37 = load i8, i8* %36
%38 = call signext i8 @toupper(i8 signext %37)
%39 = load i8*, i8** %6
%40 = load i64, i64* %7
%41 = getelementptr inbounds i8, i8* %39, i64 %40
store i8 %38, i8* %41
br label %42
42: ; preds = %33
%43 = load i64, i64* %7
%44 = add i64 %43, 1
store i64 %44, i64* %7
br label %29
45: ; preds = %29
%46 = load i8*, i8** %6
%47 = load i64, i64* %7
%48 = add i64 %47, 1
store i64 %48, i64* %7
%49 = getelementptr inbounds i8, i8* %46, i64 %47
store i8 95, i8* %49
%50 = load i8*, i8** %6
%51 = load i64, i64* %7
%52 = add i64 %51, 1
store i64 %52, i64* %7
%53 = getelementptr inbounds i8, i8* %50, i64 %51
store i8 72, i8* %53
%54 = load i8*, i8** %6
%55 = load i64, i64* %7
%56 = add i64 %55, 1
store i64 %56, i64* %7
%57 = getelementptr inbounds i8, i8* %54, i64 %55
store i8 0, i8* %57
%58 = load i8*, i8** %6
store i8* %58, i8** %2
br label %59
59: ; preds = %45, %27
%60 = load i8*, i8** %2
ret i8* %60
}

LLVM IR (-O2):
define noalias i8* @genhead_macro_name(i8* %0) {
%2 = tail call i8* @strrchr(i8* dereferenceable(1) %0, i8 signext 46)
%3 = icmp eq i8* %2, null
br i1 %3, label %8, label %4
4: ; preds = %1
%5 = ptrtoint i8* %2 to i64
%6 = ptrtoint i8* %0 to i64
%7 = sub i64 %5, %6
br label %10
8: ; preds = %1
%9 = tail call i64 @strlen(i8* dereferenceable(1) %0)
br label %10
10: ; preds = %8, %4
%11 = phi i64 [ %7, %4 ], [ %9, %8 ]
%12 = add i64 %11, 3
%13 = tail call i8* @malloc(i64 %12)
%14 = icmp eq i8* %13, null
br i1 %14, label %31, label %15
15: ; preds = %10
%16 = icmp eq i64 %11, 0
br i1 %16, label %25, label %17
17: ; preds = %15, %17
%18 = phi i64 [ %23, %17 ], [ 0, %15 ]
%19 = getelementptr inbounds i8, i8* %0, i64 %18
%20 = load i8, i8* %19
%21 = tail call signext i8 @toupper(i8 signext %20)
%22 = getelementptr inbounds i8, i8* %13, i64 %18
store i8 %21, i8* %22
%23 = add nuw i64 %18, 1
%24 = icmp eq i64 %23, %11
br i1 %24, label %25, label %17
25: ; preds = %17, %15
%26 = add i64 %11, 1
%27 = getelementptr inbounds i8, i8* %13, i64 %11
store i8 95, i8* %27
%28 = add i64 %11, 2
%29 = getelementptr inbounds i8, i8* %13, i64 %26
store i8 72, i8* %29
%30 = getelementptr inbounds i8, i8* %13, i64 %28
store i8 0, i8* %30
br label %31
31: ; preds = %10, %25
ret i8* %13
}