#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 *);
scalar_t__ islower(char);
char *strdup(char *);
char *strrchr(char *, char);
char toupper(char);
char *generate_guard(char *pathname) {
  char *filename, *guard, *tmp;
  filename = strrchr(pathname, '/');
  filename = ((filename == 0) ? pathname : filename + 1);
  guard = strdup(filename);
  tmp = guard;
  while (*tmp) {
    if (islower(*tmp))
      *tmp = toupper(*tmp);
    tmp++;
  }
  guard = extendfile(guard, "_H_RPCGEN");
  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,-0x28(%rbp)
jmp    1192 <generate_guard+0x42>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%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     11f7 <generate_guard+0xa7>
mov    -0x20(%rbp),%rax
movsbl (%rax),%edi
call   1030 <islower@plt>
cmp    $0x0,%rax
je     11e6 <generate_guard+0x96>
mov    -0x20(%rbp),%rax
movsbl (%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    0xdfe(%rip),%rsi
call   1060 <extendfile@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<generate_guard>:
push   %r14
push   %rbx
push   %rax
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,%r14
mov    (%rax),%al
test   %al,%al
je     11a5 <generate_guard+0x55>
mov    %r14,%rbx
jmp    118c <generate_guard+0x3c>
nop
movzbl 0x1(%rbx),%eax
add    $0x1,%rbx
test   %al,%al
je     11a5 <generate_guard+0x55>
movsbl %al,%edi
call   1030 <islower@plt>
test   %rax,%rax
je     1180 <generate_guard+0x30>
movsbl (%rbx),%edi
call   1040 <toupper@plt>
mov    %al,(%rbx)
jmp    1180 <generate_guard+0x30>
lea    0xe54(%rip),%rsi
mov    %r14,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1060 <extendfile@plt>

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*
store i8* %0, i8** %2
%6 = load i8*, i8** %2
%7 = call i8* @strrchr(i8* %6, i8 signext 47)
store i8* %7, i8** %3
%8 = load i8*, i8** %3
%9 = icmp eq i8* %8, null
br i1 %9, label %10, label %12
10: ; preds = %1
%11 = load i8*, i8** %2
br label %15
12: ; preds = %1
%13 = load i8*, i8** %3
%14 = getelementptr inbounds i8, i8* %13, i64 1
br label %15
15: ; preds = %12, %10
%16 = phi i8* [ %11, %10 ], [ %14, %12 ]
store i8* %16, i8** %3
%17 = load i8*, i8** %3
%18 = call i8* @strdup(i8* %17)
store i8* %18, i8** %4
%19 = load i8*, i8** %4
store i8* %19, i8** %5
br label %20
20: ; preds = %34, %15
%21 = load i8*, i8** %5
%22 = load i8, i8* %21
%23 = icmp ne i8 %22, 0
br i1 %23, label %24, label %37
24: ; preds = %20
%25 = load i8*, i8** %5
%26 = load i8, i8* %25
%27 = call i64 @islower(i8 signext %26)
%28 = icmp ne i64 %27, 0
br i1 %28, label %29, label %34
29: ; preds = %24
%30 = load i8*, i8** %5
%31 = load i8, i8* %30
%32 = call signext i8 @toupper(i8 signext %31)
%33 = load i8*, i8** %5
store i8 %32, i8* %33
br label %34
34: ; preds = %29, %24
%35 = load i8*, i8** %5
%36 = getelementptr inbounds i8, i8* %35, i32 1
store i8* %36, i8** %5
br label %20
37: ; preds = %20
%38 = load i8*, i8** %4
%39 = call i8* @extendfile(i8* %38, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
store i8* %39, i8** %4
%40 = load i8*, i8** %4
ret i8* %40
}

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 %21, label %9
9: ; preds = %1, %17
%10 = phi i8 [ %19, %17 ], [ %7, %1 ]
%11 = phi i8* [ %18, %17 ], [ %6, %1 ]
%12 = tail call i64 @islower(i8 signext %10)
%13 = icmp eq i64 %12, 0
br i1 %13, label %17, label %14
14: ; preds = %9
%15 = load i8, i8* %11
%16 = tail call signext i8 @toupper(i8 signext %15)
store i8 %16, i8* %11
br label %17
17: ; preds = %14, %9
%18 = getelementptr inbounds i8, i8* %11, i64 1
%19 = load i8, i8* %18
%20 = icmp eq i8 %19, 0
br i1 %20, label %21, label %9
21: ; preds = %17, %1
%22 = tail call i8* @extendfile(i8* %6, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
ret i8* %22
}