#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;
};
typedef int /*<<< orphan*/ st;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
scalar_t__ EOF;
int cfg_value_del(int /*<<< orphan*/ *, int /*<<< orphan*/ *, char const *,
                  char const *, char, int);
scalar_t__ chmod(char const *, int /*<<< orphan*/);
int /*<<< orphan*/ close(int);
scalar_t__ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fdopen(int, char *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ memset(struct stat *, int /*<<< orphan*/, int);
int mkstemp(char *);
scalar_t__ rename(char *, char const *);
scalar_t__ stat(char const *, struct stat *);
int /*<<< orphan*/ unlink(char *);
int cfg_file_del(const char *file, const char *keyword, const char *value) {
  FILE *fold, *ftmp;
  int tmpfd;
  int error = 0;
  struct stat st;
  char template[] = "/etc/dibbler.XXXXXX";
  if (-1 == (tmpfd = mkstemp(template)))
    return (-10);
  if (NULL == (ftmp = fdopen(tmpfd, "w"))) {
    unlink(template);
    close(tmpfd);
    return (-10);
  }
  if (!(fold = fopen(file, "r"))) {
    unlink(template);
    fclose(ftmp);
    return (-10);
  }
  error = cfg_value_del(fold, ftmp, keyword, value, '#', 1);
  if (EOF == fclose(fold))
    error = -10;
  if (EOF == fclose(ftmp))
    error = -10;
  if (error == 0) {
    memset(&st, 0, sizeof(st));
    if (stat(file, &st) || rename(template, file) || chmod(file, st.st_mode))
      error = -10;
  }
  return (error);
}


x86 assembly (clang, -O0):
<cfg_file_del>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
movl   $0x0,-0x38(%rbp)
mov    0xe2e(%rip),%rax
mov    %rax,-0x60(%rbp)
mov    0xe2b(%rip),%rax
mov    %rax,-0x58(%rbp)
mov    0xe29(%rip),%eax
mov    %eax,-0x50(%rbp)
lea    -0x60(%rbp),%rdi
call   1090 <mkstemp@plt>
mov    %eax,%ecx
mov    %ecx,-0x34(%rbp)
mov    $0xffffffff,%eax
cmp    %ecx,%eax
jne    1211 <cfg_file_del+0x61>
movl   $0xfffffff6,-0x4(%rbp)
jmp    137b <cfg_file_del+0x1cb>
mov    -0x34(%rbp),%edi
lea    0xdf9(%rip),%rsi
call   10a0 <fdopen@plt>
mov    %rax,%rcx
mov    %rcx,-0x30(%rbp)
xor    %eax,%eax
cmp    %rcx,%rax
jne    124f <cfg_file_del+0x9f>
lea    -0x60(%rbp),%rdi
call   1030 <unlink@plt>
mov    -0x34(%rbp),%edi
call   1060 <close@plt>
movl   $0xfffffff6,-0x4(%rbp)
jmp    137b <cfg_file_del+0x1cb>
mov    -0x10(%rbp),%rdi
lea    0xdbc(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    128b <cfg_file_del+0xdb>
lea    -0x60(%rbp),%rdi
call   1030 <unlink@plt>
mov    -0x30(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0xfffffff6,-0x4(%rbp)
jmp    137b <cfg_file_del+0x1cb>
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    $0x23,%r8d
mov    $0x1,%r9d
call   1080 <cfg_value_del@plt>
mov    %eax,-0x38(%rbp)
mov    0x2d32(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x68(%rbp)
mov    -0x28(%rbp),%rdi
call   1040 <fclose@plt>
mov    %rax,%rcx
mov    -0x68(%rbp),%rax
cmp    %rcx,%rax
jne    12dd <cfg_file_del+0x12d>
movl   $0xfffffff6,-0x38(%rbp)
mov    0x2d04(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x70(%rbp)
mov    -0x30(%rbp),%rdi
call   1040 <fclose@plt>
mov    %rax,%rcx
mov    -0x70(%rbp),%rax
cmp    %rcx,%rax
jne    130b <cfg_file_del+0x15b>
movl   $0xfffffff6,-0x38(%rbp)
cmpl   $0x0,-0x38(%rbp)
jne    1375 <cfg_file_del+0x1c5>
lea    -0x40(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1050 <memset@plt>
mov    -0x10(%rbp),%rdi
lea    -0x40(%rbp),%rsi
call   1070 <stat@plt>
cmp    $0x0,%rax
jne    1369 <cfg_file_del+0x1b9>
lea    -0x60(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   10d0 <rename@plt>
cmp    $0x0,%rax
jne    1369 <cfg_file_del+0x1b9>
mov    -0x10(%rbp),%rdi
mov    -0x40(%rbp),%esi
call   10b0 <chmod@plt>
cmp    $0x0,%rax
je     1370 <cfg_file_del+0x1c0>
movl   $0xfffffff6,-0x38(%rbp)
jmp    1375 <cfg_file_del+0x1c5>
mov    -0x38(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cfg_file_del>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rdx,%r15
mov    %rsi,%r12
mov    %rdi,%r14
movaps 0xe32(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movl   $0x585858,0x20(%rsp)
lea    0x10(%rsp),%rdi
call   1090 <mkstemp@plt>
mov    $0xfffffff6,%ebp
cmp    $0xffffffff,%eax
je     12f1 <cfg_file_del+0x141>
mov    %eax,%ebx
lea    0xe18(%rip),%rsi
mov    %eax,%edi
call   10a0 <fdopen@plt>
test   %rax,%rax
je     12cc <cfg_file_del+0x11c>
mov    %rax,%r13
lea    0xe00(%rip),%rsi
mov    %r14,%rdi
call   10c0 <fopen@plt>
test   %rax,%rax
je     12df <cfg_file_del+0x12f>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r13,%rsi
mov    %r12,%rdx
mov    %r15,%rcx
mov    $0x23,%r8d
mov    $0x1,%r9d
call   1080 <cfg_value_del@plt>
mov    %eax,%ebp
mov    0x2d98(%rip),%r15
mov    (%r15),%r12
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    %rax,%rbx
mov    (%r15),%r15
mov    %r13,%rdi
call   1040 <fclose@plt>
cmp    %rbx,%r12
mov    $0xfffffff6,%ecx
cmove  %ecx,%ebp
cmp    %rax,%r15
cmove  %ecx,%ebp
test   %ebp,%ebp
jne    12f1 <cfg_file_del+0x141>
lea    0x8(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1050 <memset@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1070 <stat@plt>
test   %rax,%rax
jne    12c5 <cfg_file_del+0x115>
lea    0x10(%rsp),%rdi
mov    %r14,%rsi
call   10d0 <rename@plt>
test   %rax,%rax
jne    12c5 <cfg_file_del+0x115>
mov    0x8(%rsp),%esi
mov    %r14,%rdi
call   10b0 <chmod@plt>
test   %rax,%rax
je     1302 <cfg_file_del+0x152>
mov    $0xfffffff6,%ebp
jmp    12f1 <cfg_file_del+0x141>
lea    0x10(%rsp),%rdi
call   1030 <unlink@plt>
mov    %ebx,%edi
call   1060 <close@plt>
jmp    12f1 <cfg_file_del+0x141>
lea    0x10(%rsp),%rdi
call   1030 <unlink@plt>
mov    %r13,%rdi
call   1040 <fclose@plt>
mov    %ebp,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %ebp,%ebp
jmp    12f1 <cfg_file_del+0x141>

LLVM IR (-O0):
%struct.stat = type { i32 }
@__const.cfg_file_del.template = [20 x i8] c"/etc/dibbler.XXXXXX\00"
@.str = [2 x i8] c"w\00"
@.str.1 = [2 x i8] c"r\00"
@EOF = global i64 0
define i32 @cfg_file_del(i8* %0, i8* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca i32
%11 = alloca i32
%12 = alloca %struct.stat
%13 = alloca [20 x i8]
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
store i32 0, i32* %11
%14 = bitcast [20 x i8]* %13 to i8*
%15 = getelementptr inbounds [20 x i8], [20 x i8]* %13, i64 0, i64 0
%16 = call i32 @mkstemp(i8* %15)
store i32 %16, i32* %10
%17 = icmp eq i32 -1, %16
br i1 %17, label %18, label %19
18: ; preds = %3
store i32 -10, i32* %4
br label %77
19: ; preds = %3
%20 = load i32, i32* %10
%21 = call i32* @fdopen(i32 %20, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %21, i32** %9
%22 = icmp eq i32* null, %21
br i1 %22, label %23, label %28
23: ; preds = %19
%24 = getelementptr inbounds [20 x i8], [20 x i8]* %13, i64 0, i64 0
%25 = call i32 @unlink(i8* %24)
%26 = load i32, i32* %10
%27 = call i32 @close(i32 %26)
store i32 -10, i32* %4
br label %77
28: ; preds = %19
%29 = load i8*, i8** %5
%30 = call i32* @fopen(i8* %29, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %30, i32** %8
%31 = icmp ne i32* %30, null
br i1 %31, label %37, label %32
32: ; preds = %28
%33 = getelementptr inbounds [20 x i8], [20 x i8]* %13, i64 0, i64 0
%34 = call i32 @unlink(i8* %33)
%35 = load i32*, i32** %9
%36 = call i64 @fclose(i32* %35)
store i32 -10, i32* %4
br label %77
37: ; preds = %28
%38 = load i32*, i32** %8
%39 = load i32*, i32** %9
%40 = load i8*, i8** %6
%41 = load i8*, i8** %7
%42 = call i32 @cfg_value_del(i32* %38, i32* %39, i8* %40, i8* %41, i8 signext 35, i32 1)
store i32 %42, i32* %11
%43 = load i64, i64* @EOF
%44 = load i32*, i32** %8
%45 = call i64 @fclose(i32* %44)
%46 = icmp eq i64 %43, %45
br i1 %46, label %47, label %48
47: ; preds = %37
store i32 -10, i32* %11
br label %48
48: ; preds = %47, %37
%49 = load i64, i64* @EOF
%50 = load i32*, i32** %9
%51 = call i64 @fclose(i32* %50)
%52 = icmp eq i64 %49, %51
br i1 %52, label %53, label %54
53: ; preds = %48
store i32 -10, i32* %11
br label %54
54: ; preds = %53, %48
%55 = load i32, i32* %11
%56 = icmp eq i32 %55, 0
br i1 %56, label %57, label %75
57: ; preds = %54
%58 = call i32 @memset(%struct.stat* %12, i32 0, i32 4)
%59 = load i8*, i8** %5
%60 = call i64 @stat(i8* %59, %struct.stat* %12)
%61 = icmp ne i64 %60, 0
br i1 %61, label %73, label %62
62: ; preds = %57
%63 = getelementptr inbounds [20 x i8], [20 x i8]* %13, i64 0, i64 0
%64 = load i8*, i8** %5
%65 = call i64 @rename(i8* %63, i8* %64)
%66 = icmp ne i64 %65, 0
br i1 %66, label %73, label %67
67: ; preds = %62
%68 = load i8*, i8** %5
%69 = getelementptr inbounds %struct.stat, %struct.stat* %12, i32 0, i32 0
%70 = load i32, i32* %69
%71 = call i64 @chmod(i8* %68, i32 %70)
%72 = icmp ne i64 %71, 0
br i1 %72, label %73, label %74
73: ; preds = %67, %62, %57
store i32 -10, i32* %11
br label %74
74: ; preds = %73, %67
br label %75
75: ; preds = %74, %54
%76 = load i32, i32* %11
store i32 %76, i32* %4
br label %77
77: ; preds = %75, %32, %23, %18
%78 = load i32, i32* %4
ret i32 %78
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@__const.cfg_file_del.template = [20 x i8] c"/etc/dibbler.XXXXXX\00"
@.str = [2 x i8] c"w\00"
@.str.1 = [2 x i8] c"r\00"
@EOF = global i64 0
define i32 @cfg_file_del(i8* %0, i8* %1, i8* %2) {
%4 = alloca %struct.stat
%5 = alloca [20 x i8]
%6 = bitcast %struct.stat* %4 to i8*
%7 = getelementptr inbounds [20 x i8], [20 x i8]* %5, i64 0, i64 0
%8 = call i32 @mkstemp(i8* %7)
%9 = icmp eq i32 %8, -1
br i1 %9, label %46, label %10
10: ; preds = %3
%11 = call i32* @fdopen(i32 %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %16
13: ; preds = %10
%14 = call i32 @unlink(i8* %7)
%15 = call i32 @close(i32 %8)
br label %46
16: ; preds = %10
%17 = call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%18 = icmp eq i32* %17, null
br i1 %18, label %19, label %22
19: ; preds = %16
%20 = call i32 @unlink(i8* %7)
%21 = call i64 @fclose(i32* %11)
br label %46
22: ; preds = %16
%23 = call i32 @cfg_value_del(i32* %17, i32* %11, i8* %1, i8* %2, i8 signext 35, i32 1)
%24 = load i64, i64* @EOF
%25 = call i64 @fclose(i32* %17)
%26 = icmp eq i64 %24, %25
%27 = load i64, i64* @EOF
%28 = call i64 @fclose(i32* %11)
%29 = icmp eq i64 %27, %28
%30 = select i1 %29, i1 true, i1 %26
%31 = select i1 %30, i32 -10, i32 %23
%32 = icmp eq i32 %31, 0
br i1 %32, label %33, label %46
33: ; preds = %22
%34 = call i32 @memset(%struct.stat* %4, i32 0, i32 4)
%35 = call i64 @stat(i8* %0, %struct.stat* %4)
%36 = icmp eq i64 %35, 0
br i1 %36, label %37, label %45
37: ; preds = %33
%38 = call i64 @rename(i8* %7, i8* %0)
%39 = icmp eq i64 %38, 0
br i1 %39, label %40, label %45
40: ; preds = %37
%41 = getelementptr inbounds %struct.stat, %struct.stat* %4, i64 0, i32 0
%42 = load i32, i32* %41
%43 = call i64 @chmod(i8* %0, i32 %42)
%44 = icmp eq i64 %43, 0
br i1 %44, label %46, label %45
45: ; preds = %40, %37, %33
br label %46
46: ; preds = %22, %45, %40, %3, %19, %13
%47 = phi i32 [ -10, %13 ], [ -10, %19 ], [ -10, %3 ], [ -10, %45 ], [ 0, %40 ], [ %31, %22 ]
ret i32 %47
}