#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 int32_t;

/* Variables and functions */
int /*<<< orphan*/ SIGQUIT;
int /*<<< orphan*/ SIGTERM;
int /*<<< orphan*/ errno;
int get_pid(char const *);
int kill(int, int /*<<< orphan*/);
int /*<<< orphan*/ logger_stderr(char *, char const *, int /*<<< orphan*/, ...);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
int /*<<< orphan*/ unlink(char const *);
int signal_process(char *signal, const char *pidfile) {
  int32_t pid;
  pid = get_pid(pidfile);
  if (pid == -1) {
    logger_stderr("open \"%s\" failed (%d: %s)", pidfile, errno,
                  strerror(errno));
    return 1;
  }
  if (strcmp(signal, "stop") == 0) {
    if (kill(pid, SIGTERM) != -1) {
      unlink(pidfile);
      return 0;
    } else {
      logger_stderr("stop failed (%d: %s)", errno, strerror(errno));
    }
  }
  if (strcmp(signal, "quit") == 0) {
    if (kill(pid, SIGQUIT) != -1) {
      return 0;
    } else {
      logger_stderr("quit failed (%d: %s)", errno, strerror(errno));
    }
  }
  return 1;
}


x86 assembly (clang, -O0):
<signal_process>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1080 <get_pid@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    11cb <signal_process+0x6b>
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    0x2e3b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    0x2e2f(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    -0x28(%rbp),%rsi
mov    -0x20(%rbp),%edx
mov    %eax,%ecx
lea    0xe48(%rip),%rdi
mov    $0x0,%al
call   1040 <logger_stderr@plt>
movl   $0x1,-0x4(%rbp)
jmp    12c5 <signal_process+0x165>
mov    -0x10(%rbp),%rdi
lea    0xe44(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    1249 <signal_process+0xe9>
mov    -0x1c(%rbp),%edi
mov    0x2df9(%rip),%rax
mov    (%rax),%esi
call   1060 <kill@plt>
cmp    $0xffffffff,%eax
je     1214 <signal_process+0xb4>
mov    -0x18(%rbp),%rdi
call   1030 <unlink@plt>
movl   $0x0,-0x4(%rbp)
jmp    12c5 <signal_process+0x165>
mov    0x2db5(%rip),%rax
movslq (%rax),%rax
mov    %rax,-0x30(%rbp)
mov    0x2da7(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    -0x30(%rbp),%rsi
mov    %eax,%edx
lea    0xde2(%rip),%rdi
mov    $0x0,%al
call   1040 <logger_stderr@plt>
jmp    1249 <signal_process+0xe9>
mov    -0x10(%rbp),%rdi
lea    0xde0(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    12be <signal_process+0x15e>
mov    -0x1c(%rbp),%edi
mov    0x2d73(%rip),%rax
mov    (%rax),%esi
call   1060 <kill@plt>
cmp    $0xffffffff,%eax
je     1289 <signal_process+0x129>
movl   $0x0,-0x4(%rbp)
jmp    12c5 <signal_process+0x165>
mov    0x2d40(%rip),%rax
movslq (%rax),%rax
mov    %rax,-0x38(%rbp)
mov    0x2d32(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    -0x38(%rbp),%rsi
mov    %eax,%edx
lea    0xd87(%rip),%rdi
mov    $0x0,%al
call   1040 <logger_stderr@plt>
jmp    12be <signal_process+0x15e>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<signal_process>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%rbx
mov    %rdi,%r14
mov    %rsi,%rdi
call   1080 <get_pid@plt>
cmp    $0xffffffff,%eax
je     11f2 <signal_process+0x92>
mov    %eax,%ebp
lea    0xe9a(%rip),%rsi
mov    %r14,%rdi
call   1050 <strcmp@plt>
test   %rax,%rax
je     121e <signal_process+0xbe>
lea    0xe9c(%rip),%rsi
mov    %r14,%rdi
call   1050 <strcmp@plt>
mov    %rax,%rcx
mov    $0x1,%eax
test   %rcx,%rcx
jne    123d <signal_process+0xdd>
mov    0x2e28(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
call   1060 <kill@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0xffffffff,%ecx
jne    123d <signal_process+0xdd>
mov    0x2dff(%rip),%rax
mov    (%rax),%eax
movslq %eax,%rbx
mov    %ebx,%edi
call   1070 <strerror@plt>
lea    0xe55(%rip),%rdi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1040 <logger_stderr@plt>
jmp    1217 <signal_process+0xb7>
mov    0x2dd7(%rip),%rax
mov    (%rax),%ebp
mov    %ebp,%edi
call   1070 <strerror@plt>
lea    0xdf7(%rip),%rdi
mov    %rbx,%rsi
mov    %ebp,%edx
mov    %eax,%ecx
xor    %eax,%eax
call   1040 <logger_stderr@plt>
mov    $0x1,%eax
jmp    123d <signal_process+0xdd>
mov    0x2dc3(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
call   1060 <kill@plt>
cmp    $0xffffffff,%eax
je     1242 <signal_process+0xe2>
mov    %rbx,%rdi
call   1030 <unlink@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    0x2d87(%rip),%rax
mov    (%rax),%eax
movslq %eax,%rbx
mov    %ebx,%edi
call   1070 <strerror@plt>
lea    0xdc3(%rip),%rdi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1040 <logger_stderr@plt>
jmp    1191 <signal_process+0x31>

LLVM IR (-O0):
@.str = [26 x i8] c"open \22%s\22 failed (%d: %s)\00"
@errno = global i32 0
@.str.1 = [5 x i8] c"stop\00"
@SIGTERM = global i32 0
@.str.2 = [21 x i8] c"stop failed (%d: %s)\00"
@.str.3 = [5 x i8] c"quit\00"
@SIGQUIT = global i32 0
@.str.4 = [21 x i8] c"quit failed (%d: %s)\00"
define i32 @signal_process(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%7 = load i8*, i8** %5
%8 = call i32 @get_pid(i8* %7)
store i32 %8, i32* %6
%9 = load i32, i32* %6
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %17
11: ; preds = %2
%12 = load i8*, i8** %5
%13 = load i32, i32* @errno
%14 = load i32, i32* @errno
%15 = call i32 @strerror(i32 %14)
%16 = call i32 (i8*, i8*, i32, ...) @logger_stderr(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i8* %12, i32 %13, i32 %15)
store i32 1, i32* %3
br label %56
17: ; preds = %2
%18 = load i8*, i8** %4
%19 = call i64 @strcmp(i8* %18, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %37
21: ; preds = %17
%22 = load i32, i32* %6
%23 = load i32, i32* @SIGTERM
%24 = call i32 @kill(i32 %22, i32 %23)
%25 = icmp ne i32 %24, -1
br i1 %25, label %26, label %29
26: ; preds = %21
%27 = load i8*, i8** %5
%28 = call i32 @unlink(i8* %27)
store i32 0, i32* %3
br label %56
29: ; preds = %21
%30 = load i32, i32* @errno
%31 = sext i32 %30 to i64
%32 = inttoptr i64 %31 to i8*
%33 = load i32, i32* @errno
%34 = call i32 @strerror(i32 %33)
%35 = call i32 (i8*, i8*, i32, ...) @logger_stderr(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i8* %32, i32 %34)
br label %36
36: ; preds = %29
br label %37
37: ; preds = %36, %17
%38 = load i8*, i8** %4
%39 = call i64 @strcmp(i8* %38, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%40 = icmp eq i64 %39, 0
br i1 %40, label %41, label %55
41: ; preds = %37
%42 = load i32, i32* %6
%43 = load i32, i32* @SIGQUIT
%44 = call i32 @kill(i32 %42, i32 %43)
%45 = icmp ne i32 %44, -1
br i1 %45, label %46, label %47
46: ; preds = %41
store i32 0, i32* %3
br label %56
47: ; preds = %41
%48 = load i32, i32* @errno
%49 = sext i32 %48 to i64
%50 = inttoptr i64 %49 to i8*
%51 = load i32, i32* @errno
%52 = call i32 @strerror(i32 %51)
%53 = call i32 (i8*, i8*, i32, ...) @logger_stderr(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0), i8* %50, i32 %52)
br label %54
54: ; preds = %47
br label %55
55: ; preds = %54, %37
store i32 1, i32* %3
br label %56
56: ; preds = %55, %46, %26, %11
%57 = load i32, i32* %3
ret i32 %57
}

LLVM IR (-O2):
@.str = [26 x i8] c"open \22%s\22 failed (%d: %s)\00"
@errno = global i32 0
@.str.1 = [5 x i8] c"stop\00"
@SIGTERM = global i32 0
@.str.2 = [21 x i8] c"stop failed (%d: %s)\00"
@.str.3 = [5 x i8] c"quit\00"
@SIGQUIT = global i32 0
@.str.4 = [21 x i8] c"quit failed (%d: %s)\00"
define i32 @signal_process(i8* %0, i8* %1) {
%3 = tail call i32 @get_pid(i8* %1)
%4 = icmp eq i32 %3, -1
br i1 %4, label %5, label %9
5: ; preds = %2
%6 = load i32, i32* @errno
%7 = tail call i32 @strerror(i32 %6)
%8 = tail call i32 (i8*, i8*, i32, ...) @logger_stderr(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i8* %1, i32 %6, i32 %7)
br label %37
9: ; preds = %2
%10 = tail call i64 @strcmp(i8* %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %24
12: ; preds = %9
%13 = load i32, i32* @SIGTERM
%14 = tail call i32 @kill(i32 %3, i32 %13)
%15 = icmp eq i32 %14, -1
br i1 %15, label %18, label %16
16: ; preds = %12
%17 = tail call i32 @unlink(i8* %1)
br label %37
18: ; preds = %12
%19 = load i32, i32* @errno
%20 = sext i32 %19 to i64
%21 = inttoptr i64 %20 to i8*
%22 = tail call i32 @strerror(i32 %19)
%23 = tail call i32 (i8*, i8*, i32, ...) @logger_stderr(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i8* %21, i32 %22)
br label %24
24: ; preds = %18, %9
%25 = tail call i64 @strcmp(i8* %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%26 = icmp eq i64 %25, 0
br i1 %26, label %27, label %37
27: ; preds = %24
%28 = load i32, i32* @SIGQUIT
%29 = tail call i32 @kill(i32 %3, i32 %28)
%30 = icmp eq i32 %29, -1
br i1 %30, label %31, label %37
31: ; preds = %27
%32 = load i32, i32* @errno
%33 = sext i32 %32 to i64
%34 = inttoptr i64 %33 to i8*
%35 = tail call i32 @strerror(i32 %32)
%36 = tail call i32 (i8*, i8*, i32, ...) @logger_stderr(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0), i8* %34, i32 %35)
br label %37
37: ; preds = %24, %31, %27, %16, %5
%38 = phi i32 [ 1, %5 ], [ 0, %16 ], [ 0, %27 ], [ 1, %31 ], [ 1, %24 ]
ret i32 %38
}