#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 */
struct timespec {
  long member_0;
  long member_1;
};
typedef int /*<<< orphan*/ sigset_t;

/* Variables and functions */
int EINVAL;
int ENOEXEC;
#define SIGUSR1 128
int /*<<< orphan*/ SIG_BLOCK;
int /*<<< orphan*/ SIG_IGN;
int errno;
int /*<<< orphan*/ execv(char *, char **);
int fork();
char *getenv(char *);
int /*<<< orphan*/ sigfillset(int /*<<< orphan*/ *);
int /*<<< orphan*/ signal(int, int /*<<< orphan*/);
int /*<<< orphan*/ sigprocmask(int /*<<< orphan*/, int /*<<< orphan*/ *,
                               int /*<<< orphan*/ *);
int /*<<< orphan*/ sigtimedwait(int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                                struct timespec *);
char *strdup(char *);
char *strtok(char *, char *);
int main(int argc, char **argv) {
  char *ptrs[30], *opt, *cmdline = getenv("LIGHTSM_X11_SERVER_CMDLINE");
  int count = 0;
  sigset_t set;
  struct timespec time = {60L, 0L};
  if (!cmdline)
    return EINVAL;
  switch (fork()) {
  case 0:
    for (opt = strtok(cmdline, " "); opt; opt = strtok(NULL, " "))
      ptrs[count++] = strdup(opt);
    ptrs[count] = NULL;
    signal(SIGUSR1, SIG_IGN);
    execv(ptrs[0], ptrs);
  case -1:
    return ENOEXEC;
  default:
    sigfillset(&set);
    sigprocmask(SIG_BLOCK, &set, NULL);
    switch (sigtimedwait(&set, NULL, &time)) {
    case SIGUSR1:
      return 0;
    case -1:
      return errno;
    default:
      return 1;
    }
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x140,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe50(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x110(%rbp)
movl   $0x0,-0x114(%rbp)
mov    0xe53(%rip),%rax
mov    %rax,-0x128(%rbp)
mov    0xe4d(%rip),%rax
mov    %rax,-0x120(%rbp)
cmpq   $0x0,-0x110(%rbp)
jne    1201 <main+0x71>
mov    0x2dc9(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1386 <main+0x1f6>
xor    %eax,%eax
call   10b0 <fork@plt>
mov    %eax,%ecx
mov    %ecx,-0x12c(%rbp)
sub    $0xffffffff,%eax
je     12d8 <main+0x148>
jmp    121e <main+0x8e>
mov    -0x12c(%rbp),%eax
test   %eax,%eax
jne    12e9 <main+0x159>
jmp    1231 <main+0xa1>
mov    -0x110(%rbp),%rdi
lea    0xddc(%rip),%rsi
call   1080 <strtok@plt>
mov    %rax,-0x108(%rbp)
cmpq   $0x0,-0x108(%rbp)
je     129f <main+0x10f>
mov    -0x108(%rbp),%rdi
call   1090 <strdup@plt>
mov    %rax,%rcx
mov    -0x114(%rbp),%eax
mov    %eax,%edx
add    $0x1,%edx
mov    %edx,-0x114(%rbp)
cltq
mov    %rcx,-0x100(%rbp,%rax,8)
ff
xor    %eax,%eax
mov    %eax,%edi
lea    0xd8d(%rip),%rsi
call   1080 <strtok@plt>
mov    %rax,-0x108(%rbp)
jmp    124b <main+0xbb>
movslq -0x114(%rbp),%rax
movq   $0x0,-0x100(%rbp,%rax,8)
mov    0x2d27(%rip),%rax
mov    (%rax),%esi
mov    $0x80,%edi
call   1060 <signal@plt>
mov    -0x100(%rbp),%rdi
lea    -0x100(%rbp),%rsi
call   10a0 <execv@plt>
mov    0x2d09(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1386 <main+0x1f6>
lea    -0x118(%rbp),%rdi
mov    %rdi,-0x140(%rbp)
call   1070 <sigfillset@plt>
mov    -0x140(%rbp),%rsi
mov    0x2cbe(%rip),%rax
mov    (%rax),%edi
xor    %eax,%eax
mov    %eax,%edx
mov    %rdx,-0x138(%rbp)
call   1040 <sigprocmask@plt>
mov    -0x140(%rbp),%rdi
mov    -0x138(%rbp),%rsi
lea    -0x128(%rbp),%rdx
call   1050 <sigtimedwait@plt>
mov    %eax,%ecx
mov    %ecx,-0x130(%rbp)
sub    $0xffffffff,%eax
je     136e <main+0x1de>
jmp    134c <main+0x1bc>
mov    -0x130(%rbp),%eax
sub    $0x80,%eax
jne    137f <main+0x1ef>
jmp    1362 <main+0x1d2>
movl   $0x0,-0x4(%rbp)
jmp    1386 <main+0x1f6>
mov    0x2c5b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1386 <main+0x1f6>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x140,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x108,%rsp
lea    0xe5f(%rip),%rdi
call   1030 <getenv@plt>
movups 0xe73(%rip),%xmm0
movaps %xmm0,(%rsp)
test   %rax,%rax
je     1214 <main+0x84>
mov    %rax,%rbx
xor    %eax,%eax
call   10b0 <fork@plt>
cmp    $0xffffffff,%eax
je     128e <main+0xfe>
test   %eax,%eax
jne    121d <main+0x8d>
lea    0xe47(%rip),%rsi
mov    %rbx,%rdi
call   1080 <strtok@plt>
test   %rax,%rax
je     1261 <main+0xd1>
xor    %ebx,%ebx
lea    0xe2d(%rip),%r14
xchg   %ax,%ax
mov    %rax,%rdi
call   1090 <strdup@plt>
mov    %rax,0x10(%rsp,%rbx,8)
add    $0x1,%rbx
xor    %edi,%edi
mov    %r14,%rsi
call   1080 <strtok@plt>
test   %rax,%rax
jne    11f0 <main+0x60>
mov    %ebx,%eax
jmp    1263 <main+0xd3>
mov    0x2da5(%rip),%rax
jmp    1295 <main+0x105>
lea    0x10(%rsp),%r14
mov    %r14,%rdi
call   1070 <sigfillset@plt>
mov    0x2d97(%rip),%rax
mov    (%rax),%edi
xor    %ebx,%ebx
mov    %r14,%rsi
xor    %edx,%edx
call   1040 <sigprocmask@plt>
mov    %rsp,%rdx
mov    %r14,%rdi
xor    %esi,%esi
call   1050 <sigtimedwait@plt>
cmp    $0x80,%eax
je     1297 <main+0x107>
cmp    $0xffffffff,%eax
jne    12a4 <main+0x114>
mov    0x2d71(%rip),%rax
jmp    1295 <main+0x105>
xor    %eax,%eax
movq   $0x0,0x10(%rsp,%rax,8)
mov    0x2d6d(%rip),%rax
mov    (%rax),%esi
mov    $0x80,%edi
call   1060 <signal@plt>
mov    0x10(%rsp),%rdi
lea    0x10(%rsp),%rsi
call   10a0 <execv@plt>
mov    0x2d53(%rip),%rax
mov    (%rax),%ebx
mov    %ebx,%eax
add    $0x108,%rsp
pop    %rbx
pop    %r14
ret
mov    $0x1,%ebx
jmp    1297 <main+0x107>

LLVM IR (-O0):
%struct.timespec = type { i64, i64 }
@.str = [27 x i8] c"LIGHTSM_X11_SERVER_CMDLINE\00"
@__const.main.time = %struct.timespec { i64 60, i64 0 }
@EINVAL = global i32 0
@.str.1 = [2 x i8] c" \00"
@SIG_IGN = global i32 0
@ENOEXEC = global i32 0
@SIG_BLOCK = global i32 0
@errno = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [30 x i8*]
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
%11 = alloca %struct.timespec
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = call i8* @getenv(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
store i8* %12, i8** %8
store i32 0, i32* %9
%13 = bitcast %struct.timespec* %11 to i8*
%14 = load i8*, i8** %8
%15 = icmp ne i8* %14, null
br i1 %15, label %18, label %16
16: ; preds = %2
%17 = load i32, i32* @EINVAL
store i32 %17, i32* %3
br label %56
18: ; preds = %2
%19 = call i32 (...) @fork()
switch i32 %19, label %47 [
i32 0, label %20
i32 -1, label %45
]
20: ; preds = %18
%21 = load i8*, i8** %8
%22 = call i8* @strtok(i8* %21, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i8* %22, i8** %7
br label %23
23: ; preds = %33, %20
%24 = load i8*, i8** %7
%25 = icmp ne i8* %24, null
br i1 %25, label %26, label %35
26: ; preds = %23
%27 = load i8*, i8** %7
%28 = call i8* @strdup(i8* %27)
%29 = load i32, i32* %9
%30 = add nsw i32 %29, 1
store i32 %30, i32* %9
%31 = sext i32 %29 to i64
%32 = getelementptr inbounds [30 x i8*], [30 x i8*]* %6, i64 0, i64 %31
store i8* %28, i8** %32
br label %33
33: ; preds = %26
%34 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i8* %34, i8** %7
br label %23
35: ; preds = %23
%36 = load i32, i32* %9
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds [30 x i8*], [30 x i8*]* %6, i64 0, i64 %37
store i8* null, i8** %38
%39 = load i32, i32* @SIG_IGN
%40 = call i32 @signal(i32 128, i32 %39)
%41 = getelementptr inbounds [30 x i8*], [30 x i8*]* %6, i64 0, i64 0
%42 = load i8*, i8** %41
%43 = getelementptr inbounds [30 x i8*], [30 x i8*]* %6, i64 0, i64 0
%44 = call i32 @execv(i8* %42, i8** %43)
br label %45
45: ; preds = %18, %35
%46 = load i32, i32* @ENOEXEC
store i32 %46, i32* %3
br label %56
47: ; preds = %18
%48 = call i32 @sigfillset(i32* %10)
%49 = load i32, i32* @SIG_BLOCK
%50 = call i32 @sigprocmask(i32 %49, i32* %10, i32* null)
%51 = call i32 @sigtimedwait(i32* %10, i32* null, %struct.timespec* %11)
switch i32 %51, label %55 [
i32 128, label %52
i32 -1, label %53
]
52: ; preds = %47
store i32 0, i32* %3
br label %56
53: ; preds = %47
%54 = load i32, i32* @errno
store i32 %54, i32* %3
br label %56
55: ; preds = %47
store i32 1, i32* %3
br label %56
56: ; preds = %55, %53, %52, %45, %16
%57 = load i32, i32* %3
ret i32 %57
}

LLVM IR (-O2):
%struct.timespec = type { i64, i64 }
@.str = [27 x i8] c"LIGHTSM_X11_SERVER_CMDLINE\00"
@__const.main.time = %struct.timespec { i64 60, i64 0 }
@EINVAL = global i32 0
@.str.1 = [2 x i8] c" \00"
@SIG_IGN = global i32 0
@ENOEXEC = global i32 0
@SIG_BLOCK = global i32 0
@errno = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [30 x i8*]
%4 = alloca i32
%5 = alloca %struct.timespec
%6 = bitcast [30 x i8*]* %3 to i8*
%7 = tail call i8* @getenv(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%8 = bitcast i32* %4 to i8*
%9 = bitcast %struct.timespec* %5 to i8*
%10 = icmp eq i8* %7, null
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = load i32, i32* @EINVAL
br label %46
13: ; preds = %2
%14 = tail call i32 (...) @fork()
switch i32 %14, label %38 [
i32 0, label %15
i32 -1, label %36
]
15: ; preds = %13
%16 = tail call i8* @strtok(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%17 = icmp eq i8* %16, null
br i1 %17, label %28, label %18
18: ; preds = %15, %18
%19 = phi i64 [ %22, %18 ], [ 0, %15 ]
%20 = phi i8* [ %24, %18 ], [ %16, %15 ]
%21 = tail call i8* @strdup(i8* %20)
%22 = add nuw i64 %19, 1
%23 = getelementptr inbounds [30 x i8*], [30 x i8*]* %3, i64 0, i64 %19
store i8* %21, i8** %23
%24 = tail call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%25 = icmp eq i8* %24, null
br i1 %25, label %26, label %18
26: ; preds = %18
%27 = and i64 %22, 4294967295
br label %28
28: ; preds = %26, %15
%29 = phi i64 [ 0, %15 ], [ %27, %26 ]
%30 = getelementptr inbounds [30 x i8*], [30 x i8*]* %3, i64 0, i64 %29
store i8* null, i8** %30
%31 = load i32, i32* @SIG_IGN
%32 = tail call i32 @signal(i32 128, i32 %31)
%33 = getelementptr inbounds [30 x i8*], [30 x i8*]* %3, i64 0, i64 0
%34 = load i8*, i8** %33
%35 = call i32 @execv(i8* %34, i8** %33)
br label %36
36: ; preds = %13, %28
%37 = load i32, i32* @ENOEXEC
br label %46
38: ; preds = %13
%39 = call i32 @sigfillset(i32* %4)
%40 = load i32, i32* @SIG_BLOCK
%41 = call i32 @sigprocmask(i32 %40, i32* %4, i32* null)
%42 = call i32 @sigtimedwait(i32* %4, i32* null, %struct.timespec* %5)
switch i32 %42, label %45 [
i32 128, label %46
i32 -1, label %43
]
43: ; preds = %38
%44 = load i32, i32* @errno
br label %46
45: ; preds = %38
br label %46
46: ; preds = %38, %45, %43, %36, %11
%47 = phi i32 [ 1, %45 ], [ %44, %43 ], [ %37, %36 ], [ %12, %11 ], [ 0, %38 ]
ret i32 %47
}