#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_FAILURE;
int PATH_MAX;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ perror(char const *);
int /*<<< orphan*/ stderr;
char *strstr(char *, char *);
int utime(char *, int /*<<< orphan*/ *);
void protect(const char *fn) {
  FILE *fpi;
  char buf[PATH_MAX];
  char *dow[] = {" Sun", " Mon", " Tue", " Wed", " Thu", " Fri", " Sat"};
  char *cp;
  int badformat, i;
  if (!(fpi = fopen(fn, "r"))) {
    perror(fn);
    exit(EXIT_FAILURE);
  }
  while (fgets(buf, PATH_MAX, fpi)) {
    badformat = 1;
    for (i = 0; i < 7; i++) {
      cp = strstr(buf, dow[i]);
      if (cp) {
        badformat = 0;
        break;
      }
    }
    if (badformat) {
      fprintf(stderr, "Mal formed data line: %s\n", buf);
      exit(EXIT_FAILURE);
    }
    *cp = 0;
    if (utime(buf, NULL) == -1) {
      perror(buf);
    }
  }
}


x86 assembly (clang, -O0):
<protect>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x8(%rbp)
mov    0x2e5a(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x78(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x20(%rbp)
lea    -0x60(%rbp),%rdi
lea    0x2c0a(%rip),%rsi
mov    $0x38,%edx
call   1060 <memcpy@plt>
mov    -0x8(%rbp),%rdi
lea    0xe48(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    1205 <protect+0x85>
mov    -0x8(%rbp),%rdi
call   1080 <perror@plt>
mov    0x2dd2(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
jmp    120a <protect+0x8a>
mov    -0x78(%rbp),%rdi
mov    0x2ddb(%rip),%rax
mov    (%rax),%esi
mov    -0x10(%rbp),%rdx
call   1040 <fgets@plt>
cmp    $0x0,%rax
je     12de <protect+0x15e>
movl   $0x1,-0x6c(%rbp)
movl   $0x0,-0x70(%rbp)
cmpl   $0x7,-0x70(%rbp)
jge    1282 <protect+0x102>
mov    -0x78(%rbp),%rdi
movslq -0x70(%rbp),%rax
mov    -0x60(%rbp,%rax,8),%rsi
call   10a0 <strstr@plt>
mov    %rax,-0x68(%rbp)
cmpq   $0x0,-0x68(%rbp)
je     126f <protect+0xef>
movl   $0x0,-0x6c(%rbp)
jmp    1282 <protect+0x102>
jmp    1274 <protect+0xf4>
mov    -0x70(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x70(%rbp)
jmp    1238 <protect+0xb8>
cmpl   $0x0,-0x6c(%rbp)
je     12b3 <protect+0x133>
mov    -0x78(%rbp),%rdx
mov    0x2d41(%rip),%rax
mov    (%rax),%edi
lea    0xd85(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2d24(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    -0x78(%rbp),%rdi
mov    -0x68(%rbp),%rax
movb   $0x0,(%rax)
xor    %eax,%eax
mov    %eax,%esi
call   1030 <utime@plt>
cmp    $0xffffffff,%eax
jne    12d9 <protect+0x159>
mov    -0x78(%rbp),%rdi
call   1080 <perror@plt>
jmp    120a <protect+0x8a>
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<protect>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r15
mov    0x2e68(%rip),%r13
mov    0x0(%r13),%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
lea    0xe7f(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     12bc <protect+0x14c>
mov    %rax,%r14
mov    0x0(%r13),%esi
mov    %rbx,%rdi
mov    %rax,%rdx
call   1040 <fgets@plt>
test   %rax,%rax
je     12ad <protect+0x13d>
lea    0xe2c(%rip),%r15
lea    0xe2a(%rip),%r12
jmp    120e <protect+0x9e>
nopl   (%rax)
movb   $0x0,(%rax)
mov    %rbx,%rdi
xor    %esi,%esi
call   1030 <utime@plt>
cmp    $0xffffffff,%eax
je     12a0 <protect+0x130>
mov    0x0(%r13),%esi
mov    %rbx,%rdi
mov    %r14,%rdx
call   1040 <fgets@plt>
test   %rax,%rax
je     12ad <protect+0x13d>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1090 <strstr@plt>
test   %rax,%rax
jne    11e0 <protect+0x70>
mov    %rbx,%rdi
mov    %r12,%rsi
call   1090 <strstr@plt>
test   %rax,%rax
jne    11e0 <protect+0x70>
mov    %rbx,%rdi
lea    0xdd2(%rip),%rsi
call   1090 <strstr@plt>
test   %rax,%rax
jne    11e0 <protect+0x70>
mov    %rbx,%rdi
lea    0xdc3(%rip),%rsi
call   1090 <strstr@plt>
test   %rax,%rax
jne    11e0 <protect+0x70>
mov    %rbx,%rdi
lea    0xdb4(%rip),%rsi
call   1090 <strstr@plt>
test   %rax,%rax
jne    11e0 <protect+0x70>
mov    %rbx,%rdi
lea    0xda1(%rip),%rsi
call   1090 <strstr@plt>
test   %rax,%rax
jne    11e0 <protect+0x70>
mov    %rbx,%rdi
lea    0xd8e(%rip),%rsi
call   1090 <strstr@plt>
test   %rax,%rax
jne    11e0 <protect+0x70>
jmp    12d2 <protect+0x162>
mov    %rbx,%rdi
call   1070 <perror@plt>
jmp    11f6 <protect+0x86>
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r15,%rdi
call   1070 <perror@plt>
mov    0x2d05(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    0x2cff(%rip),%rax
mov    (%rax),%edi
lea    0xd43(%rip),%rsi
mov    %rbx,%rdx
call   1050 <fprintf@plt>
jmp    12c4 <protect+0x154>

LLVM IR (-O0):
@PATH_MAX = global i32 0
@.str = [5 x i8] c" Sun\00"
@.str.1 = [5 x i8] c" Mon\00"
@.str.2 = [5 x i8] c" Tue\00"
@.str.3 = [5 x i8] c" Wed\00"
@.str.4 = [5 x i8] c" Thu\00"
@.str.5 = [5 x i8] c" Fri\00"
@.str.6 = [5 x i8] c" Sat\00"
@__const.protect.dow = [7 x i8*] [i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i32 0, i32 0)]
@.str.7 = [2 x i8] c"r\00"
@EXIT_FAILURE = global i32 0
@stderr = global i32 0
@.str.8 = [26 x i8] c"Mal formed data line: %s\0A\00"
define void @protect(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i8*
%5 = alloca i64
%6 = alloca [7 x i8*]
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %2
%10 = load i32, i32* @PATH_MAX
%11 = zext i32 %10 to i64
%12 = call i8* @llvm.stacksave()
store i8* %12, i8** %4
%13 = alloca i8, i64 %11
store i64 %11, i64* %5
%14 = bitcast [7 x i8*]* %6 to i8*
%15 = load i8*, i8** %2
%16 = call i32* @fopen(i8* %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
store i32* %16, i32** %3
%17 = icmp ne i32* %16, null
br i1 %17, label %23, label %18
18: ; preds = %1
%19 = load i8*, i8** %2
%20 = call i32 @perror(i8* %19)
%21 = load i32, i32* @EXIT_FAILURE
%22 = call i32 @exit(i32 %21)
unreachable
23: ; preds = %1
br label %24
24: ; preds = %60, %23
%25 = load i32, i32* @PATH_MAX
%26 = load i32*, i32** %3
%27 = call i64 @fgets(i8* %13, i32 %25, i32* %26)
%28 = icmp ne i64 %27, 0
br i1 %28, label %29, label %61
29: ; preds = %24
store i32 1, i32* %8
store i32 0, i32* %9
br label %30
30: ; preds = %43, %29
%31 = load i32, i32* %9
%32 = icmp slt i32 %31, 7
br i1 %32, label %33, label %46
33: ; preds = %30
%34 = load i32, i32* %9
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds [7 x i8*], [7 x i8*]* %6, i64 0, i64 %35
%37 = load i8*, i8** %36
%38 = call i8* @strstr(i8* %13, i8* %37)
store i8* %38, i8** %7
%39 = load i8*, i8** %7
%40 = icmp ne i8* %39, null
br i1 %40, label %41, label %42
41: ; preds = %33
store i32 0, i32* %8
br label %46
42: ; preds = %33
br label %43
43: ; preds = %42
%44 = load i32, i32* %9
%45 = add nsw i32 %44, 1
store i32 %45, i32* %9
br label %30
46: ; preds = %41, %30
%47 = load i32, i32* %8
%48 = icmp ne i32 %47, 0
br i1 %48, label %49, label %54
49: ; preds = %46
%50 = load i32, i32* @stderr
%51 = call i32 @fprintf(i32 %50, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.8, i64 0, i64 0), i8* %13)
%52 = load i32, i32* @EXIT_FAILURE
%53 = call i32 @exit(i32 %52)
unreachable
54: ; preds = %46
%55 = load i8*, i8** %7
store i8 0, i8* %55
%56 = call i32 @utime(i8* %13, i32* null)
%57 = icmp eq i32 %56, -1
br i1 %57, label %58, label %60
58: ; preds = %54
%59 = call i32 @perror(i8* %13)
br label %60
60: ; preds = %58, %54
br label %24
61: ; preds = %24
%62 = load i8*, i8** %4
ret void
}

LLVM IR (-O2):
@PATH_MAX = global i32 0
@.str = [5 x i8] c" Sun\00"
@.str.1 = [5 x i8] c" Mon\00"
@.str.2 = [5 x i8] c" Tue\00"
@.str.3 = [5 x i8] c" Wed\00"
@.str.4 = [5 x i8] c" Thu\00"
@.str.5 = [5 x i8] c" Fri\00"
@.str.6 = [5 x i8] c" Sat\00"
@.str.7 = [2 x i8] c"r\00"
@EXIT_FAILURE = global i32 0
@stderr = global i32 0
@.str.8 = [26 x i8] c"Mal formed data line: %s\0A\00"
define void @protect(i8* nocapture %0) {
%2 = load i32, i32* @PATH_MAX
%3 = zext i32 %2 to i64
%4 = alloca i8, i64 %3
%5 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %11, label %7
7: ; preds = %1
%8 = load i32, i32* @PATH_MAX
%9 = call i64 @fgets(i8* %4, i32 %8, i32* %5)
%10 = icmp eq i64 %9, 0
br i1 %10, label %51, label %15
11: ; preds = %1
%12 = tail call i32 @perror(i8* %0)
%13 = load i32, i32* @EXIT_FAILURE
%14 = tail call i32 @exit(i32 %13)
unreachable
15: ; preds = %7, %47
%16 = call i8* @strstr(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%17 = icmp eq i8* %16, null
br i1 %17, label %18, label %41
18: ; preds = %15
%19 = call i8* @strstr(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%20 = icmp eq i8* %19, null
br i1 %20, label %21, label %41
21: ; preds = %18
%22 = call i8* @strstr(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%23 = icmp eq i8* %22, null
br i1 %23, label %24, label %41
24: ; preds = %21
%25 = call i8* @strstr(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%26 = icmp eq i8* %25, null
br i1 %26, label %27, label %41
27: ; preds = %24
%28 = call i8* @strstr(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%29 = icmp eq i8* %28, null
br i1 %29, label %30, label %41
30: ; preds = %27
%31 = call i8* @strstr(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
%32 = icmp eq i8* %31, null
br i1 %32, label %33, label %41
33: ; preds = %30
%34 = call i8* @strstr(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0))
%35 = icmp eq i8* %34, null
br i1 %35, label %36, label %41
36: ; preds = %33
%37 = load i32, i32* @stderr
%38 = call i32 @fprintf(i32 %37, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.8, i64 0, i64 0), i8* %4)
%39 = load i32, i32* @EXIT_FAILURE
%40 = call i32 @exit(i32 %39)
unreachable
41: ; preds = %33, %30, %27, %24, %21, %18, %15
%42 = phi i8* [ %16, %15 ], [ %19, %18 ], [ %22, %21 ], [ %25, %24 ], [ %28, %27 ], [ %31, %30 ], [ %34, %33 ]
store i8 0, i8* %42
%43 = call i32 @utime(i8* %4, i32* null)
%44 = icmp eq i32 %43, -1
br i1 %44, label %45, label %47
45: ; preds = %41
%46 = call i32 @perror(i8* %4)
br label %47
47: ; preds = %45, %41
%48 = load i32, i32* @PATH_MAX
%49 = call i64 @fgets(i8* %4, i32 %48, i32* %5)
%50 = icmp eq i64 %49, 0
br i1 %50, label %51, label %15
51: ; preds = %47, %7
ret void
}