#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*/ SEEK_END;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
scalar_t__ fseek(int /*<<< orphan*/ *, long, int /*<<< orphan*/);
int ftell(int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, char *);
int lenFile(char *nom) {
  FILE *fp;
  int file_size = 0;
  if ((fp = fopen(nom, "rb")) == NULL) {
    printf("Thread-init: Fichier AD %s introuvable, taille à 0.\n", nom);
    return (file_size);
  }
  if (fseek(fp, (long)(0), SEEK_END) != 0) {
    fclose(fp);
    return (file_size);
  }
  file_size = (ftell(fp));
  fclose(fp);
  return (file_size);
}


x86 assembly (clang, -O0):
<lenFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe92(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    119c <lenFile+0x4c>
mov    -0x10(%rbp),%rsi
lea    0xe77(%rip),%rdi
call   1040 <printf@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11eb <lenFile+0x9b>
mov    -0x18(%rbp),%rdi
mov    0x2e41(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
call   1060 <fseek@plt>
cmp    $0x0,%rax
je     11d0 <lenFile+0x80>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11eb <lenFile+0x9b>
mov    -0x18(%rbp),%rdi
call   1050 <ftell@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lenFile>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%r14
lea    0xea2(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     118d <lenFile+0x3d>
mov    %rax,%rbx
mov    0x2e76(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1060 <fseek@plt>
test   %rax,%rax
je     11a0 <lenFile+0x50>
mov    %rbx,%rdi
call   1030 <fclose@plt>
jmp    119c <lenFile+0x4c>
lea    0xe6f(%rip),%rdi
mov    %r14,%rsi
call   1040 <printf@plt>
xor    %eax,%eax
jmp    11b4 <lenFile+0x64>
mov    %rbx,%rdi
call   1050 <ftell@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
@.str.1 = [54 x i8] c"Thread-init: Fichier AD %s introuvable, taille \C3\A0 0.\0A\00"
@SEEK_END = global i32 0
define i32 @lenFile(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i32
store i8* %0, i8** %3
store i32 0, i32* %5
%6 = load i8*, i8** %3
%7 = call i32* @fopen(i8* %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %7, i32** %4
%8 = icmp eq i32* %7, null
br i1 %8, label %9, label %13
9: ; preds = %1
%10 = load i8*, i8** %3
%11 = call i32 @printf(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.1, i64 0, i64 0), i8* %10)
%12 = load i32, i32* %5
store i32 %12, i32* %2
br label %28
13: ; preds = %1
%14 = load i32*, i32** %4
%15 = load i32, i32* @SEEK_END
%16 = call i64 @fseek(i32* %14, i64 0, i32 %15)
%17 = icmp ne i64 %16, 0
br i1 %17, label %18, label %22
18: ; preds = %13
%19 = load i32*, i32** %4
%20 = call i32 @fclose(i32* %19)
%21 = load i32, i32* %5
store i32 %21, i32* %2
br label %28
22: ; preds = %13
%23 = load i32*, i32** %4
%24 = call i32 @ftell(i32* %23)
store i32 %24, i32* %5
%25 = load i32*, i32** %4
%26 = call i32 @fclose(i32* %25)
%27 = load i32, i32* %5
store i32 %27, i32* %2
br label %28
28: ; preds = %22, %18, %9
%29 = load i32, i32* %2
ret i32 %29
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@.str.1 = [54 x i8] c"Thread-init: Fichier AD %s introuvable, taille \C3\A0 0.\0A\00"
@SEEK_END = global i32 0
define i32 @lenFile(i8* %0) {
%2 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, 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* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %15
6: ; preds = %1
%7 = load i32, i32* @SEEK_END
%8 = tail call i64 @fseek(i32* %2, i64 0, i32 %7)
%9 = icmp eq i64 %8, 0
br i1 %9, label %12, label %10
10: ; preds = %6
%11 = tail call i32 @fclose(i32* %2)
br label %15
12: ; preds = %6
%13 = tail call i32 @ftell(i32* %2)
%14 = tail call i32 @fclose(i32* %2)
br label %15
15: ; preds = %12, %10, %4
%16 = phi i32 [ 0, %4 ], [ 0, %10 ], [ %13, %12 ]
ret i32 %16
}