#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;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
char EOF;
char *asctime(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char *);
char getc(int /*<<< orphan*/ *);
int /*<<< orphan*/ localtime(int /*<<< orphan*/ *);
int /*<<< orphan*/ putc(char, int /*<<< orphan*/ *);
int /*<<< orphan*/ *stdout;
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int main(int argc, char **argv) {
  FILE *note;
  time_t timer;
  int i;
  char ch;
  if (argc == 1) {
    note = fopen("NOTES.TXT", "r");
    if (note != NULL) {
      while ((ch = getc(note)) != EOF)
        putc(ch, stdout);
    }
  } else {
    note = fopen("NOTES.TXT", "a");
    if (note != NULL) {
      timer = time(NULL);
      fprintf(note, "%s", asctime(localtime(&timer)));
      putc('\t', note);
      for (i = 1; i < argc; i++)
        fprintf(note, "%s ", argv[i]);
      putc('\n', note);
    }
  }
  fclose(note);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x1,-0x8(%rbp)
jne    120c <main+0x8c>
lea    0xe59(%rip),%rdi
lea    0xe5c(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1207 <main+0x87>
jmp    11c7 <main+0x47>
mov    -0x18(%rbp),%rdi
call   10a0 <getc@plt>
mov    %al,-0x21(%rbp)
movsbl %al,%eax
mov    0x2e0b(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     1202 <main+0x82>
mov    -0x21(%rbp),%al
mov    0x2de6(%rip),%rcx
mov    (%rcx),%rsi
movsbl %al,%edi
call   1060 <putc@plt>
jmp    11c7 <main+0x47>
jmp    1207 <main+0x87>
jmp    12c3 <main+0x143>
lea    0xded(%rip),%rdi
lea    0xdf2(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     12be <main+0x13e>
xor    %eax,%eax
mov    %eax,%edi
call   1080 <time@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
lea    -0x1c(%rbp),%rdi
call   1030 <localtime@plt>
mov    %eax,%edi
call   1050 <asctime@plt>
mov    -0x30(%rbp),%rdi
mov    %rax,%rdx
lea    0xdae(%rip),%rsi
call   1070 <fprintf@plt>
mov    -0x18(%rbp),%rsi
mov    $0x9,%edi
call   1060 <putc@plt>
movl   $0x1,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    12b0 <main+0x130>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xd74(%rip),%rsi
call   1070 <fprintf@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    127a <main+0xfa>
mov    -0x18(%rbp),%rsi
mov    $0xa,%edi
call   1060 <putc@plt>
jmp    12c3 <main+0x143>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
cmp    $0x1,%edi
jne    11fe <main+0x6e>
lea    0xe58(%rip),%rdi
lea    0xe5b(%rip),%rsi
call   10a0 <fopen@plt>
test   %rax,%rax
je     1297 <main+0x107>
mov    %rax,%r12
mov    %rax,%rdi
call   10b0 <getc@plt>
mov    0x2e19(%rip),%r14
cmp    (%r14),%al
je     129a <main+0x10a>
mov    0x2df9(%rip),%rbp
nop
mov    0x0(%rbp),%rsi
movsbl %al,%edi
call   1070 <putc@plt>
mov    %r12,%rdi
call   10b0 <getc@plt>
cmp    (%r14),%al
jne    11e0 <main+0x50>
jmp    129a <main+0x10a>
mov    %rsi,%r14
mov    %edi,%ebp
lea    0xdf6(%rip),%rdi
lea    0xdfb(%rip),%rsi
call   10a0 <fopen@plt>
test   %rax,%rax
je     1297 <main+0x107>
mov    %rax,%r12
xor    %edi,%edi
call   1090 <time@plt>
mov    %eax,0xc(%rsp)
lea    0xc(%rsp),%rdi
call   1030 <localtime@plt>
mov    %eax,%edi
call   1050 <asctime@plt>
mov    %rax,%rdi
mov    %r12,%rsi
call   1060 <fputs@plt>
mov    $0x9,%edi
mov    %r12,%rsi
call   1070 <putc@plt>
cmp    $0x2,%ebp
jl     1288 <main+0xf8>
mov    %ebp,%ebp
mov    $0x1,%ebx
lea    0xda9(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nop
mov    (%r14,%rbx,8),%rdx
mov    %r12,%rdi
mov    %r15,%rsi
call   1080 <fprintf@plt>
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1270 <main+0xe0>
mov    $0xa,%edi
mov    %r12,%rsi
call   1070 <putc@plt>
jmp    129a <main+0x10a>
xor    %r12d,%r12d
mov    %r12,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [10 x i8] c"NOTES.TXT\00"
@.str.1 = [2 x i8] c"r\00"
@EOF = global i8 0
@stdout = global i32* null
@.str.2 = [2 x i8] c"a\00"
@.str.3 = [3 x i8] c"%s\00"
@.str.4 = [4 x i8] c"%s \00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp eq i32 %10, 1
br i1 %11, label %12, label %30
12: ; preds = %2
%13 = call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %13, i32** %6
%14 = load i32*, i32** %6
%15 = icmp ne i32* %14, null
br i1 %15, label %16, label %29
16: ; preds = %12
br label %17
17: ; preds = %24, %16
%18 = load i32*, i32** %6
%19 = call signext i8 @getc(i32* %18)
store i8 %19, i8* %9
%20 = sext i8 %19 to i32
%21 = load i8, i8* @EOF
%22 = sext i8 %21 to i32
%23 = icmp ne i32 %20, %22
br i1 %23, label %24, label %28
24: ; preds = %17
%25 = load i8, i8* %9
%26 = load i32*, i32** @stdout
%27 = call i32 @putc(i8 signext %25, i32* %26)
br label %17
28: ; preds = %17
br label %29
29: ; preds = %28, %12
br label %61
30: ; preds = %2
%31 = call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %31, i32** %6
%32 = load i32*, i32** %6
%33 = icmp ne i32* %32, null
br i1 %33, label %34, label %60
34: ; preds = %30
%35 = call i32 @time(i32* null)
store i32 %35, i32* %7
%36 = load i32*, i32** %6
%37 = call i32 @localtime(i32* %7)
%38 = call i8* @asctime(i32 %37)
%39 = call i32 @fprintf(i32* %36, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %38)
%40 = load i32*, i32** %6
%41 = call i32 @putc(i8 signext 9, i32* %40)
store i32 1, i32* %8
br label %42
42: ; preds = %54, %34
%43 = load i32, i32* %8
%44 = load i32, i32* %4
%45 = icmp slt i32 %43, %44
br i1 %45, label %46, label %57
46: ; preds = %42
%47 = load i32*, i32** %6
%48 = load i8**, i8*** %5
%49 = load i32, i32* %8
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds i8*, i8** %48, i64 %50
%52 = load i8*, i8** %51
%53 = call i32 @fprintf(i32* %47, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %52)
br label %54
54: ; preds = %46
%55 = load i32, i32* %8
%56 = add nsw i32 %55, 1
store i32 %56, i32* %8
br label %42
57: ; preds = %42
%58 = load i32*, i32** %6
%59 = call i32 @putc(i8 signext 10, i32* %58)
br label %60
60: ; preds = %57, %30
br label %61
61: ; preds = %60, %29
%62 = load i32*, i32** %6
%63 = call i32 @fclose(i32* %62)
ret i32 0
}

LLVM IR (-O2):
@.str = [10 x i8] c"NOTES.TXT\00"
@.str.1 = [2 x i8] c"r\00"
@EOF = global i8 0
@stdout = global i32* null
@.str.2 = [2 x i8] c"a\00"
@.str.4 = [4 x i8] c"%s \00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = icmp eq i32 %0, 1
br i1 %5, label %6, label %20
6: ; preds = %2
%7 = tail call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%8 = icmp eq i32* %7, null
br i1 %8, label %41, label %9
9: ; preds = %6
%10 = tail call signext i8 @getc(i32* %7)
%11 = load i8, i8* @EOF
%12 = icmp eq i8 %10, %11
br i1 %12, label %41, label %13
13: ; preds = %9, %13
%14 = phi i8 [ %17, %13 ], [ %10, %9 ]
%15 = load i32*, i32** @stdout
%16 = tail call i32 @putc(i8 signext %14, i32* %15)
%17 = tail call signext i8 @getc(i32* %7)
%18 = load i8, i8* @EOF
%19 = icmp eq i8 %17, %18
br i1 %19, label %41, label %13
20: ; preds = %2
%21 = tail call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%22 = icmp eq i32* %21, null
br i1 %22, label %41, label %23
23: ; preds = %20
%24 = tail call i32 @time(i32* null)
store i32 %24, i32* %3
%25 = call i32 @localtime(i32* %3)
%26 = call i8* @asctime(i32 %25)
%27 = call i32 @fputs(i8* %26, i32* %21)
%28 = call i32 @putc(i8 signext 9, i32* %21)
%29 = icmp sgt i32 %0, 1
br i1 %29, label %30, label %39
30: ; preds = %23
%31 = zext i32 %0 to i64
br label %32
32: ; preds = %30, %32
%33 = phi i64 [ 1, %30 ], [ %37, %32 ]
%34 = getelementptr inbounds i8*, i8** %1, i64 %33
%35 = load i8*, i8** %34
%36 = call i32 @fprintf(i32* %21, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %35)
%37 = add nuw nsw i64 %33, 1
%38 = icmp eq i64 %37, %31
br i1 %38, label %39, label %32
39: ; preds = %32, %23
%40 = call i32 @putc(i8 signext 10, i32* %21)
br label %41
41: ; preds = %13, %9, %20, %39, %6
%42 = phi i32* [ null, %6 ], [ %21, %39 ], [ null, %20 ], [ %7, %9 ], [ %7, %13 ]
%43 = call i32 @fclose(i32* %42)
ret i32 0
}