#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 scalar_t__ pid_t;

/* Variables and functions */
int /*<<< orphan*/ _exit(int);
int /*<<< orphan*/ execlp(char *, char *, char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ exit(int);
scalar_t__ fork();
int /*<<< orphan*/ perror(char *);
void spawn_sudo(void) {
  pid_t pid;
  pid = fork();
  if (pid < 0) {
    perror("error forking new process");
    exit(1);
  }
  if (!pid) {
    execlp("sudo", "sudo", "true", NULL);
    perror("error executing process");
    _exit(1);
  }
}


x86 assembly (clang, -O0):
<spawn_sudo>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x0,%al
call   1070 <fork@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jge    1184 <spawn_sudo+0x34>
lea    0xe8b(%rip),%rdi
call   1040 <perror@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
cmpq   $0x0,-0x8(%rbp)
jne    11bf <spawn_sudo+0x6f>
lea    0xe84(%rip),%rsi
lea    0xe82(%rip),%rdx
xor    %eax,%eax
mov    %eax,%ecx
mov    %rsi,%rdi
call   1060 <execlp@plt>
lea    0xe74(%rip),%rdi
call   1040 <perror@plt>
mov    $0x1,%edi
call   1030 <_exit@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<spawn_sudo>:
push   %rax
xor    %eax,%eax
call   1070 <fork@plt>
test   %rax,%rax
js     1161 <spawn_sudo+0x11>
je     1177 <spawn_sudo+0x27>
pop    %rax
ret
lea    0xe98(%rip),%rdi
call   1040 <perror@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
lea    0xe9c(%rip),%rdi
lea    0xe9a(%rip),%rdx
mov    %rdi,%rsi
xor    %ecx,%ecx
call   1060 <execlp@plt>
lea    0xe8e(%rip),%rdi
call   1040 <perror@plt>
mov    $0x1,%edi
call   1030 <_exit@plt>

LLVM IR (-O0):
@.str = [26 x i8] c"error forking new process\00"
@.str.1 = [5 x i8] c"sudo\00"
@.str.2 = [5 x i8] c"true\00"
@.str.3 = [24 x i8] c"error executing process\00"
define void @spawn_sudo() {
%1 = alloca i64
%2 = call i64 (...) @fork()
store i64 %2, i64* %1
%3 = load i64, i64* %1
%4 = icmp slt i64 %3, 0
br i1 %4, label %5, label %8
5: ; preds = %0
%6 = call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
%7 = call i32 @exit(i32 1)
unreachable
8: ; preds = %0
%9 = load i64, i64* %1
%10 = icmp ne i64 %9, 0
br i1 %10, label %15, label %11
11: ; preds = %8
%12 = call i32 @execlp(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32* null)
%13 = call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0))
%14 = call i32 @_exit(i32 1)
unreachable
15: ; preds = %8
ret void
}

LLVM IR (-O2):
@.str = [26 x i8] c"error forking new process\00"
@.str.1 = [5 x i8] c"sudo\00"
@.str.2 = [5 x i8] c"true\00"
@.str.3 = [24 x i8] c"error executing process\00"
define void @spawn_sudo() {
%1 = tail call i64 (...) @fork()
%2 = icmp slt i64 %1, 0
br i1 %2, label %3, label %6
3: ; preds = %0
%4 = tail call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
%5 = tail call i32 @exit(i32 1)
unreachable
6: ; preds = %0
%7 = icmp eq i64 %1, 0
br i1 %7, label %8, label %12
8: ; preds = %6
%9 = tail call i32 @execlp(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32* null)
%10 = tail call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0))
%11 = tail call i32 @_exit(i32 1)
unreachable
12: ; preds = %6
ret void
}