#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*/ print(char *, unsigned int, unsigned int, unsigned int, ...);
int getprocaddressa(unsigned h, const char *proc) {
  unsigned p = (unsigned)proc;
  if (p < 0x10000) {
    print("getprocaddressa called %c%c%c, ordinal %u\n", h, h >> 8, h >> 16, p);
    return h + p * 0x10000;
  }
  print("getprocaddressa called %c%c%c, name %s\n", h, h >> 8, h >> 16, proc);
  return h + proc[0] * 0x10000 + proc[1] * 0x1000000;
}


x86 assembly (clang, -O0):
<getprocaddressa>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %eax,-0x14(%rbp)
cmpl   $0x10000,-0x14(%rbp)
jae    1167 <getprocaddressa+0x57>
mov    -0x8(%rbp),%esi
mov    -0x8(%rbp),%edx
shr    $0x8,%edx
mov    -0x8(%rbp),%ecx
shr    $0x10,%ecx
mov    -0x14(%rbp),%r8d
lea    0xeb3(%rip),%rdi
mov    $0x0,%al
call   1030 <print@plt>
mov    -0x8(%rbp),%eax
mov    -0x14(%rbp),%ecx
shl    $0x10,%ecx
add    %ecx,%eax
mov    %eax,-0x4(%rbp)
jmp    11a7 <getprocaddressa+0x97>
mov    -0x8(%rbp),%esi
mov    -0x8(%rbp),%edx
shr    $0x8,%edx
mov    -0x8(%rbp),%ecx
shr    $0x10,%ecx
mov    -0x10(%rbp),%r8
lea    0xeaa(%rip),%rdi
mov    $0x0,%al
call   1030 <print@plt>
mov    -0x8(%rbp),%eax
mov    -0x10(%rbp),%rcx
movsbl (%rcx),%ecx
shl    $0x10,%ecx
add    %ecx,%eax
mov    -0x10(%rbp),%rcx
movsbl 0x1(%rcx),%ecx
shl    $0x18,%ecx
add    %ecx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getprocaddressa>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%ebp
mov    %edi,%edx
shr    $0x8,%edx
mov    %edi,%ecx
shr    $0x10,%ecx
cmp    $0xffff,%ebx
ja     1144 <getprocaddressa+0x34>
lea    0xecf(%rip),%rdi
mov    %ebp,%esi
mov    %ebx,%r8d
xor    %eax,%eax
call   1030 <print@plt>
shl    $0x10,%ebx
add    %ebp,%ebx
jmp    1168 <getprocaddressa+0x58>
lea    0xee0(%rip),%rdi
mov    %ebp,%esi
mov    %rbx,%r8
xor    %eax,%eax
call   1030 <print@plt>
movsbl (%rbx),%eax
shl    $0x10,%eax
add    %ebp,%eax
movzbl 0x1(%rbx),%ebx
shl    $0x18,%ebx
add    %eax,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [43 x i8] c"getprocaddressa called %c%c%c, ordinal %u\0A\00"
@.str.1 = [40 x i8] c"getprocaddressa called %c%c%c, name %s\0A\00"
define i32 @getprocaddressa(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
store i32 %0, i32* %4
store i8* %1, i8** %5
%7 = load i8*, i8** %5
%8 = ptrtoint i8* %7 to i32
store i32 %8, i32* %6
%9 = load i32, i32* %6
%10 = icmp ult i32 %9, 65536
br i1 %10, label %11, label %23
11: ; preds = %2
%12 = load i32, i32* %4
%13 = load i32, i32* %4
%14 = lshr i32 %13, 8
%15 = load i32, i32* %4
%16 = lshr i32 %15, 16
%17 = load i32, i32* %6
%18 = call i32 (i8*, i32, i32, i32, ...) @print(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), i32 %12, i32 %14, i32 %16, i32 %17)
%19 = load i32, i32* %4
%20 = load i32, i32* %6
%21 = mul i32 %20, 65536
%22 = add i32 %19, %21
store i32 %22, i32* %3
br label %44
23: ; preds = %2
%24 = load i32, i32* %4
%25 = load i32, i32* %4
%26 = lshr i32 %25, 8
%27 = load i32, i32* %4
%28 = lshr i32 %27, 16
%29 = load i8*, i8** %5
%30 = call i32 (i8*, i32, i32, i32, ...) @print(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0), i32 %24, i32 %26, i32 %28, i8* %29)
%31 = load i32, i32* %4
%32 = load i8*, i8** %5
%33 = getelementptr inbounds i8, i8* %32, i64 0
%34 = load i8, i8* %33
%35 = sext i8 %34 to i32
%36 = mul nsw i32 %35, 65536
%37 = add i32 %31, %36
%38 = load i8*, i8** %5
%39 = getelementptr inbounds i8, i8* %38, i64 1
%40 = load i8, i8* %39
%41 = sext i8 %40 to i32
%42 = mul nsw i32 %41, 16777216
%43 = add i32 %37, %42
store i32 %43, i32* %3
br label %44
44: ; preds = %23, %11
%45 = load i32, i32* %3
ret i32 %45
}

LLVM IR (-O2):
@.str = [43 x i8] c"getprocaddressa called %c%c%c, ordinal %u\0A\00"
@.str.1 = [40 x i8] c"getprocaddressa called %c%c%c, name %s\0A\00"
define i32 @getprocaddressa(i32 %0, i8* %1) {
%3 = ptrtoint i8* %1 to i64
%4 = trunc i64 %3 to i32
%5 = icmp ult i32 %4, 65536
%6 = lshr i32 %0, 8
%7 = lshr i32 %0, 16
br i1 %5, label %8, label %12
8: ; preds = %2
%9 = tail call i32 (i8*, i32, i32, i32, ...) @print(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), i32 %0, i32 %6, i32 %7, i32 %4)
%10 = shl nuw i32 %4, 16
%11 = add i32 %10, %0
br label %23
12: ; preds = %2
%13 = tail call i32 (i8*, i32, i32, i32, ...) @print(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0), i32 %0, i32 %6, i32 %7, i8* %1)
%14 = load i8, i8* %1
%15 = sext i8 %14 to i32
%16 = shl nsw i32 %15, 16
%17 = add i32 %16, %0
%18 = getelementptr inbounds i8, i8* %1, i64 1
%19 = load i8, i8* %18
%20 = sext i8 %19 to i32
%21 = shl nsw i32 %20, 24
%22 = add i32 %17, %21
br label %23
23: ; preds = %12, %8
%24 = phi i32 [ %11, %8 ], [ %22, %12 ]
ret i32 %24
}