#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 EOF;
int alea(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
int strlen(char *);
int randMot(char *motPioche) {
  FILE *dico = NULL;
  int nbrMot = 0, motChoisi = 0, i = 0;
  int lettreLu = 0;
  dico = fopen("dico.paul", "r");
  if (dico == NULL) {
    printf("bug, pas de dico");
    return 0;
  }
  do {
    lettreLu = fgetc(dico);
    if (lettreLu == '\n') {
      nbrMot++;
    }
  } while (lettreLu != EOF);
  motChoisi = alea(nbrMot);
  rewind(dico);
  while (motChoisi > 0) {
    lettreLu = fgetc(dico);
    if (lettreLu == '\n') {
      motChoisi--;
    }
  }
  fgets(motPioche, 100, dico);
  motPioche[strlen(motPioche) - 1] = '\0';
  fclose(dico);
  return 1;
}


x86 assembly (clang, -O0):
<randMot>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
lea    0xe49(%rip),%rdi
lea    0xe4c(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11ea <randMot+0x6a>
lea    0xe33(%rip),%rdi
call   1060 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    12aa <randMot+0x12a>
jmp    11ef <randMot+0x6f>
mov    -0x18(%rbp),%rdi
call   1080 <fgetc@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0xa,-0x28(%rbp)
jne    120e <randMot+0x8e>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1213 <randMot+0x93>
mov    -0x28(%rbp),%eax
mov    0x2dcb(%rip),%rcx
cmp    (%rcx),%eax
jne    11ef <randMot+0x6f>
mov    -0x1c(%rbp),%edi
call   1030 <alea@plt>
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1070 <rewind@plt>
cmpl   $0x0,-0x20(%rbp)
jle    1267 <randMot+0xe7>
mov    -0x18(%rbp),%rdi
call   1080 <fgetc@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0xa,-0x28(%rbp)
jne    1262 <randMot+0xe2>
mov    -0x20(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x20(%rbp)
jmp    1239 <randMot+0xb9>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x64,%esi
call   1090 <fgets@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<randMot>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
lea    0xe6f(%rip),%rdi
lea    0xe72(%rip),%rsi
call   10a0 <fopen@plt>
test   %rax,%rax
je     1233 <randMot+0xb3>
mov    %rax,%rbx
xor    %ebp,%ebp
mov    0x2e36(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rbx,%rdi
call   1080 <fgetc@plt>
xor    %ecx,%ecx
cmp    $0xa,%eax
sete   %cl
add    %ecx,%ebp
cmp    (%r15),%eax
jne    11c0 <randMot+0x40>
mov    %ebp,%edi
call   1030 <alea@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1070 <rewind@plt>
test   %ebp,%ebp
jle    1204 <randMot+0x84>
nopl   0x0(%rax)
mov    %rbx,%rdi
call   1080 <fgetc@plt>
xor    %ecx,%ecx
cmp    $0xa,%eax
sete   %cl
sub    %ecx,%ebp
jne    11f0 <randMot+0x70>
mov    %r14,%rdi
mov    $0x64,%esi
mov    %rbx,%rdx
call   1090 <fgets@plt>
mov    %r14,%rdi
call   1050 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%r14,1)
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    $0x1,%eax
jmp    1241 <randMot+0xc1>
lea    0xdd2(%rip),%rdi
call   1060 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [10 x i8] c"dico.paul\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [17 x i8] c"bug, pas de dico\00"
@EOF = global i32 0
define i32 @randMot(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %3
store i32* null, i32** %4
store i32 0, i32* %5
store i32 0, i32* %6
store i32 0, i32* %7
store i32 0, i32* %8
%9 = call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %9, i32** %4
%10 = load i32*, i32** %4
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %14
12: ; preds = %1
%13 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %2
br label %57
14: ; preds = %1
br label %15
15: ; preds = %24, %14
%16 = load i32*, i32** %4
%17 = call i32 @fgetc(i32* %16)
store i32 %17, i32* %8
%18 = load i32, i32* %8
%19 = icmp eq i32 %18, 10
br i1 %19, label %20, label %23
20: ; preds = %15
%21 = load i32, i32* %5
%22 = add nsw i32 %21, 1
store i32 %22, i32* %5
br label %23
23: ; preds = %20, %15
br label %24
24: ; preds = %23
%25 = load i32, i32* %8
%26 = load i32, i32* @EOF
%27 = icmp ne i32 %25, %26
br i1 %27, label %15, label %28
28: ; preds = %24
%29 = load i32, i32* %5
%30 = call i32 @alea(i32 %29)
store i32 %30, i32* %6
%31 = load i32*, i32** %4
%32 = call i32 @rewind(i32* %31)
br label %33
33: ; preds = %44, %28
%34 = load i32, i32* %6
%35 = icmp sgt i32 %34, 0
br i1 %35, label %36, label %45
36: ; preds = %33
%37 = load i32*, i32** %4
%38 = call i32 @fgetc(i32* %37)
store i32 %38, i32* %8
%39 = load i32, i32* %8
%40 = icmp eq i32 %39, 10
br i1 %40, label %41, label %44
41: ; preds = %36
%42 = load i32, i32* %6
%43 = add nsw i32 %42, -1
store i32 %43, i32* %6
br label %44
44: ; preds = %41, %36
br label %33
45: ; preds = %33
%46 = load i8*, i8** %3
%47 = load i32*, i32** %4
%48 = call i32 @fgets(i8* %46, i32 100, i32* %47)
%49 = load i8*, i8** %3
%50 = load i8*, i8** %3
%51 = call i32 @strlen(i8* %50)
%52 = sub nsw i32 %51, 1
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds i8, i8* %49, i64 %53
store i8 0, i8* %54
%55 = load i32*, i32** %4
%56 = call i32 @fclose(i32* %55)
store i32 1, i32* %2
br label %57
57: ; preds = %45, %12
%58 = load i32, i32* %2
ret i32 %58
}

LLVM IR (-O2):
@.str = [10 x i8] c"dico.paul\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [17 x i8] c"bug, pas de dico\00"
@EOF = global i32 0
define i32 @randMot(i8* %0) {
%2 = tail call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%3 = icmp eq i32* %2, null
br i1 %3, label %4, label %6
4: ; preds = %1
%5 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
br label %32
6: ; preds = %1, %6
%7 = phi i32 [ %11, %6 ], [ 0, %1 ]
%8 = tail call i32 @fgetc(i32* %2)
%9 = icmp eq i32 %8, 10
%10 = zext i1 %9 to i32
%11 = add nuw nsw i32 %7, %10
%12 = load i32, i32* @EOF
%13 = icmp eq i32 %8, %12
br i1 %13, label %14, label %6
14: ; preds = %6
%15 = tail call i32 @alea(i32 %11)
%16 = tail call i32 @rewind(i32* %2)
%17 = icmp sgt i32 %15, 0
br i1 %17, label %18, label %25
18: ; preds = %14, %18
%19 = phi i32 [ %23, %18 ], [ %15, %14 ]
%20 = tail call i32 @fgetc(i32* %2)
%21 = icmp eq i32 %20, 10
%22 = sext i1 %21 to i32
%23 = add nsw i32 %19, %22
%24 = icmp eq i32 %23, 0
br i1 %24, label %25, label %18
25: ; preds = %18, %14
%26 = tail call i32 @fgets(i8* %0, i32 100, i32* %2)
%27 = tail call i32 @strlen(i8* %0)
%28 = add nsw i32 %27, -1
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* %0, i64 %29
store i8 0, i8* %30
%31 = tail call i32 @fclose(i32* %2)
br label %32
32: ; preds = %25, %4
%33 = phi i32 [ 0, %4 ], [ 1, %25 ]
ret i32 %33
}