#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 **alloca(size_t);
int /*<<< orphan*/ execvp(char *, char **);
int /*<<< orphan*/ memcpy(char **, char **, size_t);
void halt(int argc, char *argv[]) {
  char **args;
  args = alloca((size_t)(argc + 3) * sizeof(char *));
  memcpy(args, argv, (size_t)argc * sizeof(char *));
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wcast-qual"
  args[0] = (char *)("shutdown");
  args[argc + 0] = (char *)"-h";
  args[argc + 1] = (char *)"now";
  args[argc + 2] = NULL;
#pragma GCC diagnostic pop
  execvp("shutdown", args);
}


x86 assembly (clang, -O0):
<halt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x4(%rbp),%eax
add    $0x3,%eax
movslq %eax,%rdi
shl    $0x3,%rdi
call   1030 <alloca@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
movslq -0x4(%rbp),%rdx
shl    $0x3,%rdx
call   1040 <memcpy@plt>
mov    -0x18(%rbp),%rax
lea    0xe8b(%rip),%rcx
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rax
mov    -0x4(%rbp),%ecx
add    $0x0,%ecx
movslq %ecx,%rcx
lea    0xe7d(%rip),%rdx
mov    %rdx,(%rax,%rcx,8)
mov    -0x18(%rbp),%rax
mov    -0x4(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
lea    0xe68(%rip),%rdx
mov    %rdx,(%rax,%rcx,8)
mov    -0x18(%rbp),%rax
mov    -0x4(%rbp),%ecx
add    $0x2,%ecx
movslq %ecx,%rcx
movq   $0x0,(%rax,%rcx,8)
mov    -0x18(%rbp),%rsi
lea    0xe38(%rip),%rdi
call   1050 <execvp@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<halt>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
movslq %edi,%r15
lea    0x18(,%r15,8),%rdi
call   1030 <alloca@plt>
mov    %rax,%rbx
lea    0x0(,%r15,8),%rdx
mov    %rax,%rdi
mov    %r14,%rsi
call   1040 <memcpy@plt>
lea    0xe9b(%rip),%rdi
mov    %rdi,(%rbx)
lea    0xe9a(%rip),%rax
mov    %rax,(%rbx,%r15,8)
lea    0xe92(%rip),%rax
mov    %rax,0x8(%rbx,%r15,8)
movq   $0x0,0x10(%rbx,%r15,8)
mov    %rbx,%rsi
pop    %rbx
pop    %r14
pop    %r15
jmp    1050 <execvp@plt>

LLVM IR (-O0):
@.str = [9 x i8] c"shutdown\00"
@.str.1 = [3 x i8] c"-h\00"
@.str.2 = [4 x i8] c"now\00"
define void @halt(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i8**
store i32 %0, i32* %3
store i8** %1, i8*** %4
%6 = load i32, i32* %3
%7 = add nsw i32 %6, 3
%8 = sext i32 %7 to i64
%9 = mul i64 %8, 8
%10 = call i8** @alloca(i64 %9)
store i8** %10, i8*** %5
%11 = load i8**, i8*** %5
%12 = load i8**, i8*** %4
%13 = load i32, i32* %3
%14 = sext i32 %13 to i64
%15 = mul i64 %14, 8
%16 = call i32 @memcpy(i8** %11, i8** %12, i64 %15)
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 0
store i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8** %18
%19 = load i8**, i8*** %5
%20 = load i32, i32* %3
%21 = add nsw i32 %20, 0
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8*, i8** %19, i64 %22
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8** %23
%24 = load i8**, i8*** %5
%25 = load i32, i32* %3
%26 = add nsw i32 %25, 1
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8*, i8** %24, i64 %27
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8** %28
%29 = load i8**, i8*** %5
%30 = load i32, i32* %3
%31 = add nsw i32 %30, 2
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8*, i8** %29, i64 %32
store i8* null, i8** %33
%34 = load i8**, i8*** %5
%35 = call i32 @execvp(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8** %34)
ret void
}

LLVM IR (-O2):
@.str = [9 x i8] c"shutdown\00"
@.str.1 = [3 x i8] c"-h\00"
@.str.2 = [4 x i8] c"now\00"
define void @halt(i32 %0, i8** %1) {
%3 = add nsw i32 %0, 3
%4 = sext i32 %3 to i64
%5 = shl nsw i64 %4, 3
%6 = tail call i8** @alloca(i64 %5)
%7 = sext i32 %0 to i64
%8 = shl nsw i64 %7, 3
%9 = tail call i32 @memcpy(i8** %6, i8** %1, i64 %8)
store i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8** %6
%10 = getelementptr inbounds i8*, i8** %6, i64 %7
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8** %10
%11 = add nsw i32 %0, 1
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds i8*, i8** %6, i64 %12
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8** %13
%14 = add nsw i32 %0, 2
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i8*, i8** %6, i64 %15
store i8* null, i8** %16
%17 = tail call i32 @execvp(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8** %6)
ret void
}