#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*/ free(char *);
char *malloc(int);
int /*<<< orphan*/ sprintf(char *, char *, char *);
char *strdup(char *);
int strlen(char *);
char *extract_port_name(char *func_name) {
  int i;
  char *portname = malloc(strlen(func_name) + 30);
  char *tmpport = strdup(func_name);
  char *origtmpport = tmpport;
  while (tmpport[0] != 0)
    tmpport++;
  while (tmpport[0] != '_')
    tmpport--;
  tmpport++;
  for (i = 0; i < strlen(tmpport); i++)
    tmpport[i] = tmpport[i] - 'a' + 'A';
  sprintf(portname, "%s_PORT", tmpport);
  free(origtmpport);
  return portname;
}


x86 assembly (clang, -O0):
<extract_port_name>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%edi
add    $0x1e,%edi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1070 <strdup@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11a9 <extract_port_name+0x59>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1188 <extract_port_name+0x38>
jmp    11ae <extract_port_name+0x5e>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x5f,%eax
je     11cf <extract_port_name+0x7f>
mov    -0x20(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x20(%rbp)
jmp    11ae <extract_port_name+0x5e>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x2c(%rbp),%eax
cmp    %ecx,%eax
jge    122b <extract_port_name+0xdb>
mov    -0x20(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
sub    $0x61,%eax
add    $0x41,%eax
mov    %al,%dl
mov    -0x20(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11e2 <extract_port_name+0x92>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rdx
lea    0xdc6(%rip),%rsi
call   1060 <sprintf@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<extract_port_name>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%rbx
call   1040 <strlen@plt>
lea    0x1e(%rax),%edi
call   1050 <malloc@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   1070 <strdup@plt>
mov    %rax,%r15
mov    %rax,%rbx
nopl   0x0(%rax)
cmpb   $0x0,(%rbx)
lea    0x1(%rbx),%rbx
jne    1180 <extract_port_name+0x30>
nopl   0x0(%rax)
cmpb   $0x5f,-0x2(%rbx)
lea    -0x1(%rbx),%rbx
jne    1190 <extract_port_name+0x40>
mov    %rbx,%rdi
call   1040 <strlen@plt>
test   %eax,%eax
jle    11c8 <extract_port_name+0x78>
xor    %r12d,%r12d
nopl   0x0(%rax)
addb   $0xe0,(%rbx,%r12,1)
add    $0x1,%r12
mov    %rbx,%rdi
call   1040 <strlen@plt>
cltq
cmp    %rax,%r12
jl     11b0 <extract_port_name+0x60>
lea    0xe31(%rip),%rsi
mov    %r14,%rdi
mov    %rbx,%rdx
call   1060 <sprintf@plt>
mov    %r15,%rdi
call   1030 <free@plt>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [8 x i8] c"%s_PORT\00"
define i8* @extract_port_name(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
store i8* %0, i8** %2
%7 = load i8*, i8** %2
%8 = call i32 @strlen(i8* %7)
%9 = add nsw i32 %8, 30
%10 = call i8* @malloc(i32 %9)
store i8* %10, i8** %4
%11 = load i8*, i8** %2
%12 = call i8* @strdup(i8* %11)
store i8* %12, i8** %5
%13 = load i8*, i8** %5
store i8* %13, i8** %6
br label %14
14: ; preds = %20, %1
%15 = load i8*, i8** %5
%16 = getelementptr inbounds i8, i8* %15, i64 0
%17 = load i8, i8* %16
%18 = sext i8 %17 to i32
%19 = icmp ne i32 %18, 0
br i1 %19, label %20, label %23
20: ; preds = %14
%21 = load i8*, i8** %5
%22 = getelementptr inbounds i8, i8* %21, i32 1
store i8* %22, i8** %5
br label %14
23: ; preds = %14
br label %24
24: ; preds = %30, %23
%25 = load i8*, i8** %5
%26 = getelementptr inbounds i8, i8* %25, i64 0
%27 = load i8, i8* %26
%28 = sext i8 %27 to i32
%29 = icmp ne i32 %28, 95
br i1 %29, label %30, label %33
30: ; preds = %24
%31 = load i8*, i8** %5
%32 = getelementptr inbounds i8, i8* %31, i32 -1
store i8* %32, i8** %5
br label %24
33: ; preds = %24
%34 = load i8*, i8** %5
%35 = getelementptr inbounds i8, i8* %34, i32 1
store i8* %35, i8** %5
store i32 0, i32* %3
br label %36
36: ; preds = %55, %33
%37 = load i32, i32* %3
%38 = load i8*, i8** %5
%39 = call i32 @strlen(i8* %38)
%40 = icmp slt i32 %37, %39
br i1 %40, label %41, label %58
41: ; preds = %36
%42 = load i8*, i8** %5
%43 = load i32, i32* %3
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds i8, i8* %42, i64 %44
%46 = load i8, i8* %45
%47 = sext i8 %46 to i32
%48 = sub nsw i32 %47, 97
%49 = add nsw i32 %48, 65
%50 = trunc i32 %49 to i8
%51 = load i8*, i8** %5
%52 = load i32, i32* %3
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds i8, i8* %51, i64 %53
store i8 %50, i8* %54
br label %55
55: ; preds = %41
%56 = load i32, i32* %3
%57 = add nsw i32 %56, 1
store i32 %57, i32* %3
br label %36
58: ; preds = %36
%59 = load i8*, i8** %4
%60 = load i8*, i8** %5
%61 = call i32 @sprintf(i8* %59, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* %60)
%62 = load i8*, i8** %6
%63 = call i32 @free(i8* %62)
%64 = load i8*, i8** %4
ret i8* %64
}

LLVM IR (-O2):
@.str = [8 x i8] c"%s_PORT\00"
define noalias i8* @extract_port_name(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = add nsw i32 %2, 30
%4 = tail call i8* @malloc(i32 %3)
%5 = tail call i8* @strdup(i8* %0)
br label %6
6: ; preds = %6, %1
%7 = phi i8* [ %5, %1 ], [ %10, %6 ]
%8 = load i8, i8* %7
%9 = icmp eq i8 %8, 0
%10 = getelementptr inbounds i8, i8* %7, i64 1
br i1 %9, label %11, label %6
11: ; preds = %6, %11
%12 = phi i8* [ %13, %11 ], [ %7, %6 ]
%13 = getelementptr inbounds i8, i8* %12, i64 -1
%14 = load i8, i8* %13
%15 = icmp eq i8 %14, 95
br i1 %15, label %16, label %11
16: ; preds = %11
%17 = tail call i32 @strlen(i8* %12)
%18 = icmp sgt i32 %17, 0
br i1 %18, label %19, label %28
19: ; preds = %16, %19
%20 = phi i64 [ %24, %19 ], [ 0, %16 ]
%21 = getelementptr inbounds i8, i8* %12, i64 %20
%22 = load i8, i8* %21
%23 = add i8 %22, -32
store i8 %23, i8* %21
%24 = add nuw nsw i64 %20, 1
%25 = tail call i32 @strlen(i8* %12)
%26 = sext i32 %25 to i64
%27 = icmp slt i64 %24, %26
br i1 %27, label %19, label %28
28: ; preds = %19, %16
%29 = tail call i32 @sprintf(i8* dereferenceable(1) %4, i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* %12)
%30 = tail call i32 @free(i8* %5)
ret i8* %4
}