#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;
scalar_t__ fscanf(int /*<<< orphan*/ *, char *, char *);
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
int getAmount(FILE *fp) {
  FILE *input = fp;
  char buffer[32] = {0};
  int count = 0;
  rewind(input);
  while (fscanf(input, "%s", buffer) != EOF) {
    count++;
  }
  return count;
}


x86 assembly (clang, -O0):
<getAmount>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1040 <memset@plt>
movl   $0x0,-0x34(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <rewind@plt>
mov    -0x10(%rbp),%rdi
lea    -0x30(%rbp),%rdx
lea    0xe8d(%rip),%rsi
call   1050 <fscanf@plt>
mov    0x2e69(%rip),%rcx
cmp    (%rcx),%rax
je     1196 <getAmount+0x66>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1164 <getAmount+0x34>
mov    -0x34(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getAmount>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x20,%rsp
mov    %rdi,%rbx
xorps  %xmm0,%xmm0
movaps %xmm0,0x10(%rsp)
movaps %xmm0,(%rsp)
call   1030 <rewind@plt>
mov    $0xffffffff,%ebp
lea    0xeb4(%rip),%r14
mov    %rsp,%r15
mov    0x2e92(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   1040 <fscanf@plt>
add    $0x1,%ebp
cmp    (%r12),%rax
jne    1160 <getAmount+0x40>
mov    %ebp,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%s\00"
@EOF = global i64 0
define i32 @getAmount(i32* %0) {
%2 = alloca i32*
%3 = alloca i32*
%4 = alloca [32 x i8]
%5 = alloca i32
store i32* %0, i32** %2
%6 = load i32*, i32** %2
store i32* %6, i32** %3
%7 = bitcast [32 x i8]* %4 to i8*
store i32 0, i32* %5
%8 = load i32*, i32** %3
%9 = call i32 @rewind(i32* %8)
br label %10
10: ; preds = %16, %1
%11 = load i32*, i32** %3
%12 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 0
%13 = call i64 @fscanf(i32* %11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %12)
%14 = load i64, i64* @EOF
%15 = icmp ne i64 %13, %14
br i1 %15, label %16, label %19
16: ; preds = %10
%17 = load i32, i32* %5
%18 = add nsw i32 %17, 1
store i32 %18, i32* %5
br label %10
19: ; preds = %10
%20 = load i32, i32* %5
ret i32 %20
}

LLVM IR (-O2):
@.str = [3 x i8] c"%s\00"
@EOF = global i64 0
define i32 @getAmount(i32* nocapture %0) {
%2 = alloca [32 x i8]
%3 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 0
%4 = tail call i32 @rewind(i32* %0)
br label %5
5: ; preds = %5, %1
%6 = phi i32 [ 0, %1 ], [ %10, %5 ]
%7 = call i64 @fscanf(i32* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %3)
%8 = load i64, i64* @EOF
%9 = icmp eq i64 %7, %8
%10 = add nuw nsw i32 %6, 1
br i1 %9, label %11, label %5
11: ; preds = %5
ret i32 %6
}