#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 EINVAL;
unsigned long cpufreq_get_transition_latency(unsigned int);
int /*<<< orphan*/ print_duration(unsigned long);
int /*<<< orphan*/ printf(char *, ...);
int get_latency(unsigned int cpu, unsigned int human) {
  unsigned long latency = cpufreq_get_transition_latency(cpu);
  if (!latency)
    return -EINVAL;
  if (human) {
    print_duration(latency);
    printf("\n");
  } else
    printf("%lu\n", latency);
  return 0;
}


x86 assembly (clang, -O0):
<get_latency>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%edi
call   1050 <cpufreq_get_transition_latency@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1168 <get_latency+0x38>
xor    %eax,%eax
mov    0x2e82(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    11a7 <get_latency+0x77>
cmpl   $0x0,-0xc(%rbp)
je     118e <get_latency+0x5e>
mov    -0x18(%rbp),%rdi
call   1030 <print_duration@plt>
lea    0xe81(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11a0 <get_latency+0x70>
mov    -0x18(%rbp),%rsi
lea    0xe67(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_latency>:
push   %rbx
mov    %esi,%ebx
call   1060 <cpufreq_get_transition_latency@plt>
test   %rax,%rax
je     1167 <get_latency+0x27>
test   %ebx,%ebx
je     1174 <get_latency+0x34>
mov    %rax,%rdi
call   1040 <print_duration@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %ebx,%ebx
jmp    1187 <get_latency+0x47>
mov    0x2e72(%rip),%rax
xor    %ebx,%ebx
sub    (%rax),%ebx
jmp    1187 <get_latency+0x47>
lea    0xe85(%rip),%rdi
xor    %ebx,%ebx
mov    %rax,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
@EINVAL = global i32 0
@.str = [2 x i8] c"\0A\00"
@.str.1 = [5 x i8] c"%lu\0A\00"
define i32 @get_latency(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i64
store i32 %0, i32* %4
store i32 %1, i32* %5
%7 = load i32, i32* %4
%8 = call i64 @cpufreq_get_transition_latency(i32 %7)
store i64 %8, i64* %6
%9 = load i64, i64* %6
%10 = icmp ne i64 %9, 0
br i1 %10, label %14, label %11
11: ; preds = %2
%12 = load i32, i32* @EINVAL
%13 = sub nsw i32 0, %12
store i32 %13, i32* %3
br label %25
14: ; preds = %2
%15 = load i32, i32* %5
%16 = icmp ne i32 %15, 0
br i1 %16, label %17, label %21
17: ; preds = %14
%18 = load i64, i64* %6
%19 = call i32 @print_duration(i64 %18)
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %24
21: ; preds = %14
%22 = load i64, i64* %6
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i64 %22)
br label %24
24: ; preds = %21, %17
store i32 0, i32* %3
br label %25
25: ; preds = %24, %11
%26 = load i32, i32* %3
ret i32 %26
}

LLVM IR (-O2):
@EINVAL = global i32 0
@.str.1 = [5 x i8] c"%lu\0A\00"
define i32 @get_latency(i32 %0, i32 %1) {
%3 = tail call i64 @cpufreq_get_transition_latency(i32 %0)
%4 = icmp eq i64 %3, 0
br i1 %4, label %5, label %8
5: ; preds = %2
%6 = load i32, i32* @EINVAL
%7 = sub nsw i32 0, %6
br label %15
8: ; preds = %2
%9 = icmp eq i32 %1, 0
br i1 %9, label %13, label %10
10: ; preds = %8
%11 = tail call i32 @print_duration(i64 %3)
%12 = tail call i32 @putchar(i32 10)
br label %15
13: ; preds = %8
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i64 %3)
br label %15
15: ; preds = %10, %13, %5
%16 = phi i32 [ %7, %5 ], [ 0, %13 ], [ 0, %10 ]
ret i32 %16
}