#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*/ W_OK;
int /*<<< orphan*/ access(char *, int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fwrite(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, char *);
int /*<<< orphan*/ sleep(int);
int strlen(char *);
int main() {
  char *fn = "/tmp/XYZ";
  char buffer[60];
  FILE *fp;
  scanf("%50s", buffer);
  if (!access(fn, W_OK)) {
    sleep(3);
    printf("\nRECEIVED STRING: %s\n", buffer);
    fp = fopen(fn, "a+");
    printf("\nOpened file: %s\n", fn);
    fwrite(buffer, sizeof(char), strlen(buffer), fp);
    printf("\nWrote to file-1: %s\n", fn);
    fwrite("\n", sizeof(char), 1, fp);
    printf("\nWrote to file-2: %s\n", fn);
    fclose(fp);
  } else
    printf("No permission \n");
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe6a(%rip),%rax
mov    %rax,-0x10(%rbp)
lea    -0x50(%rbp),%rsi
lea    0xe64(%rip),%rdi
call   1060 <scanf@plt>
mov    -0x10(%rbp),%rdi
mov    0x2e33(%rip),%rax
mov    (%rax),%esi
call   1070 <access@plt>
cmp    $0x0,%eax
jne    1275 <main+0xf5>
mov    $0x3,%edi
call   10a0 <sleep@plt>
lea    -0x50(%rbp),%rsi
lea    0xe34(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%rdi
lea    0xe38(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x58(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xe27(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x50(%rbp),%rax
mov    %rax,-0x60(%rbp)
lea    -0x50(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x60(%rbp),%rdi
mov    %eax,%edx
mov    -0x58(%rbp),%rcx
mov    $0x1,%esi
call   1090 <fwrite@plt>
mov    -0x10(%rbp),%rsi
lea    0xe02(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x58(%rbp),%rcx
lea    0xe2a(%rip),%rdi
mov    $0x1,%edx
mov    %edx,%esi
call   1090 <fwrite@plt>
mov    -0x10(%rbp),%rsi
lea    0xdef(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x58(%rbp),%rdi
call   1030 <fclose@plt>
jmp    1283 <main+0x103>
lea    0xde9(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x40,%rsp
lea    0xe59(%rip),%rdi
mov    %rsp,%rsi
call   1080 <scanf@plt>
mov    0x2e29(%rip),%rax
mov    (%rax),%esi
lea    0xe38(%rip),%rdi
call   1090 <access@plt>
test   %eax,%eax
je     11e2 <main+0x42>
lea    0xe8d(%rip),%rdi
call   1030 <puts@plt>
jmp    127b <main+0xdb>
mov    $0x3,%edi
call   10c0 <sleep@plt>
lea    0xe1b(%rip),%rdi
mov    %rsp,%r15
mov    %r15,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xdf9(%rip),%r14
lea    0xe16(%rip),%rsi
mov    %r14,%rdi
call   10a0 <fopen@plt>
mov    %rax,%rbx
lea    0xe07(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r15,%rdi
call   1050 <strlen@plt>
mov    %r15,%rdi
mov    $0x1,%esi
mov    %eax,%edx
mov    %rbx,%rcx
call   10b0 <fwrite@plt>
lea    0xdee(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0xa,%edi
mov    %rbx,%rsi
call   1070 <fputc@plt>
lea    0xde6(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [9 x i8] c"/tmp/XYZ\00"
@.str.1 = [5 x i8] c"%50s\00"
@W_OK = global i32 0
@.str.2 = [22 x i8] c"\0ARECEIVED STRING: %s\0A\00"
@.str.3 = [3 x i8] c"a+\00"
@.str.4 = [18 x i8] c"\0AOpened file: %s\0A\00"
@.str.5 = [22 x i8] c"\0AWrote to file-1: %s\0A\00"
@.str.6 = [2 x i8] c"\0A\00"
@.str.7 = [22 x i8] c"\0AWrote to file-2: %s\0A\00"
@.str.8 = [16 x i8] c"No permission \0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca [60 x i8]
%4 = alloca i32*
store i32 0, i32* %1
store i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8** %2
%5 = getelementptr inbounds [60 x i8], [60 x i8]* %3, i64 0, i64 0
%6 = call i32 @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %5)
%7 = load i8*, i8** %2
%8 = load i32, i32* @W_OK
%9 = call i32 @access(i8* %7, i32 %8)
%10 = icmp ne i32 %9, 0
br i1 %10, label %32, label %11
11: ; preds = %0
%12 = call i32 @sleep(i32 3)
%13 = getelementptr inbounds [60 x i8], [60 x i8]* %3, i64 0, i64 0
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i8* %13)
%15 = load i8*, i8** %2
%16 = call i32* @fopen(i8* %15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
store i32* %16, i32** %4
%17 = load i8*, i8** %2
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), i8* %17)
%19 = getelementptr inbounds [60 x i8], [60 x i8]* %3, i64 0, i64 0
%20 = getelementptr inbounds [60 x i8], [60 x i8]* %3, i64 0, i64 0
%21 = call i32 @strlen(i8* %20)
%22 = load i32*, i32** %4
%23 = call i32 @fwrite(i8* %19, i32 1, i32 %21, i32* %22)
%24 = load i8*, i8** %2
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0), i8* %24)
%26 = load i32*, i32** %4
%27 = call i32 @fwrite(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0), i32 1, i32 1, i32* %26)
%28 = load i8*, i8** %2
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.7, i64 0, i64 0), i8* %28)
%30 = load i32*, i32** %4
%31 = call i32 @fclose(i32* %30)
br label %34
32: ; preds = %0
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.8, i64 0, i64 0))
br label %34
34: ; preds = %32, %11
%35 = load i32, i32* %1
ret i32 %35
}

LLVM IR (-O2):
@.str = [9 x i8] c"/tmp/XYZ\00"
@.str.1 = [5 x i8] c"%50s\00"
@W_OK = global i32 0
@.str.2 = [22 x i8] c"\0ARECEIVED STRING: %s\0A\00"
@.str.3 = [3 x i8] c"a+\00"
@.str.4 = [18 x i8] c"\0AOpened file: %s\0A\00"
@.str.5 = [22 x i8] c"\0AWrote to file-1: %s\0A\00"
@.str.7 = [22 x i8] c"\0AWrote to file-2: %s\0A\00"
@str = [15 x i8] c"No permission \00"
define i32 @main() {
%1 = alloca [60 x i8]
%2 = getelementptr inbounds [60 x i8], [60 x i8]* %1, i64 0, i64 0
%3 = call i32 @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %2)
%4 = load i32, i32* @W_OK
%5 = call i32 @access(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %4)
%6 = icmp eq i32 %5, 0
br i1 %6, label %7, label %18
7: ; preds = %0
%8 = call i32 @sleep(i32 3)
%9 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i8* %2)
%10 = call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%11 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%12 = call i32 @strlen(i8* %2)
%13 = call i32 @fwrite(i8* %2, i32 1, i32 %12, i32* %10)
%14 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%15 = call i32 @fputc(i32 10, i32* %10)
%16 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%17 = call i32 @fclose(i32* %10)
br label %20
18: ; preds = %0
%19 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str, i64 0, i64 0))
br label %20
20: ; preds = %18, %7
ret i32 0
}