#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*/ time_t;
struct tm {
  int dummy;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ EXIT_SUCCESS;
char *asctime(struct tm *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, int /*<<< orphan*/);
struct tm *localtime(int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stdin;
char *strchr(char *, char);
int strlen(char *);
char *strstr(char *, char *);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int main(int argc, char *argv[]) {
  char *cArray[120] = {"example", "dinosaurs"};
  char cInput[120] = {0};
  int y = 0;
  FILE *pWrite;
  printf("Type your message:\n");
  fgets(cInput, 120, stdin);
  cInput[strlen(cInput) - 1] = 0;
  printf("\nInitialised string array:\n");
  while (cArray[y]) {
    char *ptr = cInput;
    while ((ptr = strstr(ptr, cArray[y])) != NULL) {
      char *ep = strchr(ptr, ' ');
      if (ep)
        *ep = 0;
      printf("%s\n", ptr);
      pWrite = fopen("test.txt", "a");
      if (pWrite != NULL) {
        fprintf(pWrite, "%s\n", ptr++);
        fclose(pWrite);
      } else {
        goto ErrorHandler;
      }
      if (ep)
        *ep = ' ';
    }
    y++;
  }
  time_t rawtime;
  struct tm *timeinfo;
  time(&rawtime);
  timeinfo = localtime(&rawtime);
  printf("Timestamp: %s", asctime(timeinfo));
  exit(EXIT_SUCCESS);
ErrorHandler:
  perror("The following error occurred");
  exit(EXIT_FAILURE);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x480,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x3d0(%rbp),%rdi
xor    %esi,%esi
mov    $0x3c0,%edx
call   1090 <memset@plt>
lea    0xded(%rip),%rax
mov    %rax,-0x3d0(%rbp)
lea    0xde7(%rip),%rax
mov    %rax,-0x3c8(%rbp)
lea    -0x450(%rbp),%rdi
xor    %esi,%esi
mov    $0x78,%edx
call   1090 <memset@plt>
movl   $0x0,-0x454(%rbp)
lea    0xdc6(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
lea    -0x450(%rbp),%rdi
mov    0x2d87(%rip),%rax
mov    (%rax),%edx
mov    $0x78,%esi
call   10a0 <fgets@plt>
lea    -0x450(%rbp),%rdi
call   1050 <strlen@plt>
sub    $0x1,%eax
cltq
movb   $0x0,-0x450(%rbp,%rax,1)
lea    0xd99(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
movslq -0x454(%rbp),%rax
cmpq   $0x0,-0x3d0(%rbp,%rax,8)
je     13c2 <main+0x1e2>
lea    -0x450(%rbp),%rax
mov    %rax,-0x468(%rbp)
mov    -0x468(%rbp),%rdi
movslq -0x454(%rbp),%rax
mov    -0x3d0(%rbp,%rax,8),%rsi
ff
call   1100 <strstr@plt>
mov    %rax,-0x468(%rbp)
cmp    $0x0,%rax
je     13ae <main+0x1ce>
mov    -0x468(%rbp),%rdi
mov    $0x20,%esi
call   1070 <strchr@plt>
mov    %rax,-0x470(%rbp)
cmpq   $0x0,-0x470(%rbp)
je     1314 <main+0x134>
mov    -0x470(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x468(%rbp),%rsi
lea    0xd20(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
lea    0xd16(%rip),%rdi
lea    0xd18(%rip),%rsi
call   10d0 <fopen@plt>
mov    %rax,-0x460(%rbp)
cmpq   $0x0,-0x460(%rbp)
je     138c <main+0x1ac>
mov    -0x460(%rbp),%rdi
mov    -0x468(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x468(%rbp)
mov    %eax,%edx
lea    0xccc(%rip),%rsi
call   10b0 <fprintf@plt>
mov    -0x460(%rbp),%rdi
call   1040 <fclose@plt>
jmp    1391 <main+0x1b1>
jmp    140c <main+0x22c>
cmpq   $0x0,-0x470(%rbp)
je     13a9 <main+0x1c9>
mov    -0x470(%rbp),%rax
movb   $0x20,(%rax)
jmp    12b8 <main+0xd8>
mov    -0x454(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x454(%rbp)
jmp    1294 <main+0xb4>
lea    -0x474(%rbp),%rdi
call   10c0 <time@plt>
lea    -0x474(%rbp),%rdi
call   1030 <localtime@plt>
mov    %rax,-0x480(%rbp)
mov    -0x480(%rbp),%rdi
call   1060 <asctime@plt>
mov    %rax,%rsi
lea    0xc5a(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    0x2bcb(%rip),%rax
mov    (%rax),%edi
call   10f0 <exit@plt>
lea    0xc4c(%rip),%rdi
call   10e0 <perror@plt>
mov    0x2bb9(%rip),%rax
mov    (%rax),%edi
call   10f0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x458,%rsp
lea    0xa0(%rsp),%rdi
xor    %ebp,%ebp
mov    $0x3b0,%edx
xor    %esi,%esi
call   10a0 <memset@plt>
lea    0xde2(%rip),%rbx
mov    %rbx,0x90(%rsp)
lea    0xddb(%rip),%rax
mov    %rax,0x98(%rsp)
xorps  %xmm0,%xmm0
movaps %xmm0,0x70(%rsp)
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movq   $0x0,0x80(%rsp)
lea    0xdde(%rip),%rdi
call   1040 <puts@plt>
mov    0x2d6e(%rip),%rax
mov    (%rax),%edx
lea    0x10(%rsp),%r14
mov    %r14,%rdi
mov    $0x78,%esi
call   10b0 <fgets@plt>
mov    %r14,%rdi
call   1060 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%r14,1)
lea    0xdba(%rip),%rdi
call   1040 <puts@plt>
lea    0xd61(%rip),%r13
jmp    12d9 <main+0xe9>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    (%rsp),%rbp
mov    0x98(%rsp,%rbp,8),%rbx
add    $0x1,%rbp
test   %rbx,%rbx
je     138d <main+0x19d>
mov    %rbp,(%rsp)
lea    0x10(%rsp),%rdi
mov    %rbx,%rsi
call   1110 <strstr@plt>
test   %rax,%rax
je     12c0 <main+0xd0>
mov    %rax,%rbp
jmp    1313 <main+0x123>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r15,%rdi
mov    %rbx,%rsi
call   1110 <strstr@plt>
mov    %rax,%rbp
test   %rax,%rax
je     12c0 <main+0xd0>
mov    %rbp,%rdi
mov    $0x20,%esi
call   1080 <strchr@plt>
mov    %rax,%r14
test   %rax,%rax
je     132c <main+0x13c>
movb   $0x0,(%r14)
mov    %rbp,%rdi
call   1040 <puts@plt>
lea    0xcdb(%rip),%rdi
lea    0xcdd(%rip),%rsi
call   10e0 <fopen@plt>
test   %rax,%rax
je     1373 <main+0x183>
mov    %rax,%r12
lea    0x1(%rbp),%r15
mov    %rax,%rdi
mov    %r13,%rsi
mov    %ebp,%edx
call   10c0 <fprintf@plt>
mov    %r12,%rdi
call   1050 <fclose@plt>
test   %r14,%r14
je     1300 <main+0x110>
movb   $0x20,(%r14)
jmp    1300 <main+0x110>
lea    0xcb5(%rip),%rdi
call   10f0 <perror@plt>
mov    0x2c52(%rip),%rax
mov    (%rax),%edi
call   1100 <exit@plt>
lea    0xc(%rsp),%rbx
mov    %rbx,%rdi
call   10d0 <time@plt>
mov    %rbx,%rdi
call   1030 <localtime@plt>
mov    %rax,%rdi
call   1070 <asctime@plt>
lea    0xc70(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1090 <printf@plt>
mov    0x2c0e(%rip),%rax
mov    (%rax),%edi
call   1100 <exit@plt>

LLVM IR (-O0):
%struct.tm = type { i32 }
@.str = [8 x i8] c"example\00"
@.str.1 = [10 x i8] c"dinosaurs\00"
@.str.2 = [20 x i8] c"Type your message:\0A\00"
@stdin = global i32 0
@.str.3 = [28 x i8] c"\0AInitialised string array:\0A\00"
@.str.4 = [4 x i8] c"%s\0A\00"
@.str.5 = [9 x i8] c"test.txt\00"
@.str.6 = [2 x i8] c"a\00"
@.str.7 = [14 x i8] c"Timestamp: %s\00"
@EXIT_SUCCESS = global i32 0
@.str.8 = [29 x i8] c"The following error occurred\00"
@EXIT_FAILURE = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [120 x i8*]
%7 = alloca [120 x i8]
%8 = alloca i32
%9 = alloca i32*
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i32
%13 = alloca %struct.tm*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%14 = bitcast [120 x i8*]* %6 to i8*
%15 = bitcast i8* %14 to <{ i8*, i8*, [118 x i8*] }>*
%16 = getelementptr inbounds <{ i8*, i8*, [118 x i8*] }>, <{ i8*, i8*, [118 x i8*] }>* %15, i32 0, i32 0
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i32 0, i32 0), i8** %16
%17 = getelementptr inbounds <{ i8*, i8*, [118 x i8*] }>, <{ i8*, i8*, [118 x i8*] }>* %15, i32 0, i32 1
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i32 0, i32 0), i8** %17
%18 = bitcast [120 x i8]* %7 to i8*
store i32 0, i32* %8
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
%20 = getelementptr inbounds [120 x i8], [120 x i8]* %7, i64 0, i64 0
%21 = load i32, i32* @stdin
%22 = call i32 @fgets(i8* %20, i32 120, i32 %21)
%23 = getelementptr inbounds [120 x i8], [120 x i8]* %7, i64 0, i64 0
%24 = call i32 @strlen(i8* %23)
%25 = sub nsw i32 %24, 1
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds [120 x i8], [120 x i8]* %7, i64 0, i64 %26
store i8 0, i8* %27
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0))
br label %29
29: ; preds = %73, %2
%30 = load i32, i32* %8
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds [120 x i8*], [120 x i8*]* %6, i64 0, i64 %31
%33 = load i8*, i8** %32
%34 = icmp ne i8* %33, null
br i1 %34, label %35, label %76
35: ; preds = %29
%36 = getelementptr inbounds [120 x i8], [120 x i8]* %7, i64 0, i64 0
store i8* %36, i8** %10
br label %37
37: ; preds = %72, %35
%38 = load i8*, i8** %10
%39 = load i32, i32* %8
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds [120 x i8*], [120 x i8*]* %6, i64 0, i64 %40
%42 = load i8*, i8** %41
%43 = call i8* @strstr(i8* %38, i8* %42)
store i8* %43, i8** %10
%44 = icmp ne i8* %43, null
br i1 %44, label %45, label %73
45: ; preds = %37
%46 = load i8*, i8** %10
%47 = call i8* @strchr(i8* %46, i8 signext 32)
store i8* %47, i8** %11
%48 = load i8*, i8** %11
%49 = icmp ne i8* %48, null
br i1 %49, label %50, label %52
50: ; preds = %45
%51 = load i8*, i8** %11
store i8 0, i8* %51
br label %52
52: ; preds = %50, %45
%53 = load i8*, i8** %10
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %53)
%55 = call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
store i32* %55, i32** %9
%56 = load i32*, i32** %9
%57 = icmp ne i32* %56, null
br i1 %57, label %58, label %66
58: ; preds = %52
%59 = load i32*, i32** %9
%60 = load i8*, i8** %10
%61 = getelementptr inbounds i8, i8* %60, i32 1
store i8* %61, i8** %10
%62 = ptrtoint i8* %60 to i32
%63 = call i32 @fprintf(i32* %59, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %62)
%64 = load i32*, i32** %9
%65 = call i32 @fclose(i32* %64)
br label %67
66: ; preds = %52
br label %84
67: ; preds = %58
%68 = load i8*, i8** %11
%69 = icmp ne i8* %68, null
br i1 %69, label %70, label %72
70: ; preds = %67
%71 = load i8*, i8** %11
store i8 32, i8* %71
br label %72
72: ; preds = %70, %67
br label %37
73: ; preds = %37
%74 = load i32, i32* %8
%75 = add nsw i32 %74, 1
store i32 %75, i32* %8
br label %29
76: ; preds = %29
%77 = call i32 @time(i32* %12)
%78 = call %struct.tm* @localtime(i32* %12)
store %struct.tm* %78, %struct.tm** %13
%79 = load %struct.tm*, %struct.tm** %13
%80 = call i8* @asctime(%struct.tm* %79)
%81 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.7, i64 0, i64 0), i8* %80)
%82 = load i32, i32* @EXIT_SUCCESS
%83 = call i32 @exit(i32 %82)
unreachable
84: ; preds = %66
%85 = call i32 @perror(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.8, i64 0, i64 0))
%86 = load i32, i32* @EXIT_FAILURE
%87 = call i32 @exit(i32 %86)
unreachable
}

LLVM IR (-O2):
%struct.tm = type { i32 }
@.str = [8 x i8] c"example\00"
@.str.1 = [10 x i8] c"dinosaurs\00"
@stdin = global i32 0
@.str.4 = [4 x i8] c"%s\0A\00"
@.str.5 = [9 x i8] c"test.txt\00"
@.str.6 = [2 x i8] c"a\00"
@.str.7 = [14 x i8] c"Timestamp: %s\00"
@EXIT_SUCCESS = global i32 0
@.str.8 = [29 x i8] c"The following error occurred\00"
@EXIT_FAILURE = global i32 0
@str = [19 x i8] c"Type your message:\00"
@str.9 = [27 x i8] c"\0AInitialised string array:\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [120 x i8*]
%4 = alloca [120 x i8]
%5 = alloca i32
%6 = bitcast [120 x i8*]* %3 to i8*
%7 = getelementptr inbounds [120 x i8*], [120 x i8*]* %3, i64 0, i64 2
%8 = bitcast i8** %7 to i8*
%9 = getelementptr inbounds [120 x i8*], [120 x i8*]* %3, i64 0, i64 0
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8** %9
%10 = getelementptr inbounds [120 x i8*], [120 x i8*]* %3, i64 0, i64 1
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8** %10
%11 = getelementptr inbounds [120 x i8], [120 x i8]* %4, i64 0, i64 0
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str, i64 0, i64 0))
%13 = load i32, i32* @stdin
%14 = call i32 @fgets(i8* %11, i32 120, i32 %13)
%15 = call i32 @strlen(i8* %11)
%16 = add nsw i32 %15, -1
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds [120 x i8], [120 x i8]* %4, i64 0, i64 %17
store i8 0, i8* %18
%19 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str.9, i64 0, i64 0))
br label %20
20: ; preds = %2, %44
%21 = phi i64 [ 0, %2 ], [ %45, %44 ]
%22 = phi i8* [ getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), %2 ], [ %47, %44 ]
%23 = call i8* @strstr(i8* dereferenceable(1) %11, i8* dereferenceable(1) %22)
%24 = icmp eq i8* %23, null
br i1 %24, label %44, label %25
25: ; preds = %20, %41
%26 = phi i8* [ %42, %41 ], [ %23, %20 ]
%27 = call i8* @strchr(i8* %26, i8 signext 32)
%28 = icmp eq i8* %27, null
br i1 %28, label %30, label %29
29: ; preds = %25
store i8 0, i8* %27
br label %30
30: ; preds = %29, %25
%31 = call i32 @puts(i8* %26)
%32 = call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%33 = icmp eq i32* %32, null
br i1 %33, label %56, label %34
34: ; preds = %30
%35 = getelementptr inbounds i8, i8* %26, i64 1
%36 = ptrtoint i8* %26 to i64
%37 = trunc i64 %36 to i32
%38 = call i32 @fprintf(i32* %32, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %37)
%39 = call i32 @fclose(i32* %32)
br i1 %28, label %41, label %40
40: ; preds = %34
store i8 32, i8* %27
br label %41
41: ; preds = %34, %40
%42 = call i8* @strstr(i8* dereferenceable(1) %35, i8* dereferenceable(1) %22)
%43 = icmp eq i8* %42, null
br i1 %43, label %44, label %25
44: ; preds = %41, %20
%45 = add nuw i64 %21, 1
%46 = getelementptr inbounds [120 x i8*], [120 x i8*]* %3, i64 0, i64 %45
%47 = load i8*, i8** %46
%48 = icmp eq i8* %47, null
br i1 %48, label %49, label %20
49: ; preds = %44
%50 = call i32 @time(i32* %5)
%51 = call %struct.tm* @localtime(i32* %5)
%52 = call i8* @asctime(%struct.tm* %51)
%53 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.7, i64 0, i64 0), i8* %52)
%54 = load i32, i32* @EXIT_SUCCESS
%55 = call i32 @exit(i32 %54)
unreachable
56: ; preds = %30
%57 = call i32 @perror(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.8, i64 0, i64 0))
%58 = load i32, i32* @EXIT_FAILURE
%59 = call i32 @exit(i32 %58)
unreachable
}