#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 */
struct stat {
  int /*<<< orphan*/ st_mode;
};

/* Variables and functions */
int /*<<< orphan*/ S_IXUSR;
int chmod(char const *, int /*<<< orphan*/);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *, char *);
int /*<<< orphan*/ printf(char *, char const *);
int stat(char const *, struct stat *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcmp(char const *, char *);
char *strerror(int /*<<< orphan*/);
size_t strlen(char const *);
int unlink(char const *);
void HandleFile(const char *FileName) {
  size_t len = strlen(FileName);
  if (!strcmp(&FileName[len - 2], ".o")) {
    printf("Deleting %s...\n", FileName);
    if (unlink(FileName) == -1)
      fprintf(stderr, "Unable to unlink %s: %s\n", FileName, strerror(errno));
  } else if (!strcmp(&FileName[len - 3], ".sh")) {
    struct stat statbuf;
    if (stat(FileName, &statbuf) == -1) {
      fprintf(stderr, "Unable to stat %s: %s\n", FileName, strerror(errno));
    } else {
      statbuf.st_mode |= S_IXUSR;
      printf("Adding execute access to %s\n", FileName);
      if (chmod(FileName, statbuf.st_mode) == -1)
        fprintf(stderr, "Unable to chmod %s: %s\n", FileName, strerror(errno));
    }
  }
}


x86 assembly (clang, -O0):
<HandleFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rax
sub    $0x2,%rax
add    %rax,%rdi
lea    0xe51(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%eax
jne    121c <HandleFile+0x9c>
mov    -0x8(%rbp),%rsi
lea    0xe3b(%rip),%rdi
call   1050 <printf@plt>
mov    -0x8(%rbp),%rdi
call   1030 <unlink@plt>
cmp    $0xffffffff,%eax
jne    1217 <HandleFile+0x97>
mov    0x2df2(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    0x2dd6(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    -0x24(%rbp),%edi
mov    -0x20(%rbp),%rdx
mov    %rax,%rcx
lea    0xe01(%rip),%rsi
call   1070 <fprintf@plt>
jmp    130e <HandleFile+0x18e>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rax
sub    $0x3,%rax
add    %rax,%rdi
lea    0xdfa(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%eax
jne    1309 <HandleFile+0x189>
mov    -0x8(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1080 <stat@plt>
cmp    $0xffffffff,%eax
jne    1293 <HandleFile+0x113>
mov    0x2d7b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    0x2d5f(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    -0x34(%rbp),%edi
mov    -0x30(%rbp),%rdx
mov    %rax,%rcx
lea    0xda7(%rip),%rsi
call   1070 <fprintf@plt>
jmp    1304 <HandleFile+0x184>
mov    0x2d4e(%rip),%rax
mov    (%rax),%eax
or     -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%rsi
lea    0xd9a(%rip),%rdi
call   1050 <printf@plt>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%esi
call   1090 <chmod@plt>
cmp    $0xffffffff,%eax
jne    12ff <HandleFile+0x17f>
mov    0x2d0a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x44(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    0x2cee(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    -0x44(%rbp),%edi
mov    -0x40(%rbp),%rdx
mov    %rax,%rcx
lea    0xd6a(%rip),%rsi
call   1070 <fprintf@plt>
jmp    1304 <HandleFile+0x184>
jmp    1309 <HandleFile+0x189>
jmp    130e <HandleFile+0x18e>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<HandleFile>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%r15
call   1040 <strlen@plt>
mov    %rax,%rbx
lea    (%rax,%r15,1),%rdi
add    $0xfffffffffffffffe,%rdi
lea    0xe5d(%rip),%rsi
call   1060 <strcmp@plt>
test   %eax,%eax
je     1216 <HandleFile+0x96>
lea    (%rbx,%r15,1),%rdi
add    $0xfffffffffffffffd,%rdi
lea    0xe71(%rip),%rsi
call   1060 <strcmp@plt>
test   %eax,%eax
jne    1294 <HandleFile+0x114>
lea    0x8(%rsp),%rsi
mov    %r15,%rdi
call   1080 <stat@plt>
cmp    $0xffffffff,%eax
je     1266 <HandleFile+0xe6>
mov    0x2e03(%rip),%rax
mov    0x8(%rsp),%ebx
or     (%rax),%ebx
lea    0xe55(%rip),%rdi
mov    %r15,%rsi
call   1050 <printf@plt>
mov    %r15,%rdi
mov    %ebx,%esi
call   1090 <chmod@plt>
cmp    $0xffffffff,%eax
jne    1294 <HandleFile+0x114>
lea    0xe50(%rip),%r14
jmp    126d <HandleFile+0xed>
lea    0xde6(%rip),%rdi
mov    %r15,%rsi
call   1050 <printf@plt>
mov    %r15,%rdi
call   1030 <unlink@plt>
cmp    $0xffffffff,%eax
jne    1294 <HandleFile+0x114>
mov    0x2d9f(%rip),%rax
mov    (%rax),%ebx
mov    0x2d8e(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
lea    0xdc3(%rip),%rsi
mov    %ebx,%edi
mov    %r15,%rdx
mov    %rax,%rcx
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
jmp    1070 <fprintf@plt>
lea    0xdc3(%rip),%r14
mov    0x2d64(%rip),%rax
mov    (%rax),%ebx
mov    0x2d53(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    %r15,%rdx
mov    %rax,%rcx
call   1070 <fprintf@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [3 x i8] c".o\00"
@.str.1 = [16 x i8] c"Deleting %s...\0A\00"
@stderr = global i32 0
@.str.2 = [25 x i8] c"Unable to unlink %s: %s\0A\00"
@errno = global i32 0
@.str.3 = [4 x i8] c".sh\00"
@.str.4 = [23 x i8] c"Unable to stat %s: %s\0A\00"
@S_IXUSR = global i32 0
@.str.5 = [29 x i8] c"Adding execute access to %s\0A\00"
@.str.6 = [24 x i8] c"Unable to chmod %s: %s\0A\00"
define void @HandleFile(i8* %0) {
%2 = alloca i8*
%3 = alloca i64
%4 = alloca %struct.stat
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = call i64 @strlen(i8* %5)
store i64 %6, i64* %3
%7 = load i8*, i8** %2
%8 = load i64, i64* %3
%9 = sub i64 %8, 2
%10 = getelementptr inbounds i8, i8* %7, i64 %9
%11 = call i32 @strcmp(i8* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%12 = icmp ne i32 %11, 0
br i1 %12, label %26, label %13
13: ; preds = %1
%14 = load i8*, i8** %2
%15 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* %14)
%16 = load i8*, i8** %2
%17 = call i32 @unlink(i8* %16)
%18 = icmp eq i32 %17, -1
br i1 %18, label %19, label %25
19: ; preds = %13
%20 = load i32, i32* @stderr
%21 = load i8*, i8** %2
%22 = load i32, i32* @errno
%23 = call i8* @strerror(i32 %22)
%24 = call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i8* %21, i8* %23)
br label %25
25: ; preds = %19, %13
br label %64
26: ; preds = %1
%27 = load i8*, i8** %2
%28 = load i64, i64* %3
%29 = sub i64 %28, 3
%30 = getelementptr inbounds i8, i8* %27, i64 %29
%31 = call i32 @strcmp(i8* %30, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%32 = icmp ne i32 %31, 0
br i1 %32, label %63, label %33
33: ; preds = %26
%34 = load i8*, i8** %2
%35 = call i32 @stat(i8* %34, %struct.stat* %4)
%36 = icmp eq i32 %35, -1
br i1 %36, label %37, label %43
37: ; preds = %33
%38 = load i32, i32* @stderr
%39 = load i8*, i8** %2
%40 = load i32, i32* @errno
%41 = call i8* @strerror(i32 %40)
%42 = call i32 @fprintf(i32 %38, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0), i8* %39, i8* %41)
br label %62
43: ; preds = %33
%44 = load i32, i32* @S_IXUSR
%45 = getelementptr inbounds %struct.stat, %struct.stat* %4, i32 0, i32 0
%46 = load i32, i32* %45
%47 = or i32 %46, %44
store i32 %47, i32* %45
%48 = load i8*, i8** %2
%49 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.5, i64 0, i64 0), i8* %48)
%50 = load i8*, i8** %2
%51 = getelementptr inbounds %struct.stat, %struct.stat* %4, i32 0, i32 0
%52 = load i32, i32* %51
%53 = call i32 @chmod(i8* %50, i32 %52)
%54 = icmp eq i32 %53, -1
br i1 %54, label %55, label %61
55: ; preds = %43
%56 = load i32, i32* @stderr
%57 = load i8*, i8** %2
%58 = load i32, i32* @errno
%59 = call i8* @strerror(i32 %58)
%60 = call i32 @fprintf(i32 %56, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.6, i64 0, i64 0), i8* %57, i8* %59)
br label %61
61: ; preds = %55, %43
br label %62
62: ; preds = %61, %37
br label %63
63: ; preds = %62, %26
br label %64
64: ; preds = %63, %25
ret void
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [3 x i8] c".o\00"
@.str.1 = [16 x i8] c"Deleting %s...\0A\00"
@stderr = global i32 0
@.str.2 = [25 x i8] c"Unable to unlink %s: %s\0A\00"
@errno = global i32 0
@.str.3 = [4 x i8] c".sh\00"
@.str.4 = [23 x i8] c"Unable to stat %s: %s\0A\00"
@S_IXUSR = global i32 0
@.str.5 = [29 x i8] c"Adding execute access to %s\0A\00"
@.str.6 = [24 x i8] c"Unable to chmod %s: %s\0A\00"
define void @HandleFile(i8* %0) {
%2 = alloca %struct.stat
%3 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%4 = add i64 %3, -2
%5 = getelementptr inbounds i8, i8* %0, i64 %4
%6 = tail call i32 @strcmp(i8* dereferenceable(1) %5, i8* dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %17
8: ; preds = %1
%9 = tail call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%10 = tail call i32 @unlink(i8* %0)
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %41
12: ; preds = %8
%13 = load i32, i32* @stderr
%14 = load i32, i32* @errno
%15 = tail call i8* @strerror(i32 %14)
%16 = tail call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i8* %0, i8* %15)
br label %41
17: ; preds = %1
%18 = add i64 %3, -3
%19 = getelementptr inbounds i8, i8* %0, i64 %18
%20 = tail call i32 @strcmp(i8* dereferenceable(1) %19, i8* dereferenceable(4) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%21 = icmp eq i32 %20, 0
br i1 %21, label %22, label %41
22: ; preds = %17
%23 = bitcast %struct.stat* %2 to i8*
%24 = call i32 @stat(i8* %0, %struct.stat* %2)
%25 = icmp eq i32 %24, -1
br i1 %25, label %34, label %26
26: ; preds = %22
%27 = load i32, i32* @S_IXUSR
%28 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 0
%29 = load i32, i32* %28
%30 = or i32 %29, %27
%31 = tail call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.5, i64 0, i64 0), i8* %0)
%32 = tail call i32 @chmod(i8* %0, i32 %30)
%33 = icmp eq i32 %32, -1
br i1 %33, label %34, label %40
34: ; preds = %26, %22
%35 = phi i8* [ getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0), %22 ], [ getelementptr inbounds ([24 x i8], [24 x i8]* @.str.6, i64 0, i64 0), %26 ]
%36 = load i32, i32* @stderr
%37 = load i32, i32* @errno
%38 = tail call i8* @strerror(i32 %37)
%39 = tail call i32 @fprintf(i32 %36, i8* %35, i8* %0, i8* %38)
br label %40
40: ; preds = %34, %26
br label %41
41: ; preds = %17, %40, %8, %12
ret void
}