#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 */
int PATH_MAX;
int WEXITSTATUS(int);
int /*<<< orphan*/ execl(char *, char *, char const *, int /*<<< orphan*/ *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fork();
int /*<<< orphan*/ strcat(char *, char const *);
int /*<<< orphan*/ strncpy(char *, char const *, int);
int /*<<< orphan*/ wait(int *);
int registerDeregisterRun(const char *argv0, const char *bits, bool reg) {
  char path[PATH_MAX];
  const char *argument = (reg) ? "--register" : "--deregister";
  strncpy(path, argv0, PATH_MAX - 1);
  path[PATH_MAX - 1] = 0;
  strcat(path, bits);
  if (!fork()) {
    execl(path, path, argument, NULL);
    exit(1);
  } else {
    int status;
    wait(&status);
    return WEXITSTATUS(status);
  }
}


x86 assembly (clang, -O0):
<registerDeregisterRun>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    0x2e66(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x40(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x28(%rbp)
mov    -0x14(%rbp),%edx
lea    0xe52(%rip),%rax
lea    0xe40(%rip),%rcx
cmp    $0x0,%edx
cmovne %rcx,%rax
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rsi
mov    0x2e1a(%rip),%rax
mov    (%rax),%edx
sub    $0x1,%edx
call   1030 <strncpy@plt>
mov    -0x40(%rbp),%rdi
mov    0x2e05(%rip),%rax
mov    (%rax),%eax
sub    $0x1,%eax
cltq
movb   $0x0,(%rdi,%rax,1)
mov    -0x10(%rbp),%rsi
call   1050 <strcat@plt>
mov    $0x0,%al
call   1090 <fork@plt>
cmp    $0x0,%eax
jne    122d <registerDeregisterRun+0xbd>
mov    -0x40(%rbp),%rsi
mov    -0x30(%rbp),%rdx
xor    %eax,%eax
mov    %eax,%ecx
mov    %rsi,%rdi
call   1070 <execl@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
lea    -0x34(%rbp),%rdi
call   1080 <wait@plt>
mov    -0x34(%rbp),%edi
call   1040 <WEXITSTATUS@plt>
mov    -0x20(%rbp),%rcx
mov    %rcx,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<registerDeregisterRun>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %edx,%r14d
mov    %rsi,%r15
mov    %rdi,%rsi
mov    0x2e61(%rip),%r12
mov    (%r12),%eax
mov    %rsp,%rbx
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
sub    %rcx,%rbx
mov    %rbx,%rsp
lea    -0x1(%rax),%edx
mov    %rbx,%rdi
call   1030 <strncpy@plt>
movslq (%r12),%rax
movb   $0x0,-0x1(%rax,%rbx,1)
mov    %rbx,%rdi
mov    %r15,%rsi
call   1050 <strcat@plt>
xor    %eax,%eax
call   1090 <fork@plt>
test   %eax,%eax
je     11ef <registerDeregisterRun+0x7f>
lea    -0x24(%rbp),%rdi
call   1080 <wait@plt>
mov    -0x24(%rbp),%edi
call   1040 <WEXITSTATUS@plt>
lea    -0x20(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
test   %r14d,%r14d
lea    0xe12(%rip),%rax
lea    0xe00(%rip),%rdx
cmove  %rax,%rdx
mov    %rbx,%rdi
mov    %rbx,%rsi
xor    %ecx,%ecx
call   1070 <execl@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@PATH_MAX = global i32 0
@.str = [11 x i8] c"--register\00"
@.str.1 = [13 x i8] c"--deregister\00"
define i32 @registerDeregisterRun(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i8*
%10 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%11 = load i32, i32* @PATH_MAX
%12 = zext i32 %11 to i64
%13 = call i8* @llvm.stacksave()
store i8* %13, i8** %7
%14 = alloca i8, i64 %12
store i64 %12, i64* %8
%15 = load i32, i32* %6
%16 = icmp ne i32 %15, 0
%17 = zext i1 %16 to i64
%18 = select i1 %16, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0)
store i8* %18, i8** %9
%19 = load i8*, i8** %4
%20 = load i32, i32* @PATH_MAX
%21 = sub nsw i32 %20, 1
%22 = call i32 @strncpy(i8* %14, i8* %19, i32 %21)
%23 = load i32, i32* @PATH_MAX
%24 = sub nsw i32 %23, 1
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8, i8* %14, i64 %25
store i8 0, i8* %26
%27 = load i8*, i8** %5
%28 = call i32 @strcat(i8* %14, i8* %27)
%29 = call i32 (...) @fork()
%30 = icmp ne i32 %29, 0
br i1 %30, label %35, label %31
31: ; preds = %3
%32 = load i8*, i8** %9
%33 = call i32 @execl(i8* %14, i8* %14, i8* %32, i32* null)
%34 = call i32 @exit(i32 1)
unreachable
35: ; preds = %3
%36 = call i32 @wait(i32* %10)
%37 = load i32, i32* %10
%38 = call i32 @WEXITSTATUS(i32 %37)
%39 = load i8*, i8** %7
ret i32 %38
}

LLVM IR (-O2):
@PATH_MAX = global i32 0
@.str = [11 x i8] c"--register\00"
@.str.1 = [13 x i8] c"--deregister\00"
define i32 @registerDeregisterRun(i8* %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = load i32, i32* @PATH_MAX
%6 = zext i32 %5 to i64
%7 = alloca i8, i64 %6
%8 = add nsw i32 %5, -1
%9 = call i32 @strncpy(i8* %7, i8* %0, i32 %8)
%10 = load i32, i32* @PATH_MAX
%11 = add nsw i32 %10, -1
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds i8, i8* %7, i64 %12
store i8 0, i8* %13
%14 = call i32 @strcat(i8* %7, i8* %1)
%15 = call i32 (...) @fork()
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %22
17: ; preds = %3
%18 = icmp eq i32 %2, 0
%19 = select i1 %18, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0)
%20 = call i32 @execl(i8* %7, i8* %7, i8* %19, i32* null)
%21 = call i32 @exit(i32 1)
unreachable
22: ; preds = %3
%23 = bitcast i32* %4 to i8*
%24 = call i32 @wait(i32* %4)
%25 = load i32, i32* %4
%26 = call i32 @WEXITSTATUS(i32 %25)
ret i32 %26
}