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

/* Variables and functions */
char *basename(char *);
char *realpath(char *, int /*<<< orphan*/ *);
scalar_t__ strcmp(char *, char *);
int systemd_is_init() {
  char *path = realpath("/sbin/init", NULL);
  char *base = NULL;
  if (!path)
    return 0;
  base = basename(path);
  if (!base)
    return 0;
  if (strcmp(base, "systemd"))
    return 0;
  return 1;
}


x86 assembly (clang, -O0):
<systemd_is_init>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xec1(%rip),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1050 <realpath@plt>
mov    %rax,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    116b <systemd_is_init+0x3b>
movl   $0x0,-0x4(%rbp)
jmp    11bc <systemd_is_init+0x8c>
mov    -0x10(%rbp),%rdi
call   1040 <basename@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    118f <systemd_is_init+0x5f>
movl   $0x0,-0x4(%rbp)
jmp    11bc <systemd_is_init+0x8c>
mov    -0x18(%rbp),%rdi
lea    0xe71(%rip),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%rax
je     11b5 <systemd_is_init+0x85>
movl   $0x0,-0x4(%rbp)
jmp    11bc <systemd_is_init+0x8c>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<systemd_is_init>:
push   %rbx
lea    0xec8(%rip),%rdi
xor    %ebx,%ebx
xor    %esi,%esi
call   1050 <realpath@plt>
test   %rax,%rax
je     116a <systemd_is_init+0x3a>
mov    %rax,%rdi
call   1040 <basename@plt>
test   %rax,%rax
je     116a <systemd_is_init+0x3a>
lea    0xeb1(%rip),%rsi
mov    %rax,%rdi
call   1030 <strcmp@plt>
xor    %ebx,%ebx
test   %rax,%rax
sete   %bl
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [11 x i8] c"/sbin/init\00"
@.str.1 = [8 x i8] c"systemd\00"
define i32 @systemd_is_init() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i8*
%4 = call i8* @realpath(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32* null)
store i8* %4, i8** %2
store i8* null, i8** %3
%5 = load i8*, i8** %2
%6 = icmp ne i8* %5, null
br i1 %6, label %8, label %7
7: ; preds = %0
store i32 0, i32* %1
br label %20
8: ; preds = %0
%9 = load i8*, i8** %2
%10 = call i8* @basename(i8* %9)
store i8* %10, i8** %3
%11 = load i8*, i8** %3
%12 = icmp ne i8* %11, null
br i1 %12, label %14, label %13
13: ; preds = %8
store i32 0, i32* %1
br label %20
14: ; preds = %8
%15 = load i8*, i8** %3
%16 = call i64 @strcmp(i8* %15, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%17 = icmp ne i64 %16, 0
br i1 %17, label %18, label %19
18: ; preds = %14
store i32 0, i32* %1
br label %20
19: ; preds = %14
store i32 1, i32* %1
br label %20
20: ; preds = %19, %18, %13, %7
%21 = load i32, i32* %1
ret i32 %21
}

LLVM IR (-O2):
@.str = [11 x i8] c"/sbin/init\00"
@.str.1 = [8 x i8] c"systemd\00"
define i32 @systemd_is_init() {
%1 = tail call i8* @realpath(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32* null)
%2 = icmp eq i8* %1, null
br i1 %2, label %10, label %3
3: ; preds = %0
%4 = tail call i8* @basename(i8* %1)
%5 = icmp eq i8* %4, null
br i1 %5, label %10, label %6
6: ; preds = %3
%7 = tail call i64 @strcmp(i8* %4, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%8 = icmp eq i64 %7, 0
%9 = zext i1 %8 to i32
br label %10
10: ; preds = %6, %3, %0
%11 = phi i32 [ 0, %0 ], [ 0, %3 ], [ %9, %6 ]
ret i32 %11
}