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

/* Variables and functions */
int /*<<< orphan*/ LOG_ERR;
int /*<<< orphan*/ SEEK_CUR;
int /*<<< orphan*/ SIGHUP;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fputc(char, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
int /*<<< orphan*/ kill(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ libamg_process_get_pid(char *);
int /*<<< orphan*/ strlen(char *);
scalar_t__ strstr(char *, char *);
int /*<<< orphan*/ syslog(int /*<<< orphan*/, char *, ...);
int _process_set_inetd_program(int enable, char *prog) {
  FILE *f;
  char buf[256];
  int found = 0;
  pid_t pid;
  f = fopen("/etc/inetd.conf", "r+");
  if (!f) {
    syslog(LOG_ERR, "could not open %s", "/etc/inetd.conf");
    return (-1);
  }
  while ((!feof(f)) && (!found)) {
    fgets(buf, 255, f);
    buf[255] = 0;
    if (strstr(buf, prog)) {
      fseek(f, -strlen(buf), SEEK_CUR);
      fputc(enable ? ' ' : '#', f);
      found = 1;
    }
  }
  fclose(f);
  if (!found) {
    syslog(LOG_ERR, "%s not found in %s", prog, "/etc/inetd.conf");
    return (-1);
  }
  pid = libamg_process_get_pid("inetd");
  if (!pid) {
    syslog(LOG_ERR, "inetd is not running");
    return (-1);
  }
  kill(pid, SIGHUP);
  return 0;
}


x86 assembly (clang, -O0):
<_process_set_inetd_program>:
push   %rbp
mov    %rsp,%rbp
sub    $0x140,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x124(%rbp)
lea    0xe2d(%rip),%rdi
lea    0xe36(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1218 <_process_set_inetd_program+0x68>
mov    0x2dd3(%rip),%rax
mov    (%rax),%edi
lea    0xe15(%rip),%rsi
lea    0xdfb(%rip),%rdx
mov    $0x0,%al
call   1090 <syslog@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1390 <_process_set_inetd_program+0x1e0>
jmp    121d <_process_set_inetd_program+0x6d>
mov    -0x18(%rbp),%rdi
call   1070 <feof@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x129(%rbp)
jne    124b <_process_set_inetd_program+0x9b>
cmpl   $0x0,-0x124(%rbp)
setne  %al
xor    $0xff,%al
mov    %al,-0x129(%rbp)
mov    -0x129(%rbp),%al
test   $0x1,%al
jne    125e <_process_set_inetd_program+0xae>
jmp    12ef <_process_set_inetd_program+0x13f>
lea    -0x120(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0xff,%esi
call   1060 <fgets@plt>
movb   $0x0,-0x21(%rbp)
lea    -0x120(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   10d0 <strstr@plt>
cmp    $0x0,%rax
je     12ea <_process_set_inetd_program+0x13a>
mov    -0x18(%rbp),%rax
mov    %rax,-0x138(%rbp)
lea    -0x120(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x138(%rbp),%rdi
xor    %esi,%esi
sub    %eax,%esi
mov    0x2d26(%rip),%rax
mov    (%rax),%edx
call   10b0 <fseek@plt>
mov    -0x8(%rbp),%edx
mov    $0x23,%eax
mov    $0x20,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
mov    -0x18(%rbp),%rsi
movsbl %al,%edi
call   1050 <fputc@plt>
movl   $0x1,-0x124(%rbp)
jmp    121d <_process_set_inetd_program+0x6d>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
cmpl   $0x0,-0x124(%rbp)
jne    1333 <_process_set_inetd_program+0x183>
mov    0x2cbc(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xd0c(%rip),%rsi
lea    0xce0(%rip),%rcx
mov    $0x0,%al
call   1090 <syslog@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1390 <_process_set_inetd_program+0x1e0>
lea    0xcfe(%rip),%rdi
call   10a0 <libamg_process_get_pid@plt>
mov    %eax,-0x128(%rbp)
cmpl   $0x0,-0x128(%rbp)
jne    1375 <_process_set_inetd_program+0x1c5>
mov    0x2c6f(%rip),%rax
mov    (%rax),%edi
lea    0xcdc(%rip),%rsi
mov    $0x0,%al
call   1090 <syslog@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1390 <_process_set_inetd_program+0x1e0>
mov    -0x128(%rbp),%edi
mov    0x2c6e(%rip),%rax
mov    (%rax),%esi
call   1080 <kill@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x140,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_process_set_inetd_program>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x108,%rsp
mov    %rsi,%r14
mov    %edi,%ebp
lea    0xe33(%rip),%rdi
lea    0xe3c(%rip),%rsi
call   10c0 <fopen@plt>
test   %rax,%rax
je     1218 <_process_set_inetd_program+0x68>
mov    %rax,%rbx
mov    %rax,%rdi
call   1070 <feof@plt>
test   %eax,%eax
je     124d <_process_set_inetd_program+0x9d>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    0x2dcc(%rip),%rax
mov    (%rax),%edi
lea    0xe20(%rip),%rsi
lea    0xdf4(%rip),%rcx
mov    %r14,%rdx
xor    %eax,%eax
call   1090 <syslog@plt>
jmp    1236 <_process_set_inetd_program+0x86>
mov    0x2da9(%rip),%rax
mov    (%rax),%edi
lea    0xdeb(%rip),%rsi
lea    0xdd1(%rip),%rdx
xor    %eax,%eax
call   1090 <syslog@plt>
mov    $0xffffffff,%eax
add    $0x108,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %eax,%eax
test   %ebp,%ebp
sete   %al
lea    (%rax,%rax,2),%eax
add    $0x20,%eax
mov    %rsp,%r15
movsbl %al,%r12d
jmp    12ab <_process_set_inetd_program+0xfb>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r15,%rdi
call   1040 <strlen@plt>
neg    %eax
mov    0x2d5f(%rip),%rcx
mov    (%rcx),%edx
mov    %rbx,%rdi
mov    %eax,%esi
call   10b0 <fseek@plt>
mov    %r12d,%edi
mov    %rbx,%rsi
call   1050 <fputc@plt>
mov    $0x1,%r13d
mov    %rbx,%rdi
call   1070 <feof@plt>
or     %r13d,%eax
jne    12db <_process_set_inetd_program+0x12b>
mov    %r15,%rdi
mov    $0xff,%esi
mov    %rbx,%rdx
call   1060 <fgets@plt>
movb   $0x0,0xff(%rsp)
mov    %r15,%rdi
mov    %r14,%rsi
call   10d0 <strstr@plt>
mov    %rax,%rbp
test   %rax,%rax
jne    1270 <_process_set_inetd_program+0xc0>
xor    %r13d,%r13d
jmp    129e <_process_set_inetd_program+0xee>
mov    %rbx,%rdi
call   1030 <fclose@plt>
test   %rbp,%rbp
je     11f5 <_process_set_inetd_program+0x45>
lea    0xd45(%rip),%rdi
call   10a0 <libamg_process_get_pid@plt>
test   %eax,%eax
je     1313 <_process_set_inetd_program+0x163>
mov    0x2ced(%rip),%rcx
mov    (%rcx),%esi
mov    %eax,%edi
call   1080 <kill@plt>
xor    %eax,%eax
jmp    123b <_process_set_inetd_program+0x8b>
mov    0x2cae(%rip),%rax
mov    (%rax),%edi
lea    0xd1b(%rip),%rsi
xor    %eax,%eax
call   1090 <syslog@plt>
jmp    1236 <_process_set_inetd_program+0x86>

LLVM IR (-O0):
@.str = [16 x i8] c"/etc/inetd.conf\00"
@.str.1 = [3 x i8] c"r+\00"
@LOG_ERR = global i32 0
@.str.2 = [18 x i8] c"could not open %s\00"
@SEEK_CUR = global i32 0
@.str.3 = [19 x i8] c"%s not found in %s\00"
@.str.4 = [6 x i8] c"inetd\00"
@.str.5 = [21 x i8] c"inetd is not running\00"
@SIGHUP = global i32 0
define i32 @_process_set_inetd_program(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca [256 x i8]
%8 = alloca i32
%9 = alloca i32
store i32 %0, i32* %4
store i8* %1, i8** %5
store i32 0, i32* %8
%10 = call i32* @fopen(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %10, i32** %6
%11 = load i32*, i32** %6
%12 = icmp ne i32* %11, null
br i1 %12, label %16, label %13
13: ; preds = %2
%14 = load i32, i32* @LOG_ERR
%15 = call i32 (i32, i8*, ...) @syslog(i32 %14, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %71
16: ; preds = %2
br label %17
17: ; preds = %50, %16
%18 = load i32*, i32** %6
%19 = call i32 @feof(i32* %18)
%20 = icmp ne i32 %19, 0
br i1 %20, label %25, label %21
21: ; preds = %17
%22 = load i32, i32* %8
%23 = icmp ne i32 %22, 0
%24 = xor i1 %23, true
br label %25
25: ; preds = %21, %17
%26 = phi i1 [ false, %17 ], [ %24, %21 ]
br i1 %26, label %27, label %51
27: ; preds = %25
%28 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%29 = load i32*, i32** %6
%30 = call i32 @fgets(i8* %28, i32 255, i32* %29)
%31 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 255
store i8 0, i8* %31
%32 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%33 = load i8*, i8** %5
%34 = call i64 @strstr(i8* %32, i8* %33)
%35 = icmp ne i64 %34, 0
br i1 %35, label %36, label %50
36: ; preds = %27
%37 = load i32*, i32** %6
%38 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%39 = call i32 @strlen(i8* %38)
%40 = sub nsw i32 0, %39
%41 = load i32, i32* @SEEK_CUR
%42 = call i32 @fseek(i32* %37, i32 %40, i32 %41)
%43 = load i32, i32* %4
%44 = icmp ne i32 %43, 0
%45 = zext i1 %44 to i64
%46 = select i1 %44, i32 32, i32 35
%47 = trunc i32 %46 to i8
%48 = load i32*, i32** %6
%49 = call i32 @fputc(i8 signext %47, i32* %48)
store i32 1, i32* %8
br label %50
50: ; preds = %36, %27
br label %17
51: ; preds = %25
%52 = load i32*, i32** %6
%53 = call i32 @fclose(i32* %52)
%54 = load i32, i32* %8
%55 = icmp ne i32 %54, 0
br i1 %55, label %60, label %56
56: ; preds = %51
%57 = load i32, i32* @LOG_ERR
%58 = load i8*, i8** %5
%59 = call i32 (i32, i8*, ...) @syslog(i32 %57, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i8* %58, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %71
60: ; preds = %51
%61 = call i32 @libamg_process_get_pid(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
store i32 %61, i32* %9
%62 = load i32, i32* %9
%63 = icmp ne i32 %62, 0
br i1 %63, label %67, label %64
64: ; preds = %60
%65 = load i32, i32* @LOG_ERR
%66 = call i32 (i32, i8*, ...) @syslog(i32 %65, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0))
store i32 -1, i32* %3
br label %71
67: ; preds = %60
%68 = load i32, i32* %9
%69 = load i32, i32* @SIGHUP
%70 = call i32 @kill(i32 %68, i32 %69)
store i32 0, i32* %3
br label %71
71: ; preds = %67, %64, %56, %13
%72 = load i32, i32* %3
ret i32 %72
}

LLVM IR (-O2):
@.str = [16 x i8] c"/etc/inetd.conf\00"
@.str.1 = [3 x i8] c"r+\00"
@LOG_ERR = global i32 0
@.str.2 = [18 x i8] c"could not open %s\00"
@SEEK_CUR = global i32 0
@.str.3 = [19 x i8] c"%s not found in %s\00"
@.str.4 = [6 x i8] c"inetd\00"
@.str.5 = [21 x i8] c"inetd is not running\00"
@SIGHUP = global i32 0
define i32 @_process_set_inetd_program(i32 %0, i8* %1) {
%3 = alloca [256 x i8]
%4 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%5 = tail call i32* @fopen(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %16, label %7
7: ; preds = %2
%8 = call i32 @feof(i32* %5)
%9 = icmp eq i32 %8, 0
br i1 %9, label %12, label %10
10: ; preds = %7
%11 = call i32 @fclose(i32* %5)
br label %36
12: ; preds = %7
%13 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 255
%14 = icmp eq i32 %0, 0
%15 = select i1 %14, i8 35, i8 32
br label %19
16: ; preds = %2
%17 = load i32, i32* @LOG_ERR
%18 = tail call i32 (i32, i8*, ...) @syslog(i32 %17, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
br label %48
19: ; preds = %12, %29
%20 = call i32 @fgets(i8* %4, i32 255, i32* %5)
store i8 0, i8* %13
%21 = call i64 @strstr(i8* %4, i8* %1)
%22 = icmp eq i64 %21, 0
br i1 %22, label %29, label %23
23: ; preds = %19
%24 = call i32 @strlen(i8* %4)
%25 = sub nsw i32 0, %24
%26 = load i32, i32* @SEEK_CUR
%27 = call i32 @fseek(i32* %5, i32 %25, i32 %26)
%28 = call i32 @fputc(i8 signext %15, i32* %5)
br label %29
29: ; preds = %23, %19
%30 = phi i32 [ 1, %23 ], [ 0, %19 ]
%31 = call i32 @feof(i32* %5)
%32 = or i32 %31, %30
%33 = icmp eq i32 %32, 0
br i1 %33, label %19, label %34
34: ; preds = %29
%35 = call i32 @fclose(i32* %5)
br i1 %22, label %36, label %39
36: ; preds = %10, %34
%37 = load i32, i32* @LOG_ERR
%38 = call i32 (i32, i8*, ...) @syslog(i32 %37, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i8* %1, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
br label %48
39: ; preds = %34
%40 = call i32 @libamg_process_get_pid(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
%41 = icmp eq i32 %40, 0
br i1 %41, label %42, label %45
42: ; preds = %39
%43 = load i32, i32* @LOG_ERR
%44 = call i32 (i32, i8*, ...) @syslog(i32 %43, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0))
br label %48
45: ; preds = %39
%46 = load i32, i32* @SIGHUP
%47 = call i32 @kill(i32 %40, i32 %46)
br label %48
48: ; preds = %45, %42, %36, %16
%49 = phi i32 [ 0, %45 ], [ -1, %42 ], [ -1, %36 ], [ -1, %16 ]
ret i32 %49
}