#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 */
struct ss7 {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ memcpy(char *, unsigned char *, int);
int /*<<< orphan*/ ss7_message(struct ss7 *, char *, ...);
int((generic_name_dump))(struct ss7 *ss7, int messagetype, unsigned char *parm,
                         int len) {
  unsigned int typeofname = (parm[0] >> 5) & 0x7;
  unsigned int avail = (parm[0] >> 4) & 0x1;
  unsigned int presentation = parm[0] & 0x3;
  char name[16 + 1];
  memcpy(name, &parm[1], len - 1);
  ss7_message(ss7, "\t\t\tType of Name: %s (%d)\n",
              (typeofname == 1) ? "Calling Name" : "Unknown", typeofname);
  ss7_message(ss7, "\t\t\tAvail: %s (%d)\n",
              (avail == 1) ? "Name not available"
                           : "Name available, or availability unknown",
              avail);
  ss7_message(ss7, "\t\t\tPresentation: %d\n", presentation);
  ss7_message(ss7, "\t\t\tName: %s\n", name);
  return len;
}


x86 assembly (clang, -O0):
<generic_name_dump>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    -0x18(%rbp),%rax
movzbl (%rax),%eax
sar    $0x5,%eax
and    $0x7,%eax
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
movzbl (%rax),%eax
sar    $0x4,%eax
and    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%rax
movzbl (%rax),%eax
and    $0x3,%eax
mov    %eax,-0x28(%rbp)
lea    -0x40(%rbp),%rdi
mov    -0x18(%rbp),%rsi
add    $0x1,%rsi
mov    -0x1c(%rbp),%edx
sub    $0x1,%edx
call   1030 <memcpy@plt>
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%ecx
lea    0xe9f(%rip),%rdx
lea    0xe8b(%rip),%rax
cmp    $0x1,%ecx
cmove  %rax,%rdx
mov    -0x20(%rbp),%ecx
lea    0xe60(%rip),%rsi
mov    $0x0,%al
call   1040 <ss7_message@plt>
mov    -0x8(%rbp),%rdi
mov    -0x24(%rbp),%ecx
lea    0xea0(%rip),%rdx
lea    0xe86(%rip),%rax
cmp    $0x1,%ecx
cmove  %rax,%rdx
mov    -0x24(%rbp),%ecx
lea    0xe62(%rip),%rsi
mov    $0x0,%al
call   1040 <ss7_message@plt>
mov    -0x8(%rbp),%rdi
mov    -0x28(%rbp),%edx
lea    0xe9b(%rip),%rsi
mov    $0x0,%al
call   1040 <ss7_message@plt>
mov    -0x8(%rbp),%rdi
lea    -0x40(%rbp),%rdx
lea    0xe9a(%rip),%rsi
mov    $0x0,%al
call   1040 <ss7_message@plt>
mov    -0x1c(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<generic_name_dump>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %ecx,%r14d
mov    %rdi,%r12
movzbl (%rdx),%r13d
mov    %r13d,%ebx
shr    $0x5,%ebx
mov    %r13d,%ebp
shr    $0x4,%ebp
and    $0x3,%r13d
lea    0x1(%rdx),%rsi
lea    -0x1(%r14),%edx
mov    %rsp,%r15
mov    %r15,%rdi
call   1030 <memcpy@plt>
cmp    $0x1,%ebx
lea    0xeb5(%rip),%rax
lea    0xebb(%rip),%rdx
cmove  %rax,%rdx
lea    0xe89(%rip),%rsi
mov    %r12,%rdi
mov    %ebx,%ecx
xor    %eax,%eax
call   1040 <ss7_message@plt>
and    $0x1,%ebp
lea    0xec8(%rip),%rax
lea    0xeae(%rip),%rdx
cmove  %rax,%rdx
lea    0xe90(%rip),%rsi
mov    %r12,%rdi
mov    %ebp,%ecx
xor    %eax,%eax
call   1040 <ss7_message@plt>
lea    0xecb(%rip),%rsi
mov    %r12,%rdi
mov    %r13d,%edx
xor    %eax,%eax
call   1040 <ss7_message@plt>
lea    0xecc(%rip),%rsi
mov    %r12,%rdi
mov    %r15,%rdx
xor    %eax,%eax
call   1040 <ss7_message@plt>
mov    %r14d,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.ss7 = type { i32 }
@.str = [26 x i8] c"\09\09\09Type of Name: %s (%d)\0A\00"
@.str.1 = [13 x i8] c"Calling Name\00"
@.str.2 = [8 x i8] c"Unknown\00"
@.str.3 = [19 x i8] c"\09\09\09Avail: %s (%d)\0A\00"
@.str.4 = [19 x i8] c"Name not available\00"
@.str.5 = [40 x i8] c"Name available, or availability unknown\00"
@.str.6 = [21 x i8] c"\09\09\09Presentation: %d\0A\00"
@.str.7 = [13 x i8] c"\09\09\09Name: %s\0A\00"
define i32 @generic_name_dump(%struct.ss7* %0, i32 %1, i8* %2, i32 %3) {
%5 = alloca %struct.ss7*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca [17 x i8]
store %struct.ss7* %0, %struct.ss7** %5
store i32 %1, i32* %6
store i8* %2, i8** %7
store i32 %3, i32* %8
%13 = load i8*, i8** %7
%14 = getelementptr inbounds i8, i8* %13, i64 0
%15 = load i8, i8* %14
%16 = zext i8 %15 to i32
%17 = ashr i32 %16, 5
%18 = and i32 %17, 7
store i32 %18, i32* %9
%19 = load i8*, i8** %7
%20 = getelementptr inbounds i8, i8* %19, i64 0
%21 = load i8, i8* %20
%22 = zext i8 %21 to i32
%23 = ashr i32 %22, 4
%24 = and i32 %23, 1
store i32 %24, i32* %10
%25 = load i8*, i8** %7
%26 = getelementptr inbounds i8, i8* %25, i64 0
%27 = load i8, i8* %26
%28 = zext i8 %27 to i32
%29 = and i32 %28, 3
store i32 %29, i32* %11
%30 = getelementptr inbounds [17 x i8], [17 x i8]* %12, i64 0, i64 0
%31 = load i8*, i8** %7
%32 = getelementptr inbounds i8, i8* %31, i64 1
%33 = load i32, i32* %8
%34 = sub nsw i32 %33, 1
%35 = call i32 @memcpy(i8* %30, i8* %32, i32 %34)
%36 = load %struct.ss7*, %struct.ss7** %5
%37 = load i32, i32* %9
%38 = icmp eq i32 %37, 1
%39 = zext i1 %38 to i64
%40 = select i1 %38, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0)
%41 = load i32, i32* %9
%42 = call i32 (%struct.ss7*, i8*, ...) @ss7_message(%struct.ss7* %36, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i8* %40, i32 %41)
%43 = load %struct.ss7*, %struct.ss7** %5
%44 = load i32, i32* %10
%45 = icmp eq i32 %44, 1
%46 = zext i1 %45 to i64
%47 = select i1 %45, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.5, i64 0, i64 0)
%48 = load i32, i32* %10
%49 = call i32 (%struct.ss7*, i8*, ...) @ss7_message(%struct.ss7* %43, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i8* %47, i32 %48)
%50 = load %struct.ss7*, %struct.ss7** %5
%51 = load i32, i32* %11
%52 = call i32 (%struct.ss7*, i8*, ...) @ss7_message(%struct.ss7* %50, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.6, i64 0, i64 0), i32 %51)
%53 = load %struct.ss7*, %struct.ss7** %5
%54 = getelementptr inbounds [17 x i8], [17 x i8]* %12, i64 0, i64 0
%55 = call i32 (%struct.ss7*, i8*, ...) @ss7_message(%struct.ss7* %53, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.7, i64 0, i64 0), i8* %54)
%56 = load i32, i32* %8
ret i32 %56
}

LLVM IR (-O2):
%struct.ss7 = type { i32 }
@.str = [26 x i8] c"\09\09\09Type of Name: %s (%d)\0A\00"
@.str.1 = [13 x i8] c"Calling Name\00"
@.str.2 = [8 x i8] c"Unknown\00"
@.str.3 = [19 x i8] c"\09\09\09Avail: %s (%d)\0A\00"
@.str.4 = [19 x i8] c"Name not available\00"
@.str.5 = [40 x i8] c"Name available, or availability unknown\00"
@.str.6 = [21 x i8] c"\09\09\09Presentation: %d\0A\00"
@.str.7 = [13 x i8] c"\09\09\09Name: %s\0A\00"
define i32 @generic_name_dump(%struct.ss7* %0, i32 %1, i8* %2, i32 returned %3) {
%5 = alloca [17 x i8]
%6 = load i8, i8* %2
%7 = zext i8 %6 to i32
%8 = lshr i32 %7, 5
%9 = lshr i32 %7, 4
%10 = and i32 %9, 1
%11 = and i32 %7, 3
%12 = getelementptr inbounds [17 x i8], [17 x i8]* %5, i64 0, i64 0
%13 = getelementptr inbounds i8, i8* %2, i64 1
%14 = add nsw i32 %3, -1
%15 = call i32 @memcpy(i8* %12, i8* %13, i32 %14)
%16 = icmp eq i32 %8, 1
%17 = select i1 %16, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0)
%18 = call i32 (%struct.ss7*, i8*, ...) @ss7_message(%struct.ss7* %0, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i8* %17, i32 %8)
%19 = icmp eq i32 %10, 0
%20 = select i1 %19, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0)
%21 = call i32 (%struct.ss7*, i8*, ...) @ss7_message(%struct.ss7* %0, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i8* %20, i32 %10)
%22 = call i32 (%struct.ss7*, i8*, ...) @ss7_message(%struct.ss7* %0, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.6, i64 0, i64 0), i32 %11)
%23 = call i32 (%struct.ss7*, i8*, ...) @ss7_message(%struct.ss7* %0, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.7, i64 0, i64 0), i8* %12)
ret i32 %3
}