#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 *extendfile(char *, char *);
int /*<<< orphan*/ free(char *);
char *strdup(char const *);
char *strrchr(char const *, char);
char toupper(unsigned char);
char *generate_guard(const char *pathname) {
  const char *filename;
  char *guard, *tmp, *tmp2;
  filename = strrchr(pathname, '/');
  filename = ((filename == 0) ? pathname : filename + 1);
  guard = strdup(filename);
  tmp = guard;
  while (*tmp) {
    *tmp = toupper((unsigned char)*tmp);
    tmp++;
  }
  tmp2 = extendfile(guard, "_H_RPCGEN");
  free(guard);
  guard = tmp2;
  return (guard);
}


x86 assembly (clang, -O0):
<generate_guard>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x2f,%esi
call   1050 <strrchr@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1186 <generate_guard+0x36>
mov    -0x8(%rbp),%rax
mov    %rax,-0x30(%rbp)
jmp    1192 <generate_guard+0x42>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1070 <strdup@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmpb   $0x0,(%rax)
je     11e1 <generate_guard+0x91>
mov    -0x20(%rbp),%rax
movzbl (%rax),%edi
call   1040 <toupper@plt>
mov    %al,%cl
mov    -0x20(%rbp),%rax
mov    %cl,(%rax)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    11af <generate_guard+0x5f>
mov    -0x18(%rbp),%rdi
lea    0xe14(%rip),%rsi
call   1060 <extendfile@plt>
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<generate_guard>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%rbx
mov    $0x2f,%esi
call   1050 <strrchr@plt>
lea    0x1(%rax),%rdi
test   %rax,%rax
cmove  %rbx,%rdi
call   1070 <strdup@plt>
mov    %rax,%r15
mov    (%rax),%al
test   %al,%al
je     11a6 <generate_guard+0x56>
mov    %r15,%rbx
add    $0x1,%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movzbl %al,%edi
call   1040 <toupper@plt>
mov    %al,-0x1(%rbx)
movzbl (%rbx),%eax
add    $0x1,%rbx
test   %al,%al
jne    1190 <generate_guard+0x40>
lea    0xe53(%rip),%rsi
mov    %r15,%rdi
call   1060 <extendfile@plt>
mov    %rax,%r14
mov    %r15,%rdi
call   1030 <free@plt>
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [10 x i8] c"_H_RPCGEN\00"
define i8* @generate_guard(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
store i8* %0, i8** %2
%7 = load i8*, i8** %2
%8 = call i8* @strrchr(i8* %7, i8 signext 47)
store i8* %8, i8** %3
%9 = load i8*, i8** %3
%10 = icmp eq i8* %9, null
br i1 %10, label %11, label %13
11: ; preds = %1
%12 = load i8*, i8** %2
br label %16
13: ; preds = %1
%14 = load i8*, i8** %3
%15 = getelementptr inbounds i8, i8* %14, i64 1
br label %16
16: ; preds = %13, %11
%17 = phi i8* [ %12, %11 ], [ %15, %13 ]
store i8* %17, i8** %3
%18 = load i8*, i8** %3
%19 = call i8* @strdup(i8* %18)
store i8* %19, i8** %4
%20 = load i8*, i8** %4
store i8* %20, i8** %5
br label %21
21: ; preds = %25, %16
%22 = load i8*, i8** %5
%23 = load i8, i8* %22
%24 = icmp ne i8 %23, 0
br i1 %24, label %25, label %32
25: ; preds = %21
%26 = load i8*, i8** %5
%27 = load i8, i8* %26
%28 = call signext i8 @toupper(i8 zeroext %27)
%29 = load i8*, i8** %5
store i8 %28, i8* %29
%30 = load i8*, i8** %5
%31 = getelementptr inbounds i8, i8* %30, i32 1
store i8* %31, i8** %5
br label %21
32: ; preds = %21
%33 = load i8*, i8** %4
%34 = call i8* @extendfile(i8* %33, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
store i8* %34, i8** %6
%35 = load i8*, i8** %4
%36 = call i32 @free(i8* %35)
%37 = load i8*, i8** %6
store i8* %37, i8** %4
%38 = load i8*, i8** %4
ret i8* %38
}

LLVM IR (-O2):
@.str = [10 x i8] c"_H_RPCGEN\00"
define i8* @generate_guard(i8* %0) {
%2 = tail call i8* @strrchr(i8* dereferenceable(1) %0, i8 signext 47)
%3 = icmp eq i8* %2, null
%4 = getelementptr inbounds i8, i8* %2, i64 1
%5 = select i1 %3, i8* %0, i8* %4
%6 = tail call i8* @strdup(i8* %5)
%7 = load i8, i8* %6
%8 = icmp eq i8 %7, 0
br i1 %8, label %16, label %9
9: ; preds = %1, %9
%10 = phi i8 [ %14, %9 ], [ %7, %1 ]
%11 = phi i8* [ %13, %9 ], [ %6, %1 ]
%12 = tail call signext i8 @toupper(i8 zeroext %10)
store i8 %12, i8* %11
%13 = getelementptr inbounds i8, i8* %11, i64 1
%14 = load i8, i8* %13
%15 = icmp eq i8 %14, 0
br i1 %15, label %16, label %9
16: ; preds = %9, %1
%17 = tail call i8* @extendfile(i8* %6, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%18 = tail call i32 @free(i8* %6)
ret i8* %17
}