#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*/ SEEK_SET;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/);
size_t fread(char *, int, size_t, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
size_t ftell(int /*<<< orphan*/ *);
char *malloc(int);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ scanf(char *, char *);
int /*<<< orphan*/ stderr;
int strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
char *strstr(char *, char *);
int main(int argc, char *argv[]) {
  if (argc != 2) {
    fputs("Error - wrong number of argumets", stderr);
    exit(1);
  }
  char *name = argv[1];
  char *file;
  FILE *fp = fopen(name, "r");
  if (fp == NULL) {
    fputs("Can't open input file \n", stderr);
    exit(1);
  }
  fseek(fp, 0, SEEK_END);
  size_t sizeOfFile = ftell(fp), bytesRead;
  fseek(fp, 0, SEEK_SET);
  file = (char *)malloc(sizeOfFile);
  if (file == NULL) {
    fputs("Reading allocating memory\n", stderr);
    exit(1);
  }
  bytesRead = fread(file, sizeof(char), sizeOfFile, fp);
  if (bytesRead != sizeOfFile) {
    fputs("Reading error\n", stderr);
    exit(1);
  }
  char search_buffer[256], *search;
  puts("Enter the string you want to search for: ");
  scanf("%s", search_buffer);
  int search_len = strlen(search_buffer);
  search = malloc(search_len + 1);
  if (search == NULL) {
    fputs("Reading allocating memory\n", stderr);
    exit(1);
  }
  strncpy(search, search_buffer, search_len);
  char *search_ptr = strstr(file, search);
  if (search_ptr == NULL)
    puts("String not found");
  else
    puts("Found somewhere ");
  fclose(fp);
  free(file);
  puts("Done ;)\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x160,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     1222 <main+0x42>
mov    0x2dce(%rip),%rax
mov    (%rax),%esi
lea    0xded(%rip),%rdi
call   1090 <fputs@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xde8(%rip),%rsi
call   10e0 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    126c <main+0x8c>
mov    0x2d84(%rip),%rax
mov    (%rax),%esi
lea    0xdc6(%rip),%rdi
call   1090 <fputs@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>
mov    -0x28(%rbp),%rdi
mov    0x2d71(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   10c0 <fseek@plt>
mov    -0x28(%rbp),%rdi
call   10a0 <ftell@plt>
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rdi
mov    0x2d38(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   10c0 <fseek@plt>
mov    -0x30(%rbp),%rax
mov    %eax,%edi
call   10b0 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    12da <main+0xfa>
mov    0x2d16(%rip),%rax
mov    (%rax),%esi
lea    0xd70(%rip),%rdi
call   1090 <fputs@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>
mov    -0x20(%rbp),%rdi
mov    -0x30(%rbp),%rdx
mov    -0x28(%rbp),%rcx
mov    $0x1,%esi
call   1060 <fread@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
cmp    -0x30(%rbp),%rax
je     1321 <main+0x141>
mov    0x2ccf(%rip),%rax
mov    (%rax),%esi
lea    0xd44(%rip),%rdi
call   1090 <fputs@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>
lea    0xd3d(%rip),%rdi
call   1050 <puts@plt>
lea    -0x140(%rbp),%rsi
lea    0xd54(%rip),%rdi
call   10d0 <scanf@plt>
lea    -0x140(%rbp),%rdi
call   1080 <strlen@plt>
mov    %eax,-0x14c(%rbp)
mov    -0x14c(%rbp),%edi
add    $0x1,%edi
call   10b0 <malloc@plt>
mov    %rax,-0x148(%rbp)
cmpq   $0x0,-0x148(%rbp)
jne    1394 <main+0x1b4>
mov    0x2c5c(%rip),%rax
mov    (%rax),%esi
lea    0xcb6(%rip),%rdi
call   1090 <fputs@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>
mov    -0x148(%rbp),%rdi
lea    -0x140(%rbp),%rsi
mov    -0x14c(%rbp),%edx
call   1040 <strncpy@plt>
mov    -0x20(%rbp),%rdi
mov    -0x148(%rbp),%rsi
call   1100 <strstr@plt>
mov    %rax,-0x158(%rbp)
cmpq   $0x0,-0x158(%rbp)
jne    13e3 <main+0x203>
lea    0xcb9(%rip),%rdi
call   1050 <puts@plt>
jmp    13ef <main+0x20f>
lea    0xcb9(%rip),%rdi
call   1050 <puts@plt>
mov    -0x28(%rbp),%rdi
call   1070 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
lea    0xcac(%rip),%rdi
call   1050 <puts@plt>
xor    %eax,%eax
add    $0x160,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x108,%rsp
cmp    $0x2,%edi
jne    1320 <main+0x140>
mov    0x8(%rsi),%rdi
lea    0xe1f(%rip),%rsi
call   10e0 <fopen@plt>
test   %rax,%rax
je     1332 <main+0x152>
mov    %rax,%r15
mov    0x2dce(%rip),%rax
mov    (%rax),%edx
mov    %r15,%rdi
xor    %esi,%esi
call   10c0 <fseek@plt>
mov    %r15,%rdi
call   10a0 <ftell@plt>
mov    %rax,%rbx
mov    0x2d98(%rip),%rax
mov    (%rax),%edx
mov    %r15,%rdi
xor    %esi,%esi
call   10c0 <fseek@plt>
mov    %ebx,%edi
call   10b0 <malloc@plt>
test   %rax,%rax
je     130e <main+0x12e>
mov    %rax,%r14
mov    %rax,%rdi
mov    $0x1,%esi
mov    %rbx,%rdx
mov    %r15,%rcx
call   1060 <fread@plt>
cmp    %rbx,%rax
jne    1344 <main+0x164>
lea    0xdeb(%rip),%rdi
call   1050 <puts@plt>
lea    0xe09(%rip),%rdi
mov    %rsp,%rbx
mov    %rbx,%rsi
call   10d0 <scanf@plt>
mov    %rbx,%rdi
call   1080 <strlen@plt>
mov    %eax,%r12d
lea    0x1(%r12),%edi
call   10b0 <malloc@plt>
test   %rax,%rax
je     130e <main+0x12e>
mov    %rax,%rbx
mov    %rsp,%rsi
mov    %rax,%rdi
mov    %r12d,%edx
call   1040 <strncpy@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1100 <strstr@plt>
test   %rax,%rax
lea    0xdc1(%rip),%rax
lea    0xdcb(%rip),%rdi
cmove  %rax,%rdi
call   1050 <puts@plt>
mov    %r15,%rdi
call   1070 <fclose@plt>
mov    %r14,%rdi
call   1030 <free@plt>
lea    0xdbc(%rip),%rdi
call   1050 <puts@plt>
xor    %eax,%eax
add    $0x108,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    0x2cc3(%rip),%rax
mov    (%rax),%esi
lea    0xd1d(%rip),%rdi
jmp    1354 <main+0x174>
mov    0x2cb1(%rip),%rax
mov    (%rax),%esi
lea    0xcd0(%rip),%rdi
jmp    1354 <main+0x174>
mov    0x2c9f(%rip),%rax
mov    (%rax),%esi
lea    0xce1(%rip),%rdi
jmp    1354 <main+0x174>
mov    0x2c8d(%rip),%rax
mov    (%rax),%esi
lea    0xd02(%rip),%rdi
call   1090 <fputs@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>

LLVM IR (-O0):
@.str = [33 x i8] c"Error - wrong number of argumets\00"
@stderr = global i32 0
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [24 x i8] c"Can't open input file \0A\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@.str.3 = [27 x i8] c"Reading allocating memory\0A\00"
@.str.4 = [15 x i8] c"Reading error\0A\00"
@.str.5 = [42 x i8] c"Enter the string you want to search for: \00"
@.str.6 = [3 x i8] c"%s\00"
@.str.7 = [17 x i8] c"String not found\00"
@.str.8 = [17 x i8] c"Found somewhere \00"
@.str.9 = [9 x i8] c"Done ;)\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32*
%9 = alloca i64
%10 = alloca i64
%11 = alloca [256 x i8]
%12 = alloca i8*
%13 = alloca i32
%14 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%15 = load i32, i32* %4
%16 = icmp ne i32 %15, 2
br i1 %16, label %17, label %21
17: ; preds = %2
%18 = load i32, i32* @stderr
%19 = call i32 @fputs(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i32 %18)
%20 = call i32 @exit(i32 1)
unreachable
21: ; preds = %2
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 1
%24 = load i8*, i8** %23
store i8* %24, i8** %6
%25 = load i8*, i8** %6
%26 = call i32* @fopen(i8* %25, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %26, i32** %8
%27 = load i32*, i32** %8
%28 = icmp eq i32* %27, null
br i1 %28, label %29, label %33
29: ; preds = %21
%30 = load i32, i32* @stderr
%31 = call i32 @fputs(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i32 %30)
%32 = call i32 @exit(i32 1)
unreachable
33: ; preds = %21
%34 = load i32*, i32** %8
%35 = load i32, i32* @SEEK_END
%36 = call i32 @fseek(i32* %34, i32 0, i32 %35)
%37 = load i32*, i32** %8
%38 = call i64 @ftell(i32* %37)
store i64 %38, i64* %9
%39 = load i32*, i32** %8
%40 = load i32, i32* @SEEK_SET
%41 = call i32 @fseek(i32* %39, i32 0, i32 %40)
%42 = load i64, i64* %9
%43 = trunc i64 %42 to i32
%44 = call i8* @malloc(i32 %43)
store i8* %44, i8** %7
%45 = load i8*, i8** %7
%46 = icmp eq i8* %45, null
br i1 %46, label %47, label %51
47: ; preds = %33
%48 = load i32, i32* @stderr
%49 = call i32 @fputs(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0), i32 %48)
%50 = call i32 @exit(i32 1)
unreachable
51: ; preds = %33
%52 = load i8*, i8** %7
%53 = load i64, i64* %9
%54 = load i32*, i32** %8
%55 = call i64 @fread(i8* %52, i32 1, i64 %53, i32* %54)
store i64 %55, i64* %10
%56 = load i64, i64* %10
%57 = load i64, i64* %9
%58 = icmp ne i64 %56, %57
br i1 %58, label %59, label %63
59: ; preds = %51
%60 = load i32, i32* @stderr
%61 = call i32 @fputs(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0), i32 %60)
%62 = call i32 @exit(i32 1)
unreachable
63: ; preds = %51
%64 = call i32 @puts(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.5, i64 0, i64 0))
%65 = getelementptr inbounds [256 x i8], [256 x i8]* %11, i64 0, i64 0
%66 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i8* %65)
%67 = getelementptr inbounds [256 x i8], [256 x i8]* %11, i64 0, i64 0
%68 = call i32 @strlen(i8* %67)
store i32 %68, i32* %13
%69 = load i32, i32* %13
%70 = add nsw i32 %69, 1
%71 = call i8* @malloc(i32 %70)
store i8* %71, i8** %12
%72 = load i8*, i8** %12
%73 = icmp eq i8* %72, null
br i1 %73, label %74, label %78
74: ; preds = %63
%75 = load i32, i32* @stderr
%76 = call i32 @fputs(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0), i32 %75)
%77 = call i32 @exit(i32 1)
unreachable
78: ; preds = %63
%79 = load i8*, i8** %12
%80 = getelementptr inbounds [256 x i8], [256 x i8]* %11, i64 0, i64 0
%81 = load i32, i32* %13
%82 = call i32 @strncpy(i8* %79, i8* %80, i32 %81)
%83 = load i8*, i8** %7
%84 = load i8*, i8** %12
%85 = call i8* @strstr(i8* %83, i8* %84)
store i8* %85, i8** %14
%86 = load i8*, i8** %14
%87 = icmp eq i8* %86, null
br i1 %87, label %88, label %90
88: ; preds = %78
%89 = call i32 @puts(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.7, i64 0, i64 0))
br label %92
90: ; preds = %78
%91 = call i32 @puts(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.8, i64 0, i64 0))
br label %92
92: ; preds = %90, %88
%93 = load i32*, i32** %8
%94 = call i32 @fclose(i32* %93)
%95 = load i8*, i8** %7
%96 = call i32 @free(i8* %95)
%97 = call i32 @puts(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.9, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str = [33 x i8] c"Error - wrong number of argumets\00"
@stderr = global i32 0
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [24 x i8] c"Can't open input file \0A\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@.str.3 = [27 x i8] c"Reading allocating memory\0A\00"
@.str.4 = [15 x i8] c"Reading error\0A\00"
@.str.5 = [42 x i8] c"Enter the string you want to search for: \00"
@.str.6 = [3 x i8] c"%s\00"
@.str.7 = [17 x i8] c"String not found\00"
@.str.8 = [17 x i8] c"Found somewhere \00"
@.str.9 = [9 x i8] c"Done ;)\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [256 x i8]
%4 = icmp eq i32 %0, 2
br i1 %4, label %9, label %5
5: ; preds = %2
%6 = load i32, i32* @stderr
%7 = tail call i32 @fputs(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i32 %6)
%8 = tail call i32 @exit(i32 1)
unreachable
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = tail call i32* @fopen(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %18
14: ; preds = %9
%15 = load i32, i32* @stderr
%16 = tail call i32 @fputs(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i32 %15)
%17 = tail call i32 @exit(i32 1)
unreachable
18: ; preds = %9
%19 = load i32, i32* @SEEK_END
%20 = tail call i32 @fseek(i32* %12, i32 0, i32 %19)
%21 = tail call i64 @ftell(i32* %12)
%22 = load i32, i32* @SEEK_SET
%23 = tail call i32 @fseek(i32* %12, i32 0, i32 %22)
%24 = trunc i64 %21 to i32
%25 = tail call i8* @malloc(i32 %24)
%26 = icmp eq i8* %25, null
br i1 %26, label %27, label %31
27: ; preds = %18
%28 = load i32, i32* @stderr
%29 = tail call i32 @fputs(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0), i32 %28)
%30 = tail call i32 @exit(i32 1)
unreachable
31: ; preds = %18
%32 = tail call i64 @fread(i8* %25, i32 1, i64 %21, i32* %12)
%33 = icmp eq i64 %32, %21
br i1 %33, label %38, label %34
34: ; preds = %31
%35 = load i32, i32* @stderr
%36 = tail call i32 @fputs(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0), i32 %35)
%37 = tail call i32 @exit(i32 1)
unreachable
38: ; preds = %31
%39 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%40 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str.5, i64 0, i64 0))
%41 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i8* %39)
%42 = call i32 @strlen(i8* %39)
%43 = add nsw i32 %42, 1
%44 = call i8* @malloc(i32 %43)
%45 = icmp eq i8* %44, null
br i1 %45, label %46, label %50
46: ; preds = %38
%47 = load i32, i32* @stderr
%48 = call i32 @fputs(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0), i32 %47)
%49 = call i32 @exit(i32 1)
unreachable
50: ; preds = %38
%51 = call i32 @strncpy(i8* %44, i8* %39, i32 %42)
%52 = call i8* @strstr(i8* %25, i8* %44)
%53 = icmp eq i8* %52, null
%54 = select i1 %53, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.8, i64 0, i64 0)
%55 = call i32 @puts(i8* dereferenceable(1) %54)
%56 = call i32 @fclose(i32* %12)
%57 = call i32 @free(i8* %25)
%58 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.9, i64 0, i64 0))
ret i32 0
}