#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *const, char *);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, char *const);
char *malloc(int);
char *searchWord(const char *const filename, const unsigned int n) {
  FILE *f = fopen(filename, "r");
  if (f == NULL)
    return NULL;
  char *const re = malloc(30 * sizeof(char));
  for (unsigned int i = 0; i < n; ++i)
    fscanf(f, "%s", re);
  fclose(f);
  return re;
}


x86 assembly (clang, -O0):
<searchWord>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xea6(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    117b <searchWord+0x3b>
movq   $0x0,-0x8(%rbp)
jmp    11cf <searchWord+0x8f>
mov    $0x1e,%edi
call   1050 <malloc@plt>
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jae    11be <searchWord+0x7e>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rdx
lea    0xe57(%rip),%rsi
call   1040 <fscanf@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1190 <searchWord+0x50>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<searchWord>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %esi,%ebx
lea    0xeaf(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     119d <searchWord+0x5d>
mov    %rax,%r15
mov    $0x1e,%edi
call   1050 <malloc@plt>
mov    %rax,%r14
test   %ebx,%ebx
je     1193 <searchWord+0x53>
lea    0xe8c(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    %r12,%rsi
mov    %r14,%rdx
call   1040 <fscanf@plt>
add    $0xffffffff,%ebx
jne    1180 <searchWord+0x40>
mov    %r15,%rdi
call   1030 <fclose@plt>
jmp    11a0 <searchWord+0x60>
xor    %r14d,%r14d
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [3 x i8] c"%s\00"
define i8* @searchWord(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i8*
%8 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
%9 = load i8*, i8** %4
%10 = call i32* @fopen(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %10, i32** %6
%11 = load i32*, i32** %6
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %14
13: ; preds = %2
store i8* null, i8** %3
br label %31
14: ; preds = %2
%15 = call i8* @malloc(i32 30)
store i8* %15, i8** %7
store i32 0, i32* %8
br label %16
16: ; preds = %24, %14
%17 = load i32, i32* %8
%18 = load i32, i32* %5
%19 = icmp ult i32 %17, %18
br i1 %19, label %20, label %27
20: ; preds = %16
%21 = load i32*, i32** %6
%22 = load i8*, i8** %7
%23 = call i32 @fscanf(i32* %21, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %22)
br label %24
24: ; preds = %20
%25 = load i32, i32* %8
%26 = add i32 %25, 1
store i32 %26, i32* %8
br label %16
27: ; preds = %16
%28 = load i32*, i32** %6
%29 = call i32 @fclose(i32* %28)
%30 = load i8*, i8** %7
store i8* %30, i8** %3
br label %31
31: ; preds = %27, %13
%32 = load i8*, i8** %3
ret i8* %32
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [3 x i8] c"%s\00"
define i8* @searchWord(i8* nocapture %0, i32 %1) {
%3 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %15, label %5
5: ; preds = %2
%6 = tail call dereferenceable_or_null(30) i8* @malloc(i32 30)
%7 = icmp eq i32 %1, 0
br i1 %7, label %8, label %10
8: ; preds = %10, %5
%9 = tail call i32 @fclose(i32* %3)
br label %15
10: ; preds = %5, %10
%11 = phi i32 [ %13, %10 ], [ 0, %5 ]
%12 = tail call i32 @fscanf(i32* %3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %6)
%13 = add nuw i32 %11, 1
%14 = icmp eq i32 %13, %1
br i1 %14, label %8, label %10
15: ; preds = %2, %8
%16 = phi i8* [ %6, %8 ], [ null, %2 ]
ret i8* %16
}