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

/* Variables and functions */
scalar_t__ WEXITSTATUS(int);
int execv(char *, char *const *);
int /*<<< orphan*/ exit(int);
int fork();
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ snprintf(char *, int, char *, int);
int /*<<< orphan*/ waitpid(int, int *, int /*<<< orphan*/);
void launch_init_script() {
  int pid, status;
  char *script_path = "/usr/lib/v4/init.sh";
  char period_string[12];
  char *const args[] = {script_path, period_string, NULL};
  snprintf(period_string, sizeof(period_string), "%d", 20000000);
  pid = fork();
  if (pid == 0) {
    exit(execv(script_path, args));
  } else {
    waitpid(pid, &status, 0);
    if (WEXITSTATUS(status) != 0) {
      puts("PWM: Init script execution has an error");
      exit(1);
    }
  }
}


x86 assembly (clang, -O0):
<launch_init_script>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
lea    0xe81(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x40(%rbp)
lea    -0x1c(%rbp),%rax
mov    %rax,-0x38(%rbp)
movq   $0x0,-0x30(%rbp)
lea    -0x1c(%rbp),%rdi
mov    $0xc,%esi
lea    0xe69(%rip),%rdx
mov    $0x1312d00,%ecx
call   1040 <snprintf@plt>
mov    $0x0,%al
call   1090 <fork@plt>
mov    %eax,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
jne    11dd <launch_init_script+0x6d>
mov    -0x10(%rbp),%rdi
lea    -0x40(%rbp),%rsi
call   1080 <execv@plt>
mov    %eax,%edi
call   1070 <exit@plt>
mov    -0x4(%rbp),%edi
lea    -0x8(%rbp),%rsi
xor    %edx,%edx
call   1060 <waitpid@plt>
mov    -0x8(%rbp),%edi
call   1050 <WEXITSTATUS@plt>
cmp    $0x0,%rax
je     1213 <launch_init_script+0xa3>
lea    0xe13(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
jmp    1218 <launch_init_script+0xa8>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<launch_init_script>:
sub    $0x38,%rsp
lea    0xe85(%rip),%rax
mov    %rax,0x10(%rsp)
lea    0x2c(%rsp),%rdi
mov    %rdi,0x18(%rsp)
movq   $0x0,0x20(%rsp)
lea    0xe7a(%rip),%rdx
mov    $0xc,%esi
mov    $0x1312d00,%ecx
call   1040 <snprintf@plt>
xor    %eax,%eax
call   1090 <fork@plt>
test   %eax,%eax
je     11d5 <launch_init_script+0x65>
lea    0xc(%rsp),%rsi
mov    %eax,%edi
xor    %edx,%edx
call   1060 <waitpid@plt>
mov    0xc(%rsp),%edi
call   1050 <WEXITSTATUS@plt>
test   %rax,%rax
jne    11ed <launch_init_script+0x7d>
add    $0x38,%rsp
ret
lea    0xe24(%rip),%rdi
lea    0x10(%rsp),%rsi
call   1080 <execv@plt>
mov    %eax,%edi
call   1070 <exit@plt>
lea    0xe23(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

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

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