#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*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
int /*<<< orphan*/ sscanf(char *, char *, int *, char *);
int getNbWords(FILE *descriptorFile, int nbLine) {
  char buffer[100] = {0};
  char key[100] = {0};
  int value;
  int nbWords = 0;
  int i;
  for (i = 0; i < nbLine; i++) {
    fgets(buffer, 100, descriptorFile);
    sscanf(buffer, "%d\t%s", &value, key);
    nbWords += value;
  }
  rewind(descriptorFile);
  fgets(buffer, 100, descriptorFile);
  return (nbWords);
}


x86 assembly (clang, -O0):
<getNbWords>:
push   %rbp
mov    %rsp,%rbp
sub    $0xf0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
lea    -0x70(%rbp),%rdi
xor    %esi,%esi
mov    $0x64,%edx
call   1040 <memset@plt>
lea    -0xe0(%rbp),%rdi
xor    %esi,%esi
mov    $0x64,%edx
call   1040 <memset@plt>
movl   $0x0,-0xe8(%rbp)
movl   $0x0,-0xec(%rbp)
mov    -0xec(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11ee <getNbWords+0xae>
lea    -0x70(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    $0x64,%esi
call   1050 <fgets@plt>
lea    -0x70(%rbp),%rdi
lea    -0xe0(%rbp),%rcx
lea    0xe44(%rip),%rsi
lea    -0xe4(%rbp),%rdx
call   1060 <sscanf@plt>
mov    -0xe4(%rbp),%eax
add    -0xe8(%rbp),%eax
mov    %eax,-0xe8(%rbp)
mov    -0xec(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xec(%rbp)
jmp    1189 <getNbWords+0x49>
mov    -0x8(%rbp),%rdi
call   1030 <rewind@plt>
lea    -0x70(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    $0x64,%esi
call   1050 <fgets@plt>
mov    -0xe8(%rbp),%eax
add    $0xf0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getNbWords>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xe8,%rsp
mov    %rdi,%r14
xorps  %xmm0,%xmm0
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movl   $0x0,0x70(%rsp)
movaps %xmm0,0xd0(%rsp)
movaps %xmm0,0xc0(%rsp)
movaps %xmm0,0xb0(%rsp)
movaps %xmm0,0xa0(%rsp)
movaps %xmm0,0x90(%rsp)
movaps %xmm0,0x80(%rsp)
movl   $0x0,0xe0(%rsp)
test   %esi,%esi
jle    1200 <getNbWords+0xd0>
mov    %esi,%ebp
xor    %ebx,%ebx
lea    0x10(%rsp),%r15
lea    0xc(%rsp),%r13
lea    0x80(%rsp),%r12
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r15,%rdi
mov    $0x64,%esi
mov    %r14,%rdx
call   1040 <fgets@plt>
mov    %r15,%rdi
lea    0xe16(%rip),%rsi
mov    %r13,%rdx
mov    %r12,%rcx
call   1050 <sscanf@plt>
add    0xc(%rsp),%ebx
add    $0xffffffff,%ebp
jne    11d0 <getNbWords+0xa0>
jmp    1202 <getNbWords+0xd2>
xor    %ebx,%ebx
mov    %r14,%rdi
call   1030 <rewind@plt>
lea    0x10(%rsp),%rdi
mov    $0x64,%esi
mov    %r14,%rdx
call   1040 <fgets@plt>
mov    %ebx,%eax
add    $0xe8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [6 x i8] c"%d\09%s\00"
define i32 @getNbWords(i32* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32
%5 = alloca [100 x i8]
%6 = alloca [100 x i8]
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32* %0, i32** %3
store i32 %1, i32* %4
%10 = bitcast [100 x i8]* %5 to i8*
%11 = bitcast [100 x i8]* %6 to i8*
store i32 0, i32* %8
store i32 0, i32* %9
br label %12
12: ; preds = %26, %2
%13 = load i32, i32* %9
%14 = load i32, i32* %4
%15 = icmp slt i32 %13, %14
br i1 %15, label %16, label %29
16: ; preds = %12
%17 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%18 = load i32*, i32** %3
%19 = call i32 @fgets(i8* %17, i32 100, i32* %18)
%20 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%21 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%22 = call i32 @sscanf(i8* %20, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32* %7, i8* %21)
%23 = load i32, i32* %7
%24 = load i32, i32* %8
%25 = add nsw i32 %24, %23
store i32 %25, i32* %8
br label %26
26: ; preds = %16
%27 = load i32, i32* %9
%28 = add nsw i32 %27, 1
store i32 %28, i32* %9
br label %12
29: ; preds = %12
%30 = load i32*, i32** %3
%31 = call i32 @rewind(i32* %30)
%32 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%33 = load i32*, i32** %3
%34 = call i32 @fgets(i8* %32, i32 100, i32* %33)
%35 = load i32, i32* %8
ret i32 %35
}

LLVM IR (-O2):
@.str = [6 x i8] c"%d\09%s\00"
define i32 @getNbWords(i32* nocapture %0, i32 %1) {
%3 = alloca [100 x i8]
%4 = alloca [100 x i8]
%5 = alloca i32
%6 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%7 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%8 = bitcast i32* %5 to i8*
%9 = icmp sgt i32 %1, 0
br i1 %9, label %10, label %19
10: ; preds = %2, %10
%11 = phi i32 [ %17, %10 ], [ 0, %2 ]
%12 = phi i32 [ %16, %10 ], [ 0, %2 ]
%13 = call i32 @fgets(i8* %6, i32 100, i32* %0)
%14 = call i32 @sscanf(i8* %6, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32* %5, i8* %7)
%15 = load i32, i32* %5
%16 = add nsw i32 %15, %12
%17 = add nuw nsw i32 %11, 1
%18 = icmp eq i32 %17, %1
br i1 %18, label %19, label %10
19: ; preds = %10, %2
%20 = phi i32 [ 0, %2 ], [ %16, %10 ]
%21 = call i32 @rewind(i32* %0)
%22 = call i32 @fgets(i8* %6, i32 100, i32* %0)
ret i32 %20
}