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

/* Variables and functions */
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ stat(char *, struct stat *);
int /*<<< orphan*/ system(char *);
int check_and_set_lock_file(void) {
  char wanpipe_dir[] = "/etc/wanpipe";
  char lock_file[] = "/etc/wanpipe/wpkbd_lock";
  struct stat file_stat;
  if (stat(wanpipe_dir, &file_stat) < 0) {
    printf("wpkbdmon: Error, WANPIPE utilites not installed\n");
    printf("wpkbdmon: Directory not found: %s\n", wanpipe_dir);
    return 1;
  }
  if (stat(lock_file, &file_stat) < 0) {
    system("touch /etc/wanpipe/wpkbd_lock");
  } else {
    printf(
        "\nwpkbdmon: Error, WANPIPE Keyboard Led Monitor already running!\n");
    printf("                 The /etc/wanpipe/wpkbd_lock exits.\n\n");
    return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<check_and_set_lock_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    0xec1(%rip),%rax
mov    %rax,-0x11(%rbp)
mov    0xebf(%rip),%eax
mov    %eax,-0x9(%rbp)
mov    0xeba(%rip),%al
mov    %al,-0x5(%rbp)
mov    0xfa4(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0xfa1(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    0xf9e(%rip),%rax
mov    %rax,-0x20(%rbp)
lea    -0x11(%rbp),%rdi
lea    -0x38(%rbp),%rsi
call   1050 <stat@plt>
cmp    $0x0,%rax
jge    11b9 <check_and_set_lock_file+0x89>
lea    0xe79(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x11(%rbp),%rsi
lea    0xe98(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1210 <check_and_set_lock_file+0xe0>
lea    -0x30(%rbp),%rdi
lea    -0x38(%rbp),%rsi
call   1050 <stat@plt>
cmp    $0x0,%rax
jge    11e1 <check_and_set_lock_file+0xb1>
lea    0xe8a(%rip),%rdi
call   1030 <system@plt>
jmp    1209 <check_and_set_lock_file+0xd9>
lea    0xe97(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xeca(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1210 <check_and_set_lock_file+0xe0>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_and_set_lock_file>:
sub    $0x38,%rsp
movabs $0x657069706e6177,%rax
mov    %rax,0x15(%rsp)
movabs $0x6e61772f6374652f,%rax
77 61 6e
mov    %rax,0x10(%rsp)
movaps 0xf97(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movabs $0x6b636f6c5f6462,%rax
mov    %rax,0x30(%rsp)
lea    0x10(%rsp),%rdi
lea    0x8(%rsp),%rsi
call   1060 <stat@plt>
test   %rax,%rax
js     11bf <check_and_set_lock_file+0x7f>
lea    0x20(%rsp),%rdi
lea    0x8(%rsp),%rsi
call   1060 <stat@plt>
test   %rax,%rax
js     11e8 <check_and_set_lock_file+0xa8>
lea    0xea2(%rip),%rdi
call   1030 <puts@plt>
lea    0xed6(%rip),%rdi
call   1030 <puts@plt>
jmp    11de <check_and_set_lock_file+0x9e>
lea    0xefd(%rip),%rdi
call   1030 <puts@plt>
lea    0xe3b(%rip),%rdi
lea    0x10(%rsp),%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x1,%eax
add    $0x38,%rsp
ret
lea    0xe41(%rip),%rdi
call   1040 <system@plt>
xor    %eax,%eax
add    $0x38,%rsp
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@__const.check_and_set_lock_file.wanpipe_dir = [13 x i8] c"/etc/wanpipe\00"
@__const.check_and_set_lock_file.lock_file = [24 x i8] c"/etc/wanpipe/wpkbd_lock\00"
@.str = [49 x i8] c"wpkbdmon: Error, WANPIPE utilites not installed\0A\00"
@.str.1 = [35 x i8] c"wpkbdmon: Directory not found: %s\0A\00"
@.str.2 = [30 x i8] c"touch /etc/wanpipe/wpkbd_lock\00"
@.str.3 = [65 x i8] c"\0Awpkbdmon: Error, WANPIPE Keyboard Led Monitor already running!\0A\00"
@.str.4 = [54 x i8] c" The /etc/wanpipe/wpkbd_lock exits.\0A\0A\00"
define i32 @check_and_set_lock_file() {
%1 = alloca i32
%2 = alloca [13 x i8]
%3 = alloca [24 x i8]
%4 = alloca %struct.stat
%5 = bitcast [13 x i8]* %2 to i8*
%6 = bitcast [24 x i8]* %3 to i8*
%7 = getelementptr inbounds [13 x i8], [13 x i8]* %2, i64 0, i64 0
%8 = call i64 @stat(i8* %7, %struct.stat* %4)
%9 = icmp slt i64 %8, 0
br i1 %9, label %10, label %14
10: ; preds = %0
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0))
%12 = getelementptr inbounds [13 x i8], [13 x i8]* %2, i64 0, i64 0
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0), i8* %12)
store i32 1, i32* %1
br label %24
14: ; preds = %0
%15 = getelementptr inbounds [24 x i8], [24 x i8]* %3, i64 0, i64 0
%16 = call i64 @stat(i8* %15, %struct.stat* %4)
%17 = icmp slt i64 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %14
%19 = call i32 @system(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0))
br label %23
20: ; preds = %14
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str.3, i64 0, i64 0))
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.4, i64 0, i64 0))
store i32 1, i32* %1
br label %24
23: ; preds = %18
store i32 0, i32* %1
br label %24
24: ; preds = %23, %20, %10
%25 = load i32, i32* %1
ret i32 %25
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@__const.check_and_set_lock_file.wanpipe_dir = [13 x i8] c"/etc/wanpipe\00"
@__const.check_and_set_lock_file.lock_file = [24 x i8] c"/etc/wanpipe/wpkbd_lock\00"
@.str.1 = [35 x i8] c"wpkbdmon: Directory not found: %s\0A\00"
@.str.2 = [30 x i8] c"touch /etc/wanpipe/wpkbd_lock\00"
@str = [64 x i8] c"\0Awpkbdmon: Error, WANPIPE Keyboard Led Monitor already running!\00"
@str.5 = [53 x i8] c" The /etc/wanpipe/wpkbd_lock exits.\0A\00"
@str.6 = [48 x i8] c"wpkbdmon: Error, WANPIPE utilites not installed\00"
define i32 @check_and_set_lock_file() {
%1 = alloca [13 x i8]
%2 = alloca [24 x i8]
%3 = alloca %struct.stat
%4 = getelementptr inbounds [13 x i8], [13 x i8]* %1, i64 0, i64 0
%5 = getelementptr inbounds [24 x i8], [24 x i8]* %2, i64 0, i64 0
%6 = bitcast %struct.stat* %3 to i8*
%7 = call i64 @stat(i8* %4, %struct.stat* %3)
%8 = icmp slt i64 %7, 0
br i1 %8, label %9, label %12
9: ; preds = %0
%10 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([48 x i8], [48 x i8]* @str.6, i64 0, i64 0))
%11 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0), i8* %4)
br label %20
12: ; preds = %0
%13 = call i64 @stat(i8* %5, %struct.stat* %3)
%14 = icmp slt i64 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %12
%16 = call i32 @system(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0))
br label %20
17: ; preds = %12
%18 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([64 x i8], [64 x i8]* @str, i64 0, i64 0))
%19 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([53 x i8], [53 x i8]* @str.5, i64 0, i64 0))
br label %20
20: ; preds = %15, %17, %9
%21 = phi i32 [ 1, %9 ], [ 0, %15 ], [ 1, %17 ]
ret i32 %21
}