#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 /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, double *);
int /*<<< orphan*/ *open_file(char *, char *);
int /*<<< orphan*/ printf(char *);
void init_device_ratio_file(double *device_ratio, int cpu_number,
                            int mic_number, char *file_ratio) {
  FILE *fp = open_file(file_ratio, "r");
  int i;
  for (i = 0; i < cpu_number + mic_number; i++) {
    fscanf(fp, "%lf", device_ratio + i);
    if (device_ratio[i] <= 0) {
      printf("device ratio can't be zero or negative\n");
      fclose(fp);
      exit(1);
    }
  }
  fclose(fp);
}


x86 assembly (clang, -O0):
<init_device_ratio_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe8f(%rip),%rsi
call   1040 <open_file@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    -0xc(%rbp),%ecx
add    -0x10(%rbp),%ecx
cmp    %ecx,%eax
jge    11f9 <init_device_ratio_file+0xa9>
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rdx
movslq -0x24(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rdx
lea    0xe56(%rip),%rsi
call   1060 <fscanf@plt>
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
xorps  %xmm0,%xmm0
ucomisd (%rax,%rcx,8),%xmm0
jb     11e6 <init_device_ratio_file+0x96>
lea    0xe38(%rip),%rdi
call   1050 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
jmp    11eb <init_device_ratio_file+0x9b>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1181 <init_device_ratio_file+0x31>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<init_device_ratio_file>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%r15d
mov    %esi,%ebp
mov    %rdi,%rbx
lea    0xea2(%rip),%rsi
mov    %rcx,%rdi
call   1050 <open_file@plt>
mov    %rax,%r14
add    %r15d,%ebp
test   %ebp,%ebp
jle    11b2 <init_device_ratio_file+0x62>
mov    %ebp,%ebp
lea    0xe89(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
call   1060 <fscanf@plt>
xorpd  %xmm0,%xmm0
ucomisd (%rbx),%xmm0
jae    11c4 <init_device_ratio_file+0x74>
add    $0x8,%rbx
add    $0xffffffffffffffff,%rbp
jne    1190 <init_device_ratio_file+0x40>
mov    %r14,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <fclose@plt>
lea    0xe43(%rip),%rdi
call   1030 <puts@plt>
mov    %r14,%rdi
call   1040 <fclose@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [4 x i8] c"%lf\00"
@.str.2 = [40 x i8] c"device ratio can't be zero or negative\0A\00"
define void @init_device_ratio_file(double* %0, i32 %1, i32 %2, i8* %3) {
%5 = alloca double*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32*
%10 = alloca i32
store double* %0, double** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i8* %3, i8** %8
%11 = load i8*, i8** %8
%12 = call i32* @open_file(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %12, i32** %9
store i32 0, i32* %10
br label %13
13: ; preds = %38, %4
%14 = load i32, i32* %10
%15 = load i32, i32* %6
%16 = load i32, i32* %7
%17 = add nsw i32 %15, %16
%18 = icmp slt i32 %14, %17
br i1 %18, label %19, label %41
19: ; preds = %13
%20 = load i32*, i32** %9
%21 = load double*, double** %5
%22 = load i32, i32* %10
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds double, double* %21, i64 %23
%25 = call i32 @fscanf(i32* %20, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), double* %24)
%26 = load double*, double** %5
%27 = load i32, i32* %10
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds double, double* %26, i64 %28
%30 = load double, double* %29
%31 = fcmp ole double %30, 0.000000e+00
br i1 %31, label %32, label %37
32: ; preds = %19
%33 = call i32 @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0))
%34 = load i32*, i32** %9
%35 = call i32 @fclose(i32* %34)
%36 = call i32 @exit(i32 1)
unreachable
37: ; preds = %19
br label %38
38: ; preds = %37
%39 = load i32, i32* %10
%40 = add nsw i32 %39, 1
store i32 %40, i32* %10
br label %13
41: ; preds = %13
%42 = load i32*, i32** %9
%43 = call i32 @fclose(i32* %42)
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [4 x i8] c"%lf\00"
@str = [39 x i8] c"device ratio can't be zero or negative\00"
define void @init_device_ratio_file(double* %0, i32 %1, i32 %2, i8* %3) {
%5 = tail call i32* @open_file(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%6 = add i32 %2, %1
%7 = icmp sgt i32 %6, 0
br i1 %7, label %8, label %23
8: ; preds = %4
%9 = zext i32 %6 to i64
br label %12
10: ; preds = %12
%11 = icmp eq i64 %18, %9
br i1 %11, label %23, label %12
12: ; preds = %8, %10
%13 = phi i64 [ 0, %8 ], [ %18, %10 ]
%14 = getelementptr inbounds double, double* %0, i64 %13
%15 = tail call i32 @fscanf(i32* %5, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), double* %14)
%16 = load double, double* %14
%17 = fcmp ugt double %16, 0.000000e+00
%18 = add nuw nsw i64 %13, 1
br i1 %17, label %10, label %19
19: ; preds = %12
%20 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @str, i64 0, i64 0))
%21 = tail call i32 @fclose(i32* %5)
%22 = tail call i32 @exit(i32 1)
unreachable
23: ; preds = %10, %4
%24 = tail call i32 @fclose(i32* %5)
ret void
}