#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 */
scalar_t__ WEXITSTATUS(int);
int execv(char *, char *const *);
int /*<<< orphan*/ exit(int);
int fork();
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ waitpid(int, int *, int /*<<< orphan*/);
void v3_launch_init_script() {
  int pid, status;
  char *script_path = "/usr/lib/v3/init.sh";
  char *const args[] = {script_path, NULL};
  pid = fork();
  if (pid == 0) {
    exit(execv(script_path, args));
  } else {
    waitpid(pid, &status, 0);
    if (WEXITSTATUS(status) != 0) {
      puts("V3: Init script execution has an error");
      exit(1);
    }
  }
}


x86 assembly (clang, -O0):
<v3_launch_init_script>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xe91(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
movq   $0x0,-0x18(%rbp)
mov    $0x0,%al
call   1080 <fork@plt>
mov    %eax,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
jne    11ab <v3_launch_init_script+0x4b>
mov    -0x10(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1070 <execv@plt>
mov    %eax,%edi
call   1060 <exit@plt>
mov    -0x4(%rbp),%edi
lea    -0x8(%rbp),%rsi
xor    %edx,%edx
call   1050 <waitpid@plt>
mov    -0x8(%rbp),%edi
call   1040 <WEXITSTATUS@plt>
cmp    $0x0,%rax
je     11e1 <v3_launch_init_script+0x81>
lea    0xe42(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
jmp    11e6 <v3_launch_init_script+0x86>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<v3_launch_init_script>:
sub    $0x28,%rsp
lea    0xe95(%rip),%rax
mov    %rax,0x10(%rsp)
movq   $0x0,0x18(%rsp)
xor    %eax,%eax
call   1080 <fork@plt>
test   %eax,%eax
je     11a5 <v3_launch_init_script+0x45>
lea    0xc(%rsp),%rsi
mov    %eax,%edi
xor    %edx,%edx
call   1050 <waitpid@plt>
mov    0xc(%rsp),%edi
call   1040 <WEXITSTATUS@plt>
test   %rax,%rax
jne    11bd <v3_launch_init_script+0x5d>
add    $0x28,%rsp
ret
lea    0xe54(%rip),%rdi
lea    0x10(%rsp),%rsi
call   1070 <execv@plt>
mov    %eax,%edi
call   1060 <exit@plt>
lea    0xe50(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [20 x i8] c"/usr/lib/v3/init.sh\00"
@.str.1 = [39 x i8] c"V3: Init script execution has an error\00"
define void @v3_launch_init_script() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i8*
%4 = alloca [2 x i8*]
store i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8** %3
%5 = getelementptr inbounds [2 x i8*], [2 x i8*]* %4, i64 0, i64 0
%6 = load i8*, i8** %3
store i8* %6, i8** %5
%7 = getelementptr inbounds i8*, i8** %5, i64 1
store i8* null, i8** %7
%8 = call i32 (...) @fork()
store i32 %8, i32* %1
%9 = load i32, i32* %1
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %16
11: ; preds = %0
%12 = load i8*, i8** %3
%13 = getelementptr inbounds [2 x i8*], [2 x i8*]* %4, i64 0, i64 0
%14 = call i32 @execv(i8* %12, i8** %13)
%15 = call i32 @exit(i32 %14)
unreachable
16: ; preds = %0
%17 = load i32, i32* %1
%18 = call i32 @waitpid(i32 %17, i32* %2, i32 0)
%19 = load i32, i32* %2
%20 = call i64 @WEXITSTATUS(i32 %19)
%21 = icmp ne i64 %20, 0
br i1 %21, label %22, label %25
22: ; preds = %16
%23 = call i32 @puts(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0))
%24 = call i32 @exit(i32 1)
unreachable
25: ; preds = %16
br label %26
26: ; preds = %25
ret void
}

LLVM IR (-O2):
@.str = [20 x i8] c"/usr/lib/v3/init.sh\00"
@.str.1 = [39 x i8] c"V3: Init script execution has an error\00"
define void @v3_launch_init_script() {
%1 = alloca i32
%2 = alloca [2 x i8*]
%3 = bitcast i32* %1 to i8*
%4 = bitcast [2 x i8*]* %2 to i8*
%5 = getelementptr inbounds [2 x i8*], [2 x i8*]* %2, i64 0, i64 0
store i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8** %5
%6 = getelementptr inbounds [2 x i8*], [2 x i8*]* %2, i64 0, i64 1
store i8* null, i8** %6
%7 = tail call i32 (...) @fork()
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %12
9: ; preds = %0
%10 = call i32 @execv(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8** %5)
%11 = call i32 @exit(i32 %10)
unreachable
12: ; preds = %0
%13 = call i32 @waitpid(i32 %7, i32* %1, i32 0)
%14 = load i32, i32* %1
%15 = call i64 @WEXITSTATUS(i32 %14)
%16 = icmp eq i64 %15, 0
br i1 %16, label %20, label %17
17: ; preds = %12
%18 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0))
%19 = call i32 @exit(i32 1)
unreachable
20: ; preds = %12
ret void
}