#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 */
scalar_t__ EOF;
int /*<<< orphan*/ EXIT_FAILURE;
scalar_t__ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
scalar_t__ fscanf(int /*<<< orphan*/ *, char *, char *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, long, int /*<<< orphan*/);
int /*<<< orphan*/ ftell(int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
int scrn_passwd(int num, char *passwd) {
  long position;
  FILE *fp;
  position = (num * num * 4373 + num * 16927 + 39);
  while (position > 200000)
    position -= 200000;
  if ((fp = fopen("/usr/share/dict/words", "r")) == NULL)
    return 0;
  fseek(fp, position, ftell(fp));
  while (fgetc(fp) != '\n')
    ;
  if (fscanf(fp, "%s\n", passwd) == EOF && errno != 0) {
    fprintf(stderr, "fscanf error\n");
    exit(EXIT_FAILURE);
  }
  fclose(fp);
  return (1);
}


x86 assembly (clang, -O0):
<scrn_passwd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%eax
imul   -0x8(%rbp),%eax
imul   $0x1115,%eax,%eax
imul   $0x421f,-0x8(%rbp),%ecx
add    %ecx,%eax
add    $0x27,%eax
cltq
mov    %rax,-0x18(%rbp)
cmpq   $0x30d40,-0x18(%rbp)
jle    11cf <scrn_passwd+0x4f>
mov    -0x18(%rbp),%rax
sub    $0x30d40,%rax
mov    %rax,-0x18(%rbp)
jmp    11ae <scrn_passwd+0x2e>
lea    0xe2a(%rip),%rdi
lea    0xe39(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    11fc <scrn_passwd+0x7c>
movl   $0x0,-0x4(%rbp)
jmp    12a6 <scrn_passwd+0x126>
mov    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
call   1070 <ftell@plt>
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    %eax,%edx
call   1080 <fseek@plt>
mov    -0x20(%rbp),%rdi
call   1050 <fgetc@plt>
movsbl %al,%eax
cmp    $0xa,%eax
je     123e <scrn_passwd+0xbe>
jmp    1224 <scrn_passwd+0xa4>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xdcb(%rip),%rsi
call   1040 <fscanf@plt>
mov    0x2d8f(%rip),%rcx
cmp    (%rcx),%rax
jne    1296 <scrn_passwd+0x116>
mov    0x2d67(%rip),%rax
cmpq   $0x0,(%rax)
je     1296 <scrn_passwd+0x116>
mov    0x2d5e(%rip),%rax
mov    (%rax),%edi
lea    0xd99(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x2d39(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<scrn_passwd>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
imul   $0x1115,%edi,%eax
add    $0x421f,%eax
imul   %edi,%eax
add    $0x27,%eax
movslq %eax,%r12
cmp    $0x30d40,%r12
mov    $0x30d40,%r15d
cmovl  %r12,%r15
lea    0xe49(%rip),%rdi
lea    0xe58(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     1266 <scrn_passwd+0xe6>
mov    %rax,%rbx
neg    %r15
lea    (%r12,%r15,1),%rcx
add    $0x30d3f,%rcx
mov    %rcx,%rax
shr    $0x6,%rax
movabs $0x29f16b11c6d1e11,%rdx
16 9f 02
mul    %rdx
shr    $0x5,%rdx
imul   $0x30d40,%rdx,%rax
mov    %rcx,%r15
sub    %rax,%r15
sub    %rcx,%r15
add    %r12,%r15
mov    %rbx,%rdi
call   1070 <ftell@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %eax,%edx
call   1080 <fseek@plt>
nopl   (%rax)
mov    %rbx,%rdi
call   1050 <fgetc@plt>
cmp    $0xa,%al
jne    1220 <scrn_passwd+0xa0>
lea    0xde5(%rip),%rsi
mov    %rbx,%rdi
mov    %r14,%rdx
call   1040 <fscanf@plt>
mov    0x2da3(%rip),%rcx
cmp    (%rcx),%rax
jne    1257 <scrn_passwd+0xd7>
mov    0x2d7f(%rip),%rax
cmpq   $0x0,(%rax)
jne    1274 <scrn_passwd+0xf4>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    $0x1,%eax
jmp    1268 <scrn_passwd+0xe8>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    0x2d5d(%rip),%rax
mov    (%rax),%edi
lea    0xd98(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x2d38(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [22 x i8] c"/usr/share/dict/words\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [4 x i8] c"%s\0A\00"
@EOF = global i64 0
@errno = global i64 0
@stderr = global i32 0
@.str.3 = [14 x i8] c"fscanf error\0A\00"
@EXIT_FAILURE = global i32 0
define i32 @scrn_passwd(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i32*
store i32 %0, i32* %4
store i8* %1, i8** %5
%8 = load i32, i32* %4
%9 = load i32, i32* %4
%10 = mul nsw i32 %8, %9
%11 = mul nsw i32 %10, 4373
%12 = load i32, i32* %4
%13 = mul nsw i32 %12, 16927
%14 = add nsw i32 %11, %13
%15 = add nsw i32 %14, 39
%16 = sext i32 %15 to i64
store i64 %16, i64* %6
br label %17
17: ; preds = %20, %2
%18 = load i64, i64* %6
%19 = icmp sgt i64 %18, 200000
br i1 %19, label %20, label %23
20: ; preds = %17
%21 = load i64, i64* %6
%22 = sub nsw i64 %21, 200000
store i64 %22, i64* %6
br label %17
23: ; preds = %17
%24 = call i32* @fopen(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %24, i32** %7
%25 = icmp eq i32* %24, null
br i1 %25, label %26, label %27
26: ; preds = %23
store i32 0, i32* %3
br label %56
27: ; preds = %23
%28 = load i32*, i32** %7
%29 = load i64, i64* %6
%30 = load i32*, i32** %7
%31 = call i32 @ftell(i32* %30)
%32 = call i32 @fseek(i32* %28, i64 %29, i32 %31)
br label %33
33: ; preds = %38, %27
%34 = load i32*, i32** %7
%35 = call signext i8 @fgetc(i32* %34)
%36 = sext i8 %35 to i32
%37 = icmp ne i32 %36, 10
br i1 %37, label %38, label %39
38: ; preds = %33
br label %33
39: ; preds = %33
%40 = load i32*, i32** %7
%41 = load i8*, i8** %5
%42 = call i64 @fscanf(i32* %40, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %41)
%43 = load i64, i64* @EOF
%44 = icmp eq i64 %42, %43
br i1 %44, label %45, label %53
45: ; preds = %39
%46 = load i64, i64* @errno
%47 = icmp ne i64 %46, 0
br i1 %47, label %48, label %53
48: ; preds = %45
%49 = load i32, i32* @stderr
%50 = call i32 @fprintf(i32 %49, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
%51 = load i32, i32* @EXIT_FAILURE
%52 = call i32 @exit(i32 %51)
unreachable
53: ; preds = %45, %39
%54 = load i32*, i32** %7
%55 = call i32 @fclose(i32* %54)
store i32 1, i32* %3
br label %56
56: ; preds = %53, %26
%57 = load i32, i32* %3
ret i32 %57
}

LLVM IR (-O2):
@.str = [22 x i8] c"/usr/share/dict/words\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [4 x i8] c"%s\0A\00"
@EOF = global i64 0
@errno = global i64 0
@stderr = global i32 0
@.str.3 = [14 x i8] c"fscanf error\0A\00"
@EXIT_FAILURE = global i32 0
define i32 @scrn_passwd(i32 %0, i8* %1) {
%3 = mul i32 %0, 4373
%4 = add i32 %3, 16927
%5 = mul i32 %4, %0
%6 = add i32 %5, 39
%7 = sext i32 %6 to i64
%8 = add nsw i64 %7, 199999
%9 = call i64 @llvm.smin.i64(i64 %7, i64 200000)
%10 = sub nsw i64 %8, %9
%11 = tail call i32* @fopen(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%12 = icmp eq i32* %11, null
br i1 %12, label %36, label %13
13: ; preds = %2
%14 = urem i64 %10, 200000
%15 = sub nsw i64 %14, %10
%16 = add nsw i64 %15, %7
%17 = tail call i32 @ftell(i32* %11)
%18 = tail call i32 @fseek(i32* %11, i64 %16, i32 %17)
br label %19
19: ; preds = %19, %13
%20 = tail call signext i8 @fgetc(i32* %11)
%21 = icmp eq i8 %20, 10
br i1 %21, label %22, label %19
22: ; preds = %19
%23 = tail call i64 @fscanf(i32* %11, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %1)
%24 = load i64, i64* @EOF
%25 = icmp eq i64 %23, %24
%26 = load i64, i64* @errno
%27 = icmp ne i64 %26, 0
%28 = select i1 %25, i1 %27, i1 false
br i1 %28, label %29, label %34
29: ; preds = %22
%30 = load i32, i32* @stderr
%31 = tail call i32 @fprintf(i32 %30, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
%32 = load i32, i32* @EXIT_FAILURE
%33 = tail call i32 @exit(i32 %32)
unreachable
34: ; preds = %22
%35 = tail call i32 @fclose(i32* %11)
br label %36
36: ; preds = %2, %34
%37 = phi i32 [ 1, %34 ], [ 0, %2 ]
ret i32 %37
}