#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);
  if (position < 0)
    position = -position;
  while (position > 200000)
    position -= 200000;
  if (position > 198500)
    position -= 198500;
  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   $0x0,-0x18(%rbp)
jge    11c3 <scrn_passwd+0x43>
xor    %eax,%eax
sub    -0x18(%rbp),%rax
mov    %rax,-0x18(%rbp)
jmp    11c8 <scrn_passwd+0x48>
cmpq   $0x30d40,-0x18(%rbp)
jle    11e9 <scrn_passwd+0x69>
mov    -0x18(%rbp),%rax
sub    $0x30d40,%rax
mov    %rax,-0x18(%rbp)
jmp    11c8 <scrn_passwd+0x48>
cmpq   $0x30764,-0x18(%rbp)
jle    1205 <scrn_passwd+0x85>
mov    -0x18(%rbp),%rax
sub    $0x30764,%rax
mov    %rax,-0x18(%rbp)
lea    0xdf4(%rip),%rdi
lea    0xe03(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    1232 <scrn_passwd+0xb2>
movl   $0x0,-0x4(%rbp)
jmp    12dc <scrn_passwd+0x15c>
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     1274 <scrn_passwd+0xf4>
jmp    125a <scrn_passwd+0xda>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xd95(%rip),%rsi
call   1040 <fscanf@plt>
mov    0x2d59(%rip),%rcx
cmp    (%rcx),%rax
jne    12cc <scrn_passwd+0x14c>
mov    0x2d31(%rip),%rax
cmpq   $0x0,(%rax)
je     12cc <scrn_passwd+0x14c>
mov    0x2d28(%rip),%rax
mov    (%rax),%edi
lea    0xd63(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x2d03(%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   %r13
push   %r12
push   %rbx
mov    %rsi,%r14
imul   $0x1115,%edi,%eax
add    $0x421f,%eax
imul   %edi,%eax
lea    0x27(%rax),%ecx
movslq %ecx,%rcx
mov    %rcx,%r12
neg    %r12
cmp    $0xffffffd9,%eax
cmovge %rcx,%r12
cmp    $0x30d40,%r12
mov    $0x30d40,%eax
cmovl  %r12,%rax
neg    %rax
lea    (%r12,%rax,1),%r13
add    $0x30d3f,%r13
mov    %r13,%rax
shr    $0x6,%rax
movabs $0x29f16b11c6d1e11,%rcx
16 9f 02
mul    %rcx
mov    %rdx,%r15
lea    0xe17(%rip),%rdi
lea    0xe26(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     1286 <scrn_passwd+0x106>
mov    %rax,%rbx
shr    $0x5,%r15
imul   $0x30d40,%r15,%rax
mov    %r13,%rcx
sub    %rax,%rcx
sub    %r13,%rcx
add    %r12,%rcx
lea    -0x30764(%rcx),%r15
cmp    $0x30765,%rcx
cmovl  %rcx,%r15
mov    %rbx,%rdi
call   1070 <ftell@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %eax,%edx
call   1080 <fseek@plt>
nop
mov    %rbx,%rdi
call   1050 <fgetc@plt>
cmp    $0xa,%al
jne    1240 <scrn_passwd+0xc0>
lea    0xdc5(%rip),%rsi
mov    %rbx,%rdi
mov    %r14,%rdx
call   1040 <fscanf@plt>
mov    0x2d83(%rip),%rcx
cmp    (%rcx),%rax
jne    1277 <scrn_passwd+0xf7>
mov    0x2d5f(%rip),%rax
cmpq   $0x0,(%rax)
jne    1292 <scrn_passwd+0x112>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    $0x1,%eax
jmp    1288 <scrn_passwd+0x108>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
mov    0x2d3f(%rip),%rax
mov    (%rax),%edi
lea    0xd7a(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x2d1a(%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
%17 = load i64, i64* %6
%18 = icmp slt i64 %17, 0
br i1 %18, label %19, label %22
19: ; preds = %2
%20 = load i64, i64* %6
%21 = sub nsw i64 0, %20
store i64 %21, i64* %6
br label %22
22: ; preds = %19, %2
br label %23
23: ; preds = %26, %22
%24 = load i64, i64* %6
%25 = icmp sgt i64 %24, 200000
br i1 %25, label %26, label %29
26: ; preds = %23
%27 = load i64, i64* %6
%28 = sub nsw i64 %27, 200000
store i64 %28, i64* %6
br label %23
29: ; preds = %23
%30 = load i64, i64* %6
%31 = icmp sgt i64 %30, 198500
br i1 %31, label %32, label %35
32: ; preds = %29
%33 = load i64, i64* %6
%34 = sub nsw i64 %33, 198500
store i64 %34, i64* %6
br label %35
35: ; preds = %32, %29
%36 = 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* %36, i32** %7
%37 = icmp eq i32* %36, null
br i1 %37, label %38, label %39
38: ; preds = %35
store i32 0, i32* %3
br label %68
39: ; preds = %35
%40 = load i32*, i32** %7
%41 = load i64, i64* %6
%42 = load i32*, i32** %7
%43 = call i32 @ftell(i32* %42)
%44 = call i32 @fseek(i32* %40, i64 %41, i32 %43)
br label %45
45: ; preds = %50, %39
%46 = load i32*, i32** %7
%47 = call signext i8 @fgetc(i32* %46)
%48 = sext i8 %47 to i32
%49 = icmp ne i32 %48, 10
br i1 %49, label %50, label %51
50: ; preds = %45
br label %45
51: ; preds = %45
%52 = load i32*, i32** %7
%53 = load i8*, i8** %5
%54 = call i64 @fscanf(i32* %52, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %53)
%55 = load i64, i64* @EOF
%56 = icmp eq i64 %54, %55
br i1 %56, label %57, label %65
57: ; preds = %51
%58 = load i64, i64* @errno
%59 = icmp ne i64 %58, 0
br i1 %59, label %60, label %65
60: ; preds = %57
%61 = load i32, i32* @stderr
%62 = call i32 @fprintf(i32 %61, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
%63 = load i32, i32* @EXIT_FAILURE
%64 = call i32 @exit(i32 %63)
unreachable
65: ; preds = %57, %51
%66 = load i32*, i32** %7
%67 = call i32 @fclose(i32* %66)
store i32 1, i32* %3
br label %68
68: ; preds = %65, %38
%69 = load i32, i32* %3
ret i32 %69
}

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 nsw i32 %5, 39
%7 = sext i32 %6 to i64
%8 = icmp slt i32 %5, -39
%9 = sub nsw i64 0, %7
%10 = select i1 %8, i64 %9, i64 %7
%11 = add nsw i64 %10, 199999
%12 = call i64 @llvm.smin.i64(i64 %10, i64 200000)
%13 = sub nsw i64 %11, %12
%14 = urem i64 %13, 200000
%15 = sub nsw i64 %14, %13
%16 = add nsw i64 %15, %10
%17 = 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))
%18 = icmp eq i32* %17, null
br i1 %18, label %42, label %19
19: ; preds = %2
%20 = icmp sgt i64 %16, 198500
%21 = add nsw i64 %16, -198500
%22 = select i1 %20, i64 %21, i64 %16
%23 = tail call i32 @ftell(i32* %17)
%24 = tail call i32 @fseek(i32* %17, i64 %22, i32 %23)
br label %25
25: ; preds = %25, %19
%26 = tail call signext i8 @fgetc(i32* %17)
%27 = icmp eq i8 %26, 10
br i1 %27, label %28, label %25
28: ; preds = %25
%29 = tail call i64 @fscanf(i32* %17, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %1)
%30 = load i64, i64* @EOF
%31 = icmp eq i64 %29, %30
%32 = load i64, i64* @errno
%33 = icmp ne i64 %32, 0
%34 = select i1 %31, i1 %33, i1 false
br i1 %34, label %35, label %40
35: ; preds = %28
%36 = load i32, i32* @stderr
%37 = tail call i32 @fprintf(i32 %36, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
%38 = load i32, i32* @EXIT_FAILURE
%39 = tail call i32 @exit(i32 %38)
unreachable
40: ; preds = %28
%41 = tail call i32 @fclose(i32* %17)
br label %42
42: ; preds = %2, %40
%43 = phi i32 [ 1, %40 ], [ 0, %2 ]
ret i32 %43
}