#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int atof(char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ free(char *);
char *malloc(int);
int /*<<< orphan*/ stderr;
float getfreq(char *file) {
  FILE *fd;
  char *freq;
  float ret;
  freq = malloc(10);
  fd = fopen(file, "r");
  if (fd == NULL) {
    fprintf(stderr, "Cannot open '%s' for reading.\n", file);
    exit(1);
  }
  fgets(freq, 10, fd);
  fclose(fd);
  ret = atof(freq) / 1000000;
  free(freq);
  return ret;
}


x86 assembly (clang, -O0):
<getfreq>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0xa,%edi
call   1080 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe5b(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11dc <getfreq+0x5c>
mov    0x2e20(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe35(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0xa,%esi
call   1060 <fgets@plt>
mov    -0x10(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x18(%rbp),%rdi
call   1040 <atof@plt>
mov    $0xf4240,%ecx
cltd
idiv   %ecx
cvtsi2ss %eax,%xmm0
movss  %xmm0,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
movss  -0x1c(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getfreq>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%r14
mov    $0xa,%edi
call   1080 <malloc@plt>
mov    %rax,%r15
lea    0xe60(%rip),%rsi
mov    %r14,%rdi
call   1090 <fopen@plt>
test   %rax,%rax
je     1208 <getfreq+0x88>
mov    %rax,%rbx
mov    %r15,%rdi
mov    $0xa,%esi
mov    %rax,%rdx
call   1060 <fgets@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
mov    %r15,%rdi
call   1040 <atof@plt>
cltq
imul   $0x431bde83,%rax,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x32,%rax
add    %ecx,%eax
cvtsi2ss %eax,%xmm0
movss  %xmm0,0xc(%rsp)
mov    %r15,%rdi
call   1030 <free@plt>
movss  0xc(%rsp),%xmm0
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
mov    0x2dd1(%rip),%rax
mov    (%rax),%edi
lea    0xdea(%rip),%rsi
mov    %r14,%rdx
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [31 x i8] c"Cannot open '%s' for reading.\0A\00"
define float @getfreq(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i8*
%5 = alloca float
store i8* %0, i8** %2
%6 = call i8* @malloc(i32 10)
store i8* %6, i8** %4
%7 = load i8*, i8** %2
%8 = call i32* @fopen(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %8, i32** %3
%9 = load i32*, i32** %3
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %16
11: ; preds = %1
%12 = load i32, i32* @stderr
%13 = load i8*, i8** %2
%14 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i8* %13)
%15 = call i32 @exit(i32 1)
unreachable
16: ; preds = %1
%17 = load i8*, i8** %4
%18 = load i32*, i32** %3
%19 = call i32 @fgets(i8* %17, i32 10, i32* %18)
%20 = load i32*, i32** %3
%21 = call i32 @fclose(i32* %20)
%22 = load i8*, i8** %4
%23 = call i32 @atof(i8* %22)
%24 = sdiv i32 %23, 1000000
%25 = sitofp i32 %24 to float
store float %25, float* %5
%26 = load i8*, i8** %4
%27 = call i32 @free(i8* %26)
%28 = load float, float* %5
ret float %28
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [31 x i8] c"Cannot open '%s' for reading.\0A\00"
define float @getfreq(i8* %0) {
%2 = tail call dereferenceable_or_null(10) i8* @malloc(i32 10)
%3 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %9
5: ; preds = %1
%6 = load i32, i32* @stderr
%7 = tail call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%8 = tail call i32 @exit(i32 1)
unreachable
9: ; preds = %1
%10 = tail call i32 @fgets(i8* %2, i32 10, i32* %3)
%11 = tail call i32 @fclose(i32* %3)
%12 = tail call i32 @atof(i8* %2)
%13 = sdiv i32 %12, 1000000
%14 = sitofp i32 %13 to float
%15 = tail call i32 @free(i8* %2)
ret float %14
}