#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*/ snprintf(char *, int, char *, char *);
int /*<<< orphan*/ stat(char *, struct stat *);
int isSystemd(char *initscript) {
  char tmppath[500];
  struct stat sbuf;
  snprintf(tmppath, 500, "/lib/systemd/system/%s.service", initscript);
  if (!stat(tmppath, &sbuf))
    return 1;
  snprintf(tmppath, 500, "/etc/systemd/system/%s.service", initscript);
  if (!stat(tmppath, &sbuf))
    return 1;
  return 0;
}


x86 assembly (clang, -O0):
<isSystemd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x220,%rsp
mov    %rdi,-0x10(%rbp)
lea    -0x210(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x1f4,%esi
lea    0xeba(%rip),%rdx
call   1030 <snprintf@plt>
lea    -0x210(%rbp),%rdi
lea    -0x218(%rbp),%rsi
call   1040 <stat@plt>
cmp    $0x0,%eax
jne    1173 <isSystemd+0x53>
movl   $0x1,-0x4(%rbp)
jmp    11be <isSystemd+0x9e>
lea    -0x210(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x1f4,%esi
lea    0xe95(%rip),%rdx
call   1030 <snprintf@plt>
lea    -0x210(%rbp),%rdi
lea    -0x218(%rbp),%rsi
call   1040 <stat@plt>
cmp    $0x0,%eax
jne    11b7 <isSystemd+0x97>
movl   $0x1,-0x4(%rbp)
jmp    11be <isSystemd+0x9e>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x220,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<isSystemd>:
push   %r14
push   %rbx
sub    $0x208,%rsp
mov    %rdi,%rbx
lea    0xecc(%rip),%rdx
lea    0x10(%rsp),%r14
mov    %r14,%rdi
mov    $0x1f4,%esi
mov    %rbx,%rcx
call   1030 <snprintf@plt>
lea    0x8(%rsp),%rsi
mov    %r14,%rdi
call   1040 <stat@plt>
test   %eax,%eax
je     118e <isSystemd+0x6e>
lea    0xebe(%rip),%rdx
lea    0x10(%rsp),%r14
mov    %r14,%rdi
mov    $0x1f4,%esi
mov    %rbx,%rcx
call   1030 <snprintf@plt>
lea    0x8(%rsp),%rsi
mov    %r14,%rdi
call   1040 <stat@plt>
mov    %eax,%ecx
xor    %eax,%eax
test   %ecx,%ecx
sete   %al
jmp    1193 <isSystemd+0x73>
mov    $0x1,%eax
add    $0x208,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [31 x i8] c"/lib/systemd/system/%s.service\00"
@.str.1 = [31 x i8] c"/etc/systemd/system/%s.service\00"
define i32 @isSystemd(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca [500 x i8]
%5 = alloca %struct.stat
store i8* %0, i8** %3
%6 = getelementptr inbounds [500 x i8], [500 x i8]* %4, i64 0, i64 0
%7 = load i8*, i8** %3
%8 = call i32 @snprintf(i8* %6, i32 500, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i8* %7)
%9 = getelementptr inbounds [500 x i8], [500 x i8]* %4, i64 0, i64 0
%10 = call i32 @stat(i8* %9, %struct.stat* %5)
%11 = icmp ne i32 %10, 0
br i1 %11, label %13, label %12
12: ; preds = %1
store i32 1, i32* %2
br label %22
13: ; preds = %1
%14 = getelementptr inbounds [500 x i8], [500 x i8]* %4, i64 0, i64 0
%15 = load i8*, i8** %3
%16 = call i32 @snprintf(i8* %14, i32 500, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i8* %15)
%17 = getelementptr inbounds [500 x i8], [500 x i8]* %4, i64 0, i64 0
%18 = call i32 @stat(i8* %17, %struct.stat* %5)
%19 = icmp ne i32 %18, 0
br i1 %19, label %21, label %20
20: ; preds = %13
store i32 1, i32* %2
br label %22
21: ; preds = %13
store i32 0, i32* %2
br label %22
22: ; preds = %21, %20, %12
%23 = load i32, i32* %2
ret i32 %23
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [31 x i8] c"/lib/systemd/system/%s.service\00"
@.str.1 = [31 x i8] c"/etc/systemd/system/%s.service\00"
define i32 @isSystemd(i8* %0) {
%2 = alloca [500 x i8]
%3 = alloca %struct.stat
%4 = getelementptr inbounds [500 x i8], [500 x i8]* %2, i64 0, i64 0
%5 = bitcast %struct.stat* %3 to i8*
%6 = call i32 @snprintf(i8* %4, i32 500, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i8* %0)
%7 = call i32 @stat(i8* %4, %struct.stat* %3)
%8 = icmp eq i32 %7, 0
br i1 %8, label %14, label %9
9: ; preds = %1
%10 = call i32 @snprintf(i8* %4, i32 500, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%11 = call i32 @stat(i8* %4, %struct.stat* %3)
%12 = icmp eq i32 %11, 0
%13 = zext i1 %12 to i32
br label %14
14: ; preds = %9, %1
%15 = phi i32 [ 1, %1 ], [ %13, %9 ]
ret i32 %15
}