#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 /*<<< orphan*/ EX_OSERR;
int /*<<< orphan*/ emit_help();
int /*<<< orphan*/ err(int /*<<< orphan*/, char *, ...);
int execvp(char *, char **);
int /*<<< orphan*/ exit(int);
int getopt(int, char **, char *);
scalar_t__ optind;
int setsid();
int main(int argc, char *argv[]) {
  int ch;
  while ((ch = getopt(argc, argv, "h?")) != -1) {
    switch (ch) {
    case 'h':
    case '?':
    default:
      emit_help();
    }
  }
  argc -= optind;
  argv += optind;
  if (setsid() == -1)
    err(EX_OSERR, "could not setsid()");
  if (execvp(*argv, argv) == -1)
    err(EX_OSERR, "could not exec %s", *argv);
  exit(1);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe7c(%rip),%rdx
call   1060 <getopt@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
je     11cb <main+0x6b>
mov    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
sub    $0x3f,%eax
je     11ba <main+0x5a>
jmp    11a9 <main+0x49>
mov    -0x18(%rbp),%eax
sub    $0x68,%eax
jne    11bf <main+0x5f>
jmp    11ba <main+0x5a>
jmp    11bf <main+0x5f>
mov    $0x0,%al
call   1030 <emit_help@plt>
jmp    1176 <main+0x16>
mov    0x2e16(%rip),%rax
mov    (%rax),%rcx
movslq -0x8(%rbp),%rax
sub    %rcx,%rax
mov    %eax,-0x8(%rbp)
mov    0x2e02(%rip),%rax
mov    (%rax),%rax
shl    $0x3,%rax
add    -0x10(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    $0x0,%al
call   1040 <setsid@plt>
cmp    $0xffffffff,%eax
jne    121c <main+0xbc>
mov    0x2dcc(%rip),%rax
mov    (%rax),%edi
lea    0xdee(%rip),%rsi
mov    $0x0,%al
call   1050 <err@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rsi
call   1070 <execvp@plt>
cmp    $0xffffffff,%eax
jne    1253 <main+0xf3>
mov    0x2d9c(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xdca(%rip),%rsi
mov    $0x0,%al
call   1050 <err@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%rbx
mov    %edi,%ebp
lea    0xe90(%rip),%rdx
call   1060 <getopt@plt>
cmp    $0xffffffff,%eax
je     11a9 <main+0x49>
lea    0xe7f(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1030 <emit_help@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r14,%rdx
call   1060 <getopt@plt>
cmp    $0xffffffff,%eax
jne    1190 <main+0x30>
mov    0x2e38(%rip),%rax
mov    (%rax),%rax
lea    (%rbx,%rax,8),%rbx
xor    %eax,%eax
call   1040 <setsid@plt>
cmp    $0xffffffff,%eax
jne    11da <main+0x7a>
mov    0x2e0e(%rip),%rax
mov    (%rax),%edi
lea    0xe30(%rip),%rsi
xor    %eax,%eax
call   1050 <err@plt>
mov    (%rbx),%rdi
mov    %rbx,%rsi
call   1070 <execvp@plt>
cmp    $0xffffffff,%eax
jne    1204 <main+0xa4>
mov    0x2de7(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xe19(%rip),%rsi
xor    %eax,%eax
call   1050 <err@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"h?\00"
@optind = global i64 0
@EX_OSERR = global i32 0
@.str.1 = [19 x i8] c"could not setsid()\00"
@.str.2 = [18 x i8] c"could not exec %s\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
br label %7
7: ; preds = %17, %2
%8 = load i32, i32* %4
%9 = load i8**, i8*** %5
%10 = call i32 @getopt(i32 %8, i8** %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32 %10, i32* %6
%11 = icmp ne i32 %10, -1
br i1 %11, label %12, label %18
12: ; preds = %7
%13 = load i32, i32* %6
switch i32 %13, label %15 [
i32 104, label %14
i32 63, label %14
]
14: ; preds = %12, %12
br label %15
15: ; preds = %12, %14
%16 = call i32 (...) @emit_help()
br label %17
17: ; preds = %15
br label %7
18: ; preds = %7
%19 = load i64, i64* @optind
%20 = load i32, i32* %4
%21 = sext i32 %20 to i64
%22 = sub nsw i64 %21, %19
%23 = trunc i64 %22 to i32
store i32 %23, i32* %4
%24 = load i64, i64* @optind
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 %24
store i8** %26, i8*** %5
%27 = call i32 (...) @setsid()
%28 = icmp eq i32 %27, -1
br i1 %28, label %29, label %32
29: ; preds = %18
%30 = load i32, i32* @EX_OSERR
%31 = call i32 (i32, i8*, ...) @err(i32 %30, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
br label %32
32: ; preds = %29, %18
%33 = load i8**, i8*** %5
%34 = load i8*, i8** %33
%35 = load i8**, i8*** %5
%36 = call i32 @execvp(i8* %34, i8** %35)
%37 = icmp eq i32 %36, -1
br i1 %37, label %38, label %43
38: ; preds = %32
%39 = load i32, i32* @EX_OSERR
%40 = load i8**, i8*** %5
%41 = load i8*, i8** %40
%42 = call i32 (i32, i8*, ...) @err(i32 %39, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* %41)
br label %43
43: ; preds = %38, %32
%44 = call i32 @exit(i32 1)
unreachable
}

LLVM IR (-O2):
@.str = [3 x i8] c"h?\00"
@optind = global i64 0
@EX_OSERR = global i32 0
@.str.1 = [19 x i8] c"could not setsid()\00"
@.str.2 = [18 x i8] c"could not exec %s\00"
define i32 @main(i32 %0, i8** %1) {
%3 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i32 %3, -1
br i1 %4, label %9, label %5
5: ; preds = %2, %5
%6 = tail call i32 (...) @emit_help()
%7 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %5
9: ; preds = %5, %2
%10 = load i64, i64* @optind
%11 = getelementptr inbounds i8*, i8** %1, i64 %10
%12 = tail call i32 (...) @setsid()
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %17
14: ; preds = %9
%15 = load i32, i32* @EX_OSERR
%16 = tail call i32 (i32, i8*, ...) @err(i32 %15, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
br label %17
17: ; preds = %14, %9
%18 = load i8*, i8** %11
%19 = tail call i32 @execvp(i8* %18, i8** %11)
%20 = icmp eq i32 %19, -1
br i1 %20, label %21, label %25
21: ; preds = %17
%22 = load i32, i32* @EX_OSERR
%23 = load i8*, i8** %11
%24 = tail call i32 (i32, i8*, ...) @err(i32 %22, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* %23)
br label %25
25: ; preds = %21, %17
%26 = tail call i32 @exit(i32 1)
unreachable
}