#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*/ init();
int /*<<< orphan*/ *libc_fopen64(char const *, char const *);
scalar_t__ strchr(char const *, char);
int /*<<< orphan*/ watch_log(char *, char const *);
FILE *fopen64(const char *path, const char *mode) {
  init();
  if (strchr(mode, 'w') || strchr(mode, 'a')) {
    watch_log("open %s w\n", path);
  }
  return libc_fopen64(path, mode);
}


x86 assembly (clang, -O0):
<fopen64>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   1050 <init@plt>
mov    -0x10(%rbp),%rdi
mov    $0x77,%esi
call   1030 <strchr@plt>
cmp    $0x0,%rax
jne    1187 <fopen64+0x47>
mov    -0x10(%rbp),%rdi
mov    $0x61,%esi
call   1030 <strchr@plt>
cmp    $0x0,%rax
je     1197 <fopen64+0x57>
mov    -0x8(%rbp),%rsi
lea    0xe6e(%rip),%rdi
call   1060 <watch_log@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <libc_fopen64@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fopen64>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r14
xor    %eax,%eax
call   1050 <init@plt>
mov    %rbx,%rdi
mov    $0x77,%esi
call   1030 <strchr@plt>
test   %rax,%rax
jne    1175 <fopen64+0x35>
mov    %rbx,%rdi
mov    $0x61,%esi
call   1030 <strchr@plt>
test   %rax,%rax
je     1184 <fopen64+0x44>
lea    0xe84(%rip),%rdi
mov    %r14,%rsi
call   1060 <watch_log@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1040 <libc_fopen64@plt>

LLVM IR (-O0):
@.str = [11 x i8] c"open %s w\0A\00"
define i32* @fopen64(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
store i8* %0, i8** %3
store i8* %1, i8** %4
%5 = call i32 (...) @init()
%6 = load i8*, i8** %4
%7 = call i64 @strchr(i8* %6, i8 signext 119)
%8 = icmp ne i64 %7, 0
br i1 %8, label %13, label %9
9: ; preds = %2
%10 = load i8*, i8** %4
%11 = call i64 @strchr(i8* %10, i8 signext 97)
%12 = icmp ne i64 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %9, %2
%14 = load i8*, i8** %3
%15 = call i32 @watch_log(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* %14)
br label %16
16: ; preds = %13, %9
%17 = load i8*, i8** %3
%18 = load i8*, i8** %4
%19 = call i32* @libc_fopen64(i8* %17, i8* %18)
ret i32* %19
}

LLVM IR (-O2):
@.str = [11 x i8] c"open %s w\0A\00"
define i32* @fopen64(i8* %0, i8* %1) {
%3 = tail call i32 (...) @init()
%4 = tail call i64 @strchr(i8* %1, i8 signext 119)
%5 = icmp eq i64 %4, 0
br i1 %5, label %6, label %9
6: ; preds = %2
%7 = tail call i64 @strchr(i8* %1, i8 signext 97)
%8 = icmp eq i64 %7, 0
br i1 %8, label %11, label %9
9: ; preds = %6, %2
%10 = tail call i32 @watch_log(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %11
11: ; preds = %9, %6
%12 = tail call i32* @libc_fopen64(i8* %0, i8* %1)
ret i32* %12
}