#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*/ __get_cpuid(int, unsigned int *, unsigned int *,
                               unsigned int *, unsigned int *);
int /*<<< orphan*/ detect_packages();
int /*<<< orphan*/ memcpy(char *, unsigned int *, int);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ test_apm_pwr_reporting(unsigned int);
int /*<<< orphan*/ test_tdp_reporting(int);
int main(int argc, char **argv) {
  unsigned int eax, ebx, ecx, edx = 0;
  unsigned int stepping, model, family;
  char vendor_string[13];
  int is_excavator = 0;
  __get_cpuid(0x0, &eax, &ebx, &ecx, &edx);
  memcpy(vendor_string, &ebx, 4);
  memcpy(vendor_string + 4, &edx, 4);
  memcpy(vendor_string + 8, &ecx, 4);
  vendor_string[12] = 0;
  __get_cpuid(0x1, &eax, &ebx, &ecx, &edx);
  stepping = eax & 0xf;
  model = (eax >> 4) & 0xf;
  family = (eax >> 8) & 0xf;
  family += ((eax >> 20) & 0xff);
  model += (((eax >> 16) & 0xf) << 4);
  printf("Looking for AMD APM support...\n");
  printf("\tFound family %d model %d stepping %d %s processor\n", family, model,
         stepping, vendor_string);
  if (strcmp("AuthenticAMD", vendor_string)) {
    printf("Not an AMD processor!  Exiting.\n\n");
    return 0;
  }
  if (family < 0x15) {
    printf("Family %x processor too old (need at least 0x15)\n\n", family);
    return 0;
  }
  if ((family == 0x15) && (model >= 0x60))
    is_excavator = 1;
  detect_packages();
  test_tdp_reporting(is_excavator);
  test_apm_pwr_reporting(family);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x40(%rbp)
xor    %edi,%edi
lea    -0x14(%rbp),%rsi
lea    -0x18(%rbp),%rdx
lea    -0x1c(%rbp),%rcx
lea    -0x20(%rbp),%r8
call   1060 <__get_cpuid@plt>
lea    -0x39(%rbp),%rdi
lea    -0x18(%rbp),%rsi
mov    $0x4,%edx
call   1080 <memcpy@plt>
lea    -0x39(%rbp),%rdi
add    $0x4,%rdi
lea    -0x20(%rbp),%rsi
mov    $0x4,%edx
call   1080 <memcpy@plt>
lea    -0x39(%rbp),%rdi
add    $0x8,%rdi
lea    -0x1c(%rbp),%rsi
mov    $0x4,%edx
call   1080 <memcpy@plt>
movb   $0x0,-0x2d(%rbp)
mov    $0x1,%edi
lea    -0x14(%rbp),%rsi
lea    -0x18(%rbp),%rdx
lea    -0x1c(%rbp),%rcx
lea    -0x20(%rbp),%r8
call   1060 <__get_cpuid@plt>
mov    -0x14(%rbp),%eax
and    $0xf,%eax
mov    %eax,-0x24(%rbp)
mov    -0x14(%rbp),%eax
shr    $0x4,%eax
and    $0xf,%eax
mov    %eax,-0x28(%rbp)
mov    -0x14(%rbp),%eax
shr    $0x8,%eax
and    $0xf,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x14(%rbp),%eax
shr    $0x14,%eax
and    $0xff,%eax
add    -0x2c(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x14(%rbp),%eax
shr    $0x10,%eax
and    $0xf,%eax
shl    $0x4,%eax
add    -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
lea    0xdae(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x2c(%rbp),%esi
mov    -0x28(%rbp),%edx
mov    -0x24(%rbp),%ecx
lea    -0x39(%rbp),%r8
lea    0xdb3(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x39(%rbp),%rsi
lea    0xdd5(%rip),%rdi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
je     12a8 <main+0x138>
lea    0xdcc(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1308 <main+0x198>
cmpl   $0x15,-0x2c(%rbp)
jae    12cf <main+0x15f>
mov    -0x2c(%rbp),%esi
lea    0xdc7(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1308 <main+0x198>
cmpl   $0x15,-0x2c(%rbp)
jne    12ea <main+0x17a>
cmpl   $0x60,-0x28(%rbp)
jb     12ea <main+0x17a>
movl   $0x1,-0x40(%rbp)
mov    $0x0,%al
call   1040 <detect_packages@plt>
mov    -0x40(%rbp),%edi
call   1030 <test_tdp_reporting@plt>
mov    -0x2c(%rbp),%edi
call   1090 <test_apm_pwr_reporting@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x20,%rsp
movl   $0x0,(%rsp)
lea    0x4(%rsp),%r15
lea    0x1c(%rsp),%rbp
lea    0x18(%rsp),%rbx
mov    %rsp,%r12
xor    %edi,%edi
mov    %r15,%rsi
mov    %rbp,%rdx
mov    %rbx,%rcx
mov    %r12,%r8
call   1070 <__get_cpuid@plt>
lea    0xb(%rsp),%r14
mov    %r14,%rdi
mov    %rbp,%rsi
mov    $0x4,%edx
call   1090 <memcpy@plt>
lea    0xf(%rsp),%rdi
mov    %r12,%rsi
mov    $0x4,%edx
call   1090 <memcpy@plt>
lea    0x13(%rsp),%rdi
mov    %rbx,%rsi
mov    $0x4,%edx
call   1090 <memcpy@plt>
movb   $0x0,0x17(%rsp)
mov    $0x1,%edi
mov    %r15,%rsi
mov    %rbp,%rdx
mov    %rbx,%rcx
mov    %r12,%r8
call   1070 <__get_cpuid@plt>
mov    0x4(%rsp),%ebx
mov    %ebx,%ebp
and    $0xf,%ebp
mov    %ebx,%eax
shr    $0x4,%eax
and    $0xf,%eax
mov    %ebx,%ecx
shr    $0x8,%ecx
and    $0xf,%ecx
mov    %ebx,%edx
shr    $0x14,%edx
movzbl %dl,%r15d
add    %ecx,%r15d
shr    $0xc,%ebx
and    $0xf0,%ebx
or     %eax,%ebx
lea    0xe31(%rip),%rdi
call   1030 <puts@plt>
lea    0xdb1(%rip),%rdi
mov    %r15d,%esi
mov    %ebx,%edx
mov    %ebp,%ecx
mov    %r14,%r8
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xdcd(%rip),%rdi
mov    %r14,%rsi
call   1080 <strcmp@plt>
test   %rax,%rax
je     1282 <main+0x102>
lea    0xe18(%rip),%rdi
call   1030 <puts@plt>
jmp    12c3 <main+0x143>
cmp    $0x14,%r15d
ja     129b <main+0x11b>
lea    0xdb2(%rip),%rdi
mov    %r15d,%esi
xor    %eax,%eax
call   1060 <printf@plt>
jmp    12c3 <main+0x143>
cmp    $0x15,%r15d
sete   %al
cmp    $0x60,%ebx
setae  %cl
and    %al,%cl
movzbl %cl,%ebx
xor    %eax,%eax
call   1050 <detect_packages@plt>
mov    %ebx,%edi
call   1040 <test_tdp_reporting@plt>
mov    %r15d,%edi
call   10a0 <test_apm_pwr_reporting@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [32 x i8] c"Looking for AMD APM support...\0A\00"
@.str.1 = [52 x i8] c"\09Found family %d model %d stepping %d %s processor\0A\00"
@.str.2 = [13 x i8] c"AuthenticAMD\00"
@.str.3 = [34 x i8] c"Not an AMD processor! Exiting.\0A\0A\00"
@.str.4 = [51 x i8] c"Family %x processor too old (need at least 0x15)\0A\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca [13 x i8]
%14 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %9
store i32 0, i32* %14
%15 = call i32 @__get_cpuid(i32 0, i32* %6, i32* %7, i32* %8, i32* %9)
%16 = getelementptr inbounds [13 x i8], [13 x i8]* %13, i64 0, i64 0
%17 = call i32 @memcpy(i8* %16, i32* %7, i32 4)
%18 = getelementptr inbounds [13 x i8], [13 x i8]* %13, i64 0, i64 0
%19 = getelementptr inbounds i8, i8* %18, i64 4
%20 = call i32 @memcpy(i8* %19, i32* %9, i32 4)
%21 = getelementptr inbounds [13 x i8], [13 x i8]* %13, i64 0, i64 0
%22 = getelementptr inbounds i8, i8* %21, i64 8
%23 = call i32 @memcpy(i8* %22, i32* %8, i32 4)
%24 = getelementptr inbounds [13 x i8], [13 x i8]* %13, i64 0, i64 12
store i8 0, i8* %24
%25 = call i32 @__get_cpuid(i32 1, i32* %6, i32* %7, i32* %8, i32* %9)
%26 = load i32, i32* %6
%27 = and i32 %26, 15
store i32 %27, i32* %10
%28 = load i32, i32* %6
%29 = lshr i32 %28, 4
%30 = and i32 %29, 15
store i32 %30, i32* %11
%31 = load i32, i32* %6
%32 = lshr i32 %31, 8
%33 = and i32 %32, 15
store i32 %33, i32* %12
%34 = load i32, i32* %6
%35 = lshr i32 %34, 20
%36 = and i32 %35, 255
%37 = load i32, i32* %12
%38 = add i32 %37, %36
store i32 %38, i32* %12
%39 = load i32, i32* %6
%40 = lshr i32 %39, 16
%41 = and i32 %40, 15
%42 = shl i32 %41, 4
%43 = load i32, i32* %11
%44 = add i32 %43, %42
store i32 %44, i32* %11
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
%46 = load i32, i32* %12
%47 = load i32, i32* %11
%48 = load i32, i32* %10
%49 = getelementptr inbounds [13 x i8], [13 x i8]* %13, i64 0, i64 0
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.1, i64 0, i64 0), i32 %46, i32 %47, i32 %48, i8* %49)
%51 = getelementptr inbounds [13 x i8], [13 x i8]* %13, i64 0, i64 0
%52 = call i64 @strcmp(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i8* %51)
%53 = icmp ne i64 %52, 0
br i1 %53, label %54, label %56
54: ; preds = %2
%55 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %3
br label %75
56: ; preds = %2
%57 = load i32, i32* %12
%58 = icmp ult i32 %57, 21
br i1 %58, label %59, label %62
59: ; preds = %56
%60 = load i32, i32* %12
%61 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.4, i64 0, i64 0), i32 %60)
store i32 0, i32* %3
br label %75
62: ; preds = %56
%63 = load i32, i32* %12
%64 = icmp eq i32 %63, 21
br i1 %64, label %65, label %69
65: ; preds = %62
%66 = load i32, i32* %11
%67 = icmp uge i32 %66, 96
br i1 %67, label %68, label %69
68: ; preds = %65
store i32 1, i32* %14
br label %69
69: ; preds = %68, %65, %62
%70 = call i32 (...) @detect_packages()
%71 = load i32, i32* %14
%72 = call i32 @test_tdp_reporting(i32 %71)
%73 = load i32, i32* %12
%74 = call i32 @test_apm_pwr_reporting(i32 %73)
store i32 0, i32* %3
br label %75
75: ; preds = %69, %59, %54
%76 = load i32, i32* %3
ret i32 %76
}

LLVM IR (-O2):
@.str.1 = [52 x i8] c"\09Found family %d model %d stepping %d %s processor\0A\00"
@.str.2 = [13 x i8] c"AuthenticAMD\00"
@.str.4 = [51 x i8] c"Family %x processor too old (need at least 0x15)\0A\0A\00"
@str = [31 x i8] c"Looking for AMD APM support...\00"
@str.5 = [33 x i8] c"Not an AMD processor! Exiting.\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca [13 x i8]
%8 = bitcast i32* %3 to i8*
%9 = bitcast i32* %4 to i8*
%10 = bitcast i32* %5 to i8*
%11 = bitcast i32* %6 to i8*
store i32 0, i32* %6
%12 = getelementptr inbounds [13 x i8], [13 x i8]* %7, i64 0, i64 0
%13 = call i32 @__get_cpuid(i32 0, i32* %3, i32* %4, i32* %5, i32* %6)
%14 = call i32 @memcpy(i8* %12, i32* %4, i32 4)
%15 = getelementptr inbounds [13 x i8], [13 x i8]* %7, i64 0, i64 4
%16 = call i32 @memcpy(i8* %15, i32* %6, i32 4)
%17 = getelementptr inbounds [13 x i8], [13 x i8]* %7, i64 0, i64 8
%18 = call i32 @memcpy(i8* %17, i32* %5, i32 4)
%19 = getelementptr inbounds [13 x i8], [13 x i8]* %7, i64 0, i64 12
store i8 0, i8* %19
%20 = call i32 @__get_cpuid(i32 1, i32* %3, i32* %4, i32* %5, i32* %6)
%21 = load i32, i32* %3
%22 = and i32 %21, 15
%23 = lshr i32 %21, 4
%24 = and i32 %23, 15
%25 = lshr i32 %21, 8
%26 = and i32 %25, 15
%27 = lshr i32 %21, 20
%28 = and i32 %27, 255
%29 = add nuw nsw i32 %26, %28
%30 = lshr i32 %21, 12
%31 = and i32 %30, 240
%32 = or i32 %24, %31
%33 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str, i64 0, i64 0))
%34 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([52 x i8], [52 x i8]* @.str.1, i64 0, i64 0), i32 %29, i32 %32, i32 %22, i8* %12)
%35 = call i64 @strcmp(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i8* %12)
%36 = icmp eq i64 %35, 0
br i1 %36, label %39, label %37
37: ; preds = %2
%38 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @str.5, i64 0, i64 0))
br label %51
39: ; preds = %2
%40 = icmp ult i32 %29, 21
br i1 %40, label %41, label %43
41: ; preds = %39
%42 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([51 x i8], [51 x i8]* @.str.4, i64 0, i64 0), i32 %29)
br label %51
43: ; preds = %39
%44 = icmp eq i32 %29, 21
%45 = icmp ugt i32 %32, 95
%46 = select i1 %44, i1 %45, i1 false
%47 = zext i1 %46 to i32
%48 = call i32 (...) @detect_packages()
%49 = call i32 @test_tdp_reporting(i32 %47)
%50 = call i32 @test_apm_pwr_reporting(i32 %29)
br label %51
51: ; preds = %43, %41, %37
ret i32 0
}