#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*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ scanf(char *, char *);
int /*<<< orphan*/ *strstr(char *, char *);
int source() {
  int a, sum = 0;
  char filename[50], buffer[50];
  printf("Enter the name of the program file: ");
  scanf("%s", filename);
  FILE *fp = fopen(filename, "r");
  if (fp == NULL)
    exit(1);
  while (fgets(buffer, 50, fp) != NULL) {
    if (strstr(buffer, "if") != NULL)
      sum++;
    else if (strstr(buffer, "for") != NULL)
      sum++;
    else if (strstr(buffer, "while") != NULL)
      sum++;
  }
  fclose(fp);
  return (sum + 1);
}


x86 assembly (clang, -O0):
<source>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movl   $0x0,-0x8(%rbp)
lea    0xe77(%rip),%rdi
call   1040 <printf@plt>
lea    -0x40(%rbp),%rsi
lea    0xe8c(%rip),%rdi
call   1060 <scanf@plt>
lea    -0x40(%rbp),%rdi
lea    0xe84(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x88(%rbp)
cmpq   $0x0,-0x88(%rbp)
jne    11cd <source+0x5d>
mov    $0x1,%edi
call   1080 <exit@plt>
jmp    11d2 <source+0x62>
lea    -0x80(%rbp),%rdi
mov    -0x88(%rbp),%rdx
mov    $0x32,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     1273 <source+0x103>
lea    -0x80(%rbp),%rdi
lea    0xe2c(%rip),%rsi
call   1090 <strstr@plt>
cmp    $0x0,%rax
je     1219 <source+0xa9>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    126e <source+0xfe>
lea    -0x80(%rbp),%rdi
lea    0xe07(%rip),%rsi
call   1090 <strstr@plt>
cmp    $0x0,%rax
je     1241 <source+0xd1>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1269 <source+0xf9>
lea    -0x80(%rbp),%rdi
lea    0xde3(%rip),%rsi
call   1090 <strstr@plt>
cmp    $0x0,%rax
je     1264 <source+0xf4>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1269 <source+0xf9>
jmp    126e <source+0xfe>
jmp    11d2 <source+0x62>
mov    -0x88(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<source>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x78,%rsp
lea    0xe7b(%rip),%rdi
call   1040 <printf@plt>
lea    0xe94(%rip),%rdi
lea    0x40(%rsp),%rbx
mov    %rbx,%rsi
call   1060 <scanf@plt>
lea    0xe88(%rip),%rsi
mov    %rbx,%rdi
call   1070 <fopen@plt>
test   %rax,%rax
je     126c <source+0xfc>
mov    %rax,%r15
mov    %rsp,%rdi
mov    $0x32,%esi
mov    %rax,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     124e <source+0xde>
xor    %ebp,%ebp
lea    0xe4d(%rip),%r14
mov    %rsp,%rbx
lea    0xe46(%rip),%r12
jmp    1208 <source+0x98>
nopw   0x0(%rax,%rax,1)
add    %r13d,%ebp
mov    %rbx,%rdi
mov    $0x32,%esi
mov    %r15,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     1249 <source+0xd9>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1090 <strstr@plt>
mov    $0x1,%r13d
test   %rax,%rax
jne    11f0 <source+0x80>
mov    %rbx,%rdi
mov    %r12,%rsi
call   1090 <strstr@plt>
test   %rax,%rax
jne    11f0 <source+0x80>
mov    %rbx,%rdi
lea    0xdf7(%rip),%rsi
call   1090 <strstr@plt>
xor    %r13d,%r13d
test   %rax,%rax
setne  %r13b
jmp    11f0 <source+0x80>
add    $0x1,%ebp
jmp    1253 <source+0xe3>
mov    $0x1,%ebp
mov    %r15,%rdi
call   1030 <fclose@plt>
mov    %ebp,%eax
add    $0x78,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [37 x i8] c"Enter the name of the program file: \00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [3 x i8] c"if\00"
@.str.4 = [4 x i8] c"for\00"
@.str.5 = [6 x i8] c"while\00"
define i32 @source() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [50 x i8]
%4 = alloca [50 x i8]
%5 = alloca i32*
store i32 0, i32* %2
%6 = call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0))
%7 = getelementptr inbounds [50 x i8], [50 x i8]* %3, i64 0, i64 0
%8 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %7)
%9 = getelementptr inbounds [50 x i8], [50 x i8]* %3, i64 0, i64 0
%10 = call i32* @fopen(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %10, i32** %5
%11 = load i32*, i32** %5
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %15
13: ; preds = %0
%14 = call i32 @exit(i32 1)
unreachable
15: ; preds = %0
br label %16
16: ; preds = %44, %15
%17 = getelementptr inbounds [50 x i8], [50 x i8]* %4, i64 0, i64 0
%18 = load i32*, i32** %5
%19 = call i32* @fgets(i8* %17, i32 50, i32* %18)
%20 = icmp ne i32* %19, null
br i1 %20, label %21, label %45
21: ; preds = %16
%22 = getelementptr inbounds [50 x i8], [50 x i8]* %4, i64 0, i64 0
%23 = call i32* @strstr(i8* %22, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%24 = icmp ne i32* %23, null
br i1 %24, label %25, label %28
25: ; preds = %21
%26 = load i32, i32* %2
%27 = add nsw i32 %26, 1
store i32 %27, i32* %2
br label %44
28: ; preds = %21
%29 = getelementptr inbounds [50 x i8], [50 x i8]* %4, i64 0, i64 0
%30 = call i32* @strstr(i8* %29, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
%31 = icmp ne i32* %30, null
br i1 %31, label %32, label %35
32: ; preds = %28
%33 = load i32, i32* %2
%34 = add nsw i32 %33, 1
store i32 %34, i32* %2
br label %43
35: ; preds = %28
%36 = getelementptr inbounds [50 x i8], [50 x i8]* %4, i64 0, i64 0
%37 = call i32* @strstr(i8* %36, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
%38 = icmp ne i32* %37, null
br i1 %38, label %39, label %42
39: ; preds = %35
%40 = load i32, i32* %2
%41 = add nsw i32 %40, 1
store i32 %41, i32* %2
br label %42
42: ; preds = %39, %35
br label %43
43: ; preds = %42, %32
br label %44
44: ; preds = %43, %25
br label %16
45: ; preds = %16
%46 = load i32*, i32** %5
%47 = call i32 @fclose(i32* %46)
%48 = load i32, i32* %2
%49 = add nsw i32 %48, 1
ret i32 %49
}

LLVM IR (-O2):
@.str = [37 x i8] c"Enter the name of the program file: \00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [3 x i8] c"if\00"
@.str.4 = [4 x i8] c"for\00"
@.str.5 = [6 x i8] c"while\00"
define i32 @source() {
%1 = alloca [50 x i8]
%2 = alloca [50 x i8]
%3 = getelementptr inbounds [50 x i8], [50 x i8]* %1, i64 0, i64 0
%4 = getelementptr inbounds [50 x i8], [50 x i8]* %2, i64 0, i64 0
%5 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0))
%6 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %3)
%7 = call i32* @fopen(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%8 = icmp eq i32* %7, null
br i1 %8, label %12, label %9
9: ; preds = %0
%10 = call i32* @fgets(i8* %4, i32 50, i32* %7)
%11 = icmp eq i32* %10, null
br i1 %11, label %32, label %14
12: ; preds = %0
%13 = call i32 @exit(i32 1)
unreachable
14: ; preds = %9, %25
%15 = phi i32 [ %27, %25 ], [ 0, %9 ]
%16 = call i32* @strstr(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%17 = icmp eq i32* %16, null
br i1 %17, label %18, label %25
18: ; preds = %14
%19 = call i32* @strstr(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
%20 = icmp eq i32* %19, null
br i1 %20, label %21, label %25
21: ; preds = %18
%22 = call i32* @strstr(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
%23 = icmp ne i32* %22, null
%24 = zext i1 %23 to i32
br label %25
25: ; preds = %18, %14, %21
%26 = phi i32 [ %24, %21 ], [ 1, %14 ], [ 1, %18 ]
%27 = add nuw nsw i32 %15, %26
%28 = call i32* @fgets(i8* %4, i32 50, i32* %7)
%29 = icmp eq i32* %28, null
br i1 %29, label %30, label %14
30: ; preds = %25
%31 = add nuw i32 %27, 1
br label %32
32: ; preds = %30, %9
%33 = phi i32 [ 1, %9 ], [ %31, %30 ]
%34 = call i32 @fclose(i32* %7)
ret i32 %33
}