#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 pattern_image {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ LOCK_EX;
int /*<<< orphan*/ LOCK_UN;
int O_CREAT;
int /*<<< orphan*/ O_RDONLY;
int O_TRUNC;
int O_WRONLY;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ flock(int, int /*<<< orphan*/);
int open(char *, int, ...);
int /*<<< orphan*/ write(int, struct pattern_image *, size_t);
int /*<<< orphan*/ ytht_mgrep_prepf(int, struct pattern_image **, size_t *);
int /*<<< orphan*/ ytht_mgrep_releasepf(struct pattern_image *);
int ytht_smth_reload_badwords(char *wordlistf, char *imgf) {
  int fp;
  struct pattern_image *pattern_buf;
  size_t pattern_imagesize;
  fp = open(wordlistf, O_RDONLY);
  if (fp == -1)
    return -1;
  flock(fp, LOCK_EX);
  ytht_mgrep_prepf(fp, &pattern_buf, &pattern_imagesize);
  flock(fp, LOCK_UN);
  close(fp);
  fp = open(imgf, O_WRONLY | O_TRUNC | O_CREAT, 0600);
  if (fp == -1) {
    ytht_mgrep_releasepf(pattern_buf);
    return -1;
  }
  write(fp, pattern_buf, pattern_imagesize);
  close(fp);
  ytht_mgrep_releasepf(pattern_buf);
  return 0;
}


x86 assembly (clang, -O0):
<ytht_smth_reload_badwords>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e55(%rip),%rax
mov    (%rax),%esi
mov    $0x0,%al
call   1060 <open@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    119d <ytht_smth_reload_badwords+0x3d>
movl   $0xffffffff,-0x4(%rbp)
jmp    124c <ytht_smth_reload_badwords+0xec>
mov    -0x1c(%rbp),%edi
mov    0x2e31(%rip),%rax
mov    (%rax),%esi
call   1070 <flock@plt>
mov    -0x1c(%rbp),%edi
lea    -0x28(%rbp),%rsi
lea    -0x30(%rbp),%rdx
call   1030 <ytht_mgrep_prepf@plt>
mov    -0x1c(%rbp),%edi
mov    0x2df8(%rip),%rax
mov    (%rax),%esi
call   1070 <flock@plt>
mov    -0x1c(%rbp),%edi
call   1050 <close@plt>
mov    -0x18(%rbp),%rdi
mov    0x2dce(%rip),%rax
mov    (%rax),%esi
mov    0x2e05(%rip),%rax
or     (%rax),%esi
mov    0x2e04(%rip),%rax
or     (%rax),%esi
mov    $0x180,%edx
mov    $0x0,%al
call   1060 <open@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    1224 <ytht_smth_reload_badwords+0xc4>
mov    -0x28(%rbp),%rdi
call   1080 <ytht_mgrep_releasepf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    124c <ytht_smth_reload_badwords+0xec>
mov    -0x1c(%rbp),%edi
mov    -0x28(%rbp),%rsi
mov    -0x30(%rbp),%rdx
call   1040 <write@plt>
mov    -0x1c(%rbp),%edi
call   1050 <close@plt>
mov    -0x28(%rbp),%rdi
call   1080 <ytht_mgrep_releasepf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ytht_smth_reload_badwords>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbx
mov    0x2e60(%rip),%rax
mov    (%rax),%esi
xor    %eax,%eax
call   1060 <open@plt>
cmp    $0xffffffff,%eax
je     120e <ytht_smth_reload_badwords+0xae>
mov    %eax,%ebp
mov    0x2e4d(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
call   1070 <flock@plt>
lea    0x8(%rsp),%rsi
lea    0x10(%rsp),%rdx
mov    %ebp,%edi
call   1030 <ytht_mgrep_prepf@plt>
mov    0x2e14(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
call   1070 <flock@plt>
mov    %ebp,%edi
call   1050 <close@plt>
mov    0x2ded(%rip),%rax
mov    0x2e26(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2e23(%rip),%rax
or     (%rax),%esi
xor    %ebp,%ebp
mov    %rbx,%rdi
mov    $0x180,%edx
xor    %eax,%eax
call   1060 <open@plt>
mov    0x8(%rsp),%rsi
cmp    $0xffffffff,%eax
je     1215 <ytht_smth_reload_badwords+0xb5>
mov    %eax,%ebx
mov    0x10(%rsp),%rdx
mov    %eax,%edi
call   1040 <write@plt>
mov    %ebx,%edi
call   1050 <close@plt>
mov    0x8(%rsp),%rsi
jmp    121a <ytht_smth_reload_badwords+0xba>
mov    $0xffffffff,%ebp
jmp    1222 <ytht_smth_reload_badwords+0xc2>
mov    $0xffffffff,%ebp
mov    %rsi,%rdi
call   1080 <ytht_mgrep_releasepf@plt>
mov    %ebp,%eax
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.pattern_image = type { i32 }
@O_RDONLY = global i32 0
@LOCK_EX = global i32 0
@LOCK_UN = global i32 0
@O_WRONLY = global i32 0
@O_TRUNC = global i32 0
@O_CREAT = global i32 0
define i32 @ytht_smth_reload_badwords(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca %struct.pattern_image*
%8 = alloca i64
store i8* %0, i8** %4
store i8* %1, i8** %5
%9 = load i8*, i8** %4
%10 = load i32, i32* @O_RDONLY
%11 = call i32 (i8*, i32, ...) @open(i8* %9, i32 %10)
store i32 %11, i32* %6
%12 = load i32, i32* %6
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %15
14: ; preds = %2
store i32 -1, i32* %3
br label %47
15: ; preds = %2
%16 = load i32, i32* %6
%17 = load i32, i32* @LOCK_EX
%18 = call i32 @flock(i32 %16, i32 %17)
%19 = load i32, i32* %6
%20 = call i32 @ytht_mgrep_prepf(i32 %19, %struct.pattern_image** %7, i64* %8)
%21 = load i32, i32* %6
%22 = load i32, i32* @LOCK_UN
%23 = call i32 @flock(i32 %21, i32 %22)
%24 = load i32, i32* %6
%25 = call i32 @close(i32 %24)
%26 = load i8*, i8** %5
%27 = load i32, i32* @O_WRONLY
%28 = load i32, i32* @O_TRUNC
%29 = or i32 %27, %28
%30 = load i32, i32* @O_CREAT
%31 = or i32 %29, %30
%32 = call i32 (i8*, i32, ...) @open(i8* %26, i32 %31, i32 384)
store i32 %32, i32* %6
%33 = load i32, i32* %6
%34 = icmp eq i32 %33, -1
br i1 %34, label %35, label %38
35: ; preds = %15
%36 = load %struct.pattern_image*, %struct.pattern_image** %7
%37 = call i32 @ytht_mgrep_releasepf(%struct.pattern_image* %36)
store i32 -1, i32* %3
br label %47
38: ; preds = %15
%39 = load i32, i32* %6
%40 = load %struct.pattern_image*, %struct.pattern_image** %7
%41 = load i64, i64* %8
%42 = call i32 @write(i32 %39, %struct.pattern_image* %40, i64 %41)
%43 = load i32, i32* %6
%44 = call i32 @close(i32 %43)
%45 = load %struct.pattern_image*, %struct.pattern_image** %7
%46 = call i32 @ytht_mgrep_releasepf(%struct.pattern_image* %45)
store i32 0, i32* %3
br label %47
47: ; preds = %38, %35, %14
%48 = load i32, i32* %3
ret i32 %48
}

LLVM IR (-O2):
%struct.pattern_image = type { i32 }
@O_RDONLY = global i32 0
@LOCK_EX = global i32 0
@LOCK_UN = global i32 0
@O_WRONLY = global i32 0
@O_TRUNC = global i32 0
@O_CREAT = global i32 0
define i32 @ytht_smth_reload_badwords(i8* nocapture %0, i8* nocapture %1) {
%3 = alloca %struct.pattern_image*
%4 = alloca i64
%5 = bitcast %struct.pattern_image** %3 to i8*
%6 = bitcast i64* %4 to i8*
%7 = load i32, i32* @O_RDONLY
%8 = tail call i32 (i8*, i32, ...) @open(i8* %0, i32 %7)
%9 = icmp eq i32 %8, -1
br i1 %9, label %34, label %10
10: ; preds = %2
%11 = load i32, i32* @LOCK_EX
%12 = tail call i32 @flock(i32 %8, i32 %11)
%13 = call i32 @ytht_mgrep_prepf(i32 %8, %struct.pattern_image** %3, i64* %4)
%14 = load i32, i32* @LOCK_UN
%15 = call i32 @flock(i32 %8, i32 %14)
%16 = call i32 @close(i32 %8)
%17 = load i32, i32* @O_WRONLY
%18 = load i32, i32* @O_TRUNC
%19 = or i32 %18, %17
%20 = load i32, i32* @O_CREAT
%21 = or i32 %19, %20
%22 = call i32 (i8*, i32, ...) @open(i8* %1, i32 %21, i32 384)
%23 = icmp eq i32 %22, -1
%24 = load %struct.pattern_image*, %struct.pattern_image** %3
br i1 %23, label %30, label %25
25: ; preds = %10
%26 = load i64, i64* %4
%27 = call i32 @write(i32 %22, %struct.pattern_image* %24, i64 %26)
%28 = call i32 @close(i32 %22)
%29 = load %struct.pattern_image*, %struct.pattern_image** %3
br label %30
30: ; preds = %10, %25
%31 = phi %struct.pattern_image* [ %29, %25 ], [ %24, %10 ]
%32 = phi i32 [ 0, %25 ], [ -1, %10 ]
%33 = call i32 @ytht_mgrep_releasepf(%struct.pattern_image* %31)
br label %34
34: ; preds = %30, %2
%35 = phi i32 [ -1, %2 ], [ %32, %30 ]
ret i32 %35
}