#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*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ LOG_ERR;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
scalar_t__ strstr(char *, char *);
int /*<<< orphan*/ syslog(int /*<<< orphan*/, char *, char *);
int libamg_process_check_inetd_program(char *prog) {
  FILE *f;
  char buf[256];
  char *p;
  int found = 0;
  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;
    p = buf;
    if ((*p != '#') && (strstr(buf, prog)))
      found = 1;
  }
  fclose(f);
  return (found);
}


x86 assembly (clang, -O0):
<libamg_process_check_inetd_program>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x12c(%rbp)
lea    0xe80(%rip),%rdi
lea    0xe89(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11c3 <libamg_process_check_inetd_program+0x63>
mov    0x2e36(%rip),%rax
mov    (%rax),%edi
lea    0xe68(%rip),%rsi
lea    0xe4e(%rip),%rdx
call   1060 <syslog@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    127e <libamg_process_check_inetd_program+0x11e>
jmp    11c8 <libamg_process_check_inetd_program+0x68>
mov    -0x18(%rbp),%rdi
call   1050 <feof@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x12d(%rbp)
jne    11f6 <libamg_process_check_inetd_program+0x96>
cmpl   $0x0,-0x12c(%rbp)
setne  %al
xor    $0xff,%al
mov    %al,-0x12d(%rbp)
mov    -0x12d(%rbp),%al
test   $0x1,%al
jne    1209 <libamg_process_check_inetd_program+0xa9>
jmp    126c <libamg_process_check_inetd_program+0x10c>
lea    -0x120(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0xff,%esi
call   1040 <fgets@plt>
movb   $0x0,-0x21(%rbp)
lea    -0x120(%rbp),%rax
mov    %rax,-0x128(%rbp)
mov    -0x128(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x23,%eax
je     1267 <libamg_process_check_inetd_program+0x107>
lea    -0x120(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1080 <strstr@plt>
cmp    $0x0,%rax
je     1267 <libamg_process_check_inetd_program+0x107>
movl   $0x1,-0x12c(%rbp)
jmp    11c8 <libamg_process_check_inetd_program+0x68>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x12c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<libamg_process_check_inetd_program>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x108,%rsp
mov    %rdi,%r14
lea    0xe89(%rip),%rdi
lea    0xe92(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     11a3 <libamg_process_check_inetd_program+0x43>
mov    %rax,%rbx
mov    %rax,%rdi
call   1050 <feof@plt>
xor    %ebp,%ebp
test   %eax,%eax
je     11d4 <libamg_process_check_inetd_program+0x74>
mov    %rbx,%rdi
call   1030 <fclose@plt>
jmp    11c4 <libamg_process_check_inetd_program+0x64>
mov    0x2e2e(%rip),%rax
mov    (%rax),%edi
lea    0xe60(%rip),%rsi
lea    0xe46(%rip),%rdx
call   1060 <syslog@plt>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x108,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %rsp,%r15
jmp    11ec <libamg_process_check_inetd_program+0x8c>
nopl   0x0(%rax)
mov    %rbx,%rdi
call   1050 <feof@plt>
or     %ebp,%eax
jne    1199 <libamg_process_check_inetd_program+0x39>
mov    %r15,%rdi
mov    $0xff,%esi
mov    %rbx,%rdx
call   1040 <fgets@plt>
movb   $0x0,0xff(%rsp)
xor    %ebp,%ebp
cmpb   $0x23,(%rsp)
je     11e0 <libamg_process_check_inetd_program+0x80>
mov    %r15,%rdi
mov    %r14,%rsi
call   1080 <strstr@plt>
xor    %ebp,%ebp
test   %rax,%rax
setne  %bpl
jmp    11e0 <libamg_process_check_inetd_program+0x80>

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"
define i32 @libamg_process_check_inetd_program(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca [256 x i8]
%6 = alloca i8*
%7 = alloca i32
store i8* %0, i8** %3
store i32 0, i32* %7
%8 = 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* %8, i32** %4
%9 = load i32*, i32** %4
%10 = icmp ne i32* %9, null
br i1 %10, label %14, label %11
11: ; preds = %1
%12 = load i32, i32* @LOG_ERR
%13 = call i32 @syslog(i32 %12, 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* %2
br label %46
14: ; preds = %1
br label %15
15: ; preds = %41, %14
%16 = load i32*, i32** %4
%17 = call i32 @feof(i32* %16)
%18 = icmp ne i32 %17, 0
br i1 %18, label %23, label %19
19: ; preds = %15
%20 = load i32, i32* %7
%21 = icmp ne i32 %20, 0
%22 = xor i1 %21, true
br label %23
23: ; preds = %19, %15
%24 = phi i1 [ false, %15 ], [ %22, %19 ]
br i1 %24, label %25, label %42
25: ; preds = %23
%26 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%27 = load i32*, i32** %4
%28 = call i32 @fgets(i8* %26, i32 255, i32* %27)
%29 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 255
store i8 0, i8* %29
%30 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
store i8* %30, i8** %6
%31 = load i8*, i8** %6
%32 = load i8, i8* %31
%33 = sext i8 %32 to i32
%34 = icmp ne i32 %33, 35
br i1 %34, label %35, label %41
35: ; preds = %25
%36 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%37 = load i8*, i8** %3
%38 = call i64 @strstr(i8* %36, i8* %37)
%39 = icmp ne i64 %38, 0
br i1 %39, label %40, label %41
40: ; preds = %35
store i32 1, i32* %7
br label %41
41: ; preds = %40, %35, %25
br label %15
42: ; preds = %23
%43 = load i32*, i32** %4
%44 = call i32 @fclose(i32* %43)
%45 = load i32, i32* %7
store i32 %45, i32* %2
br label %46
46: ; preds = %42, %11
%47 = load i32, i32* %2
ret i32 %47
}

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"
define i32 @libamg_process_check_inetd_program(i8* %0) {
%2 = alloca [256 x i8]
%3 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%4 = 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))
%5 = icmp eq i32* %4, null
br i1 %5, label %11, label %6
6: ; preds = %1
%7 = call i32 @feof(i32* %4)
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %28
9: ; preds = %6
%10 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 255
br label %14
11: ; preds = %1
%12 = load i32, i32* @LOG_ERR
%13 = tail call i32 @syslog(i32 %12, 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 %31
14: ; preds = %9, %22
%15 = call i32 @fgets(i8* %3, i32 255, i32* %4)
store i8 0, i8* %10
%16 = load i8, i8* %3
%17 = icmp eq i8 %16, 35
br i1 %17, label %22, label %18
18: ; preds = %14
%19 = call i64 @strstr(i8* %3, i8* %0)
%20 = icmp ne i64 %19, 0
%21 = zext i1 %20 to i32
br label %22
22: ; preds = %18, %14
%23 = phi i32 [ 0, %14 ], [ %21, %18 ]
%24 = call i32 @feof(i32* %4)
%25 = icmp eq i32 %24, 0
%26 = icmp eq i32 %23, 0
%27 = select i1 %25, i1 %26, i1 false
br i1 %27, label %14, label %28
28: ; preds = %22, %6
%29 = phi i32 [ 0, %6 ], [ %23, %22 ]
%30 = call i32 @fclose(i32* %4)
br label %31
31: ; preds = %28, %11
%32 = phi i32 [ %29, %28 ], [ -1, %11 ]
ret i32 %32
}