#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
size_t fread(void *, int, int, int /*<<< orphan*/ *);
void paillier_get_rand_file(void *buf, int len, char *file) {
  FILE *fp;
  void *p;
  fp = fopen(file, "r");
  p = buf;
  while (len) {
    size_t s;
    s = fread(p, 1, len, fp);
    p += s;
    len -= s;
  }
  fclose(fp);
}


x86 assembly (clang, -O0):
<paillier_get_rand_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xeb2(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     11a1 <paillier_get_rand_file+0x71>
mov    -0x28(%rbp),%rdi
mov    -0xc(%rbp),%edx
mov    -0x20(%rbp),%rcx
mov    $0x1,%esi
call   1030 <fread@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
add    -0x28(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x30(%rbp),%rcx
movslq -0xc(%rbp),%rax
sub    %rcx,%rax
mov    %eax,-0xc(%rbp)
jmp    115f <paillier_get_rand_file+0x2f>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<paillier_get_rand_file>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%ebp
mov    %rdi,%rbx
lea    0xec0(%rip),%rsi
mov    %rdx,%rdi
call   1050 <fopen@plt>
mov    %rax,%r14
test   %ebp,%ebp
je     1169 <paillier_get_rand_file+0x39>
nop
mov    %rbx,%rdi
mov    $0x1,%esi
mov    %ebp,%edx
mov    %r14,%rcx
call   1030 <fread@plt>
add    %rax,%rbx
sub    %eax,%ebp
jne    1150 <paillier_get_rand_file+0x20>
mov    %r14,%rdi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1040 <fclose@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
define void @paillier_get_rand_file(i8* %0, i32 %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32*
%8 = alloca i8*
%9 = alloca i64
store i8* %0, i8** %4
store i32 %1, i32* %5
store i8* %2, i8** %6
%10 = load i8*, i8** %6
%11 = call i32* @fopen(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %11, i32** %7
%12 = load i8*, i8** %4
store i8* %12, i8** %8
br label %13
13: ; preds = %16, %3
%14 = load i32, i32* %5
%15 = icmp ne i32 %14, 0
br i1 %15, label %16, label %29
16: ; preds = %13
%17 = load i8*, i8** %8
%18 = load i32, i32* %5
%19 = load i32*, i32** %7
%20 = call i64 @fread(i8* %17, i32 1, i32 %18, i32* %19)
store i64 %20, i64* %9
%21 = load i64, i64* %9
%22 = load i8*, i8** %8
%23 = getelementptr i8, i8* %22, i64 %21
store i8* %23, i8** %8
%24 = load i64, i64* %9
%25 = load i32, i32* %5
%26 = sext i32 %25 to i64
%27 = sub i64 %26, %24
%28 = trunc i64 %27 to i32
store i32 %28, i32* %5
br label %13
29: ; preds = %13
%30 = load i32*, i32** %7
%31 = call i32 @fclose(i32* %30)
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
define void @paillier_get_rand_file(i8* nocapture %0, i32 %1, i8* nocapture %2) {
%4 = tail call i32* @fopen(i8* %2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i32 %1, 0
br i1 %5, label %14, label %6
6: ; preds = %3, %6
%7 = phi i32 [ %12, %6 ], [ %1, %3 ]
%8 = phi i8* [ %10, %6 ], [ %0, %3 ]
%9 = tail call i64 @fread(i8* %8, i32 1, i32 %7, i32* %4)
%10 = getelementptr i8, i8* %8, i64 %9
%11 = trunc i64 %9 to i32
%12 = sub i32 %7, %11
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %6
14: ; preds = %6, %3
%15 = tail call i32 @fclose(i32* %4)
ret void
}