#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*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int read(int, char *, int);
int /*<<< orphan*/ stderr;
int get_freq(int fd, int num_bytes) {
  int freq = 0, i = 0, ret = 0;
  char *ptr = (char *)&freq;
  for (i = (num_bytes - 1); i >= 0; i--) {
    if ((ret = read(fd, ptr + i, sizeof(char))) != 1) {
      fprintf(stderr, "Failure to read the frequency a certain character.\n");
      exit(1);
    }
  }
  return freq;
}


x86 assembly (clang, -O0):
<get_freq>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
lea    -0xc(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jl     11c4 <get_freq+0x94>
mov    -0x4(%rbp),%edi
mov    -0x20(%rbp),%rsi
movslq -0x10(%rbp),%rax
add    %rax,%rsi
mov    $0x1,%edx
call   1030 <read@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x1,%eax
je     11b1 <get_freq+0x81>
mov    0x2e47(%rip),%rax
mov    (%rax),%edi
lea    0xe5e(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
jmp    11b6 <get_freq+0x86>
mov    -0x10(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x10(%rbp)
jmp    1164 <get_freq+0x34>
mov    -0xc(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_freq>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %esi,%ebx
mov    %edi,%r14d
movl   $0x0,0xc(%rsp)
mov    %esi,%eax
lea    0xc(%rsp),%rcx
lea    (%rax,%rcx,1),%rbp
add    $0xffffffffffffffff,%rbp
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
test   %ebx,%ebx
jle    119f <get_freq+0x6f>
mov    %r14d,%edi
mov    %rbp,%rsi
mov    $0x1,%edx
call   1030 <read@plt>
add    $0xffffffff,%ebx
add    $0xffffffffffffffff,%rbp
cmp    $0x1,%eax
je     1160 <get_freq+0x30>
mov    0x2e59(%rip),%rax
mov    (%rax),%edi
lea    0xe70(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
mov    0xc(%rsp),%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [52 x i8] c"Failure to read the frequency a certain character.\0A\00"
define i32 @get_freq(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
store i32 %0, i32* %3
store i32 %1, i32* %4
store i32 0, i32* %5
store i32 0, i32* %6
store i32 0, i32* %7
%9 = bitcast i32* %5 to i8*
store i8* %9, i8** %8
%10 = load i32, i32* %4
%11 = sub nsw i32 %10, 1
store i32 %11, i32* %6
br label %12
12: ; preds = %28, %2
%13 = load i32, i32* %6
%14 = icmp sge i32 %13, 0
br i1 %14, label %15, label %31
15: ; preds = %12
%16 = load i32, i32* %3
%17 = load i8*, i8** %8
%18 = load i32, i32* %6
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i8, i8* %17, i64 %19
%21 = call i32 @read(i32 %16, i8* %20, i32 1)
store i32 %21, i32* %7
%22 = icmp ne i32 %21, 1
br i1 %22, label %23, label %27
23: ; preds = %15
%24 = load i32, i32* @stderr
%25 = call i32 @fprintf(i32 %24, i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str, i64 0, i64 0))
%26 = call i32 @exit(i32 1)
unreachable
27: ; preds = %15
br label %28
28: ; preds = %27
%29 = load i32, i32* %6
%30 = add nsw i32 %29, -1
store i32 %30, i32* %6
br label %12
31: ; preds = %12
%32 = load i32, i32* %5
ret i32 %32
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [52 x i8] c"Failure to read the frequency a certain character.\0A\00"
define i32 @get_freq(i32 %0, i32 %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%5 = zext i32 %1 to i64
br label %6
6: ; preds = %11, %2
%7 = phi i64 [ %8, %11 ], [ %5, %2 ]
%8 = add nsw i64 %7, -1
%9 = trunc i64 %7 to i32
%10 = icmp sgt i32 %9, 0
br i1 %10, label %11, label %19
11: ; preds = %6
%12 = getelementptr inbounds i8, i8* %4, i64 %8
%13 = call i32 @read(i32 %0, i8* %12, i32 1)
%14 = icmp eq i32 %13, 1
br i1 %14, label %6, label %15
15: ; preds = %11
%16 = load i32, i32* @stderr
%17 = tail call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str, i64 0, i64 0))
%18 = tail call i32 @exit(i32 1)
unreachable
19: ; preds = %6
%20 = load i32, i32* %3
ret i32 %20
}