#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 tms {
  int dummy;
};
typedef scalar_t__ pid_t;
typedef int /*<<< orphan*/ clock_t;

/* Variables and functions */
int /*<<< orphan*/ SIGINT;
int /*<<< orphan*/ SIGQUIT;
int /*<<< orphan*/ SIGTERM;
int /*<<< orphan*/ SIG_DFL;
int /*<<< orphan*/ SIG_IGN;
scalar_t__ WEXITSTATUS(int);
scalar_t__ WIFEXITED(int);
int /*<<< orphan*/ execvp(char *, char **);
scalar_t__ fork();
char *getenv(char *);
char *glue(char **, int, int);
int /*<<< orphan*/ print_time(int /*<<< orphan*/, struct tms);
int /*<<< orphan*/ signal(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ times(struct tms *);
int /*<<< orphan*/ wait(int *);
int main(int argc, char **argv) {
  if (argc < 2)
    return 1;
  struct tms start;
  int state = 0;
  clock_t before = times(&start);
  pid_t pid = fork();
  if (pid > 0) {
    signal(SIGINT, SIG_IGN);
    signal(SIGTERM, SIG_IGN);
    signal(SIGQUIT, SIG_IGN);
    wait(&state);
    signal(SIGINT, SIG_DFL);
    signal(SIGTERM, SIG_DFL);
    signal(SIGQUIT, SIG_DFL);
    print_time(before, start);
  } else {
    char *args[] = {"sh", "-c", NULL, NULL};
    args[2] = glue(argv, 1, argc);
    if (getenv("SHELL"))
      args[0] = getenv("SHELL");
    execvp(args[0], args);
    return 1;
  }
  if (WIFEXITED(state) && WEXITSTATUS(state) != 0)
    return 1;
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    11cc <main+0x2c>
movl   $0x1,-0x4(%rbp)
jmp    134f <main+0x1af>
movl   $0x0,-0x1c(%rbp)
lea    -0x18(%rbp),%rdi
call   1080 <times@plt>
mov    %eax,-0x20(%rbp)
mov    $0x0,%al
call   10c0 <fork@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jle    1298 <main+0xf8>
mov    0x2de4(%rip),%rax
mov    (%rax),%edi
mov    0x2dc3(%rip),%rax
mov    (%rax),%esi
call   1040 <signal@plt>
mov    0x2dc5(%rip),%rax
mov    (%rax),%edi
mov    0x2dac(%rip),%rax
mov    (%rax),%esi
call   1040 <signal@plt>
mov    0x2da6(%rip),%rax
mov    (%rax),%edi
mov    0x2d95(%rip),%rax
mov    (%rax),%esi
call   1040 <signal@plt>
lea    -0x1c(%rbp),%rdi
call   10b0 <wait@plt>
mov    0x2d96(%rip),%rax
mov    (%rax),%edi
mov    0x2d65(%rip),%rax
mov    (%rax),%esi
call   1040 <signal@plt>
mov    0x2d77(%rip),%rax
mov    (%rax),%edi
mov    0x2d4e(%rip),%rax
mov    (%rax),%esi
call   1040 <signal@plt>
mov    0x2d58(%rip),%rax
mov    (%rax),%edi
mov    0x2d37(%rip),%rax
mov    (%rax),%esi
call   1040 <signal@plt>
mov    -0x20(%rbp),%edi
mov    -0x18(%rbp),%esi
call   1070 <print_time@plt>
jmp    1318 <main+0x178>
mov    0x2b31(%rip),%rax
mov    %rax,-0x50(%rbp)
mov    0x2b2e(%rip),%rax
mov    %rax,-0x48(%rbp)
mov    0x2b2b(%rip),%rax
mov    %rax,-0x40(%rbp)
mov    0x2b28(%rip),%rax
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%edx
mov    $0x1,%esi
call   1050 <glue@plt>
mov    %rax,-0x40(%rbp)
lea    0xd26(%rip),%rdi
call   1030 <getenv@plt>
cmp    $0x0,%rax
je     12ff <main+0x15f>
lea    0xd10(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x50(%rbp)
mov    -0x50(%rbp),%rdi
lea    -0x50(%rbp),%rsi
call   1090 <execvp@plt>
movl   $0x1,-0x4(%rbp)
jmp    134f <main+0x1af>
mov    -0x1c(%rbp),%edi
call   10a0 <WIFEXITED@plt>
cmp    $0x0,%rax
je     1348 <main+0x1a8>
mov    -0x1c(%rbp),%edi
call   1060 <WEXITSTATUS@plt>
cmp    $0x0,%rax
je     1348 <main+0x1a8>
movl   $0x1,-0x4(%rbp)
jmp    134f <main+0x1af>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x30,%rsp
mov    $0x1,%ebx
cmp    $0x2,%edi
jl     12e1 <main+0x141>
mov    %rsi,%r14
mov    %edi,%ebp
movl   $0x0,0x4(%rsp)
lea    0x8(%rsp),%rdi
call   1080 <times@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   10c0 <fork@plt>
test   %rax,%rax
jle    1284 <main+0xe4>
mov    0x2df6(%rip),%r14
mov    (%r14),%edi
mov    0x2dd4(%rip),%rbp
mov    0x0(%rbp),%esi
call   1040 <signal@plt>
mov    0x2dd5(%rip),%r15
mov    (%r15),%edi
mov    0x0(%rbp),%esi
call   1040 <signal@plt>
mov    0x2dbb(%rip),%r12
mov    (%r12),%edi
mov    0x0(%rbp),%esi
call   1040 <signal@plt>
lea    0x4(%rsp),%rdi
call   10b0 <wait@plt>
mov    (%r14),%edi
mov    0x2d83(%rip),%rbp
mov    0x0(%rbp),%esi
call   1040 <signal@plt>
mov    (%r15),%edi
mov    0x0(%rbp),%esi
call   1040 <signal@plt>
mov    (%r12),%edi
mov    0x0(%rbp),%esi
call   1040 <signal@plt>
mov    0x8(%rsp),%esi
mov    %ebx,%edi
call   1070 <print_time@plt>
mov    0x4(%rsp),%edi
call   10a0 <WIFEXITED@plt>
test   %rax,%rax
je     1280 <main+0xe0>
mov    0x4(%rsp),%edi
call   1060 <WEXITSTATUS@plt>
mov    $0x1,%ebx
test   %rax,%rax
jne    12e1 <main+0x141>
xor    %ebx,%ebx
jmp    12e1 <main+0x141>
movaps 0x2b55(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movaps 0x2b39(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
mov    $0x1,%ebx
mov    %r14,%rdi
mov    $0x1,%esi
mov    %ebp,%edx
call   1050 <glue@plt>
mov    %rax,0x20(%rsp)
lea    0xd4a(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     12cd <main+0x12d>
mov    %rax,0x10(%rsp)
jmp    12d4 <main+0x134>
lea    0xd2c(%rip),%rax
lea    0x10(%rsp),%rsi
mov    %rax,%rdi
call   1090 <execvp@plt>
mov    %ebx,%eax
add    $0x30,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.tms = type { i32 }
@SIGINT = global i32 0
@SIG_IGN = global i32 0
@SIGTERM = global i32 0
@SIGQUIT = global i32 0
@SIG_DFL = global i32 0
@.str = [3 x i8] c"sh\00"
@.str.1 = [3 x i8] c"-c\00"
@__const.main.args = [4 x i8*] [i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i32 0, i32 0), i8* null, i8* null]
@.str.2 = [6 x i8] c"SHELL\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.tms
%7 = alloca i32
%8 = alloca i32
%9 = alloca i64
%10 = alloca [4 x i8*]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* %4
%12 = icmp slt i32 %11, 2
br i1 %12, label %13, label %14
13: ; preds = %2
store i32 1, i32* %3
br label %69
14: ; preds = %2
store i32 0, i32* %7
%15 = call i32 @times(%struct.tms* %6)
store i32 %15, i32* %8
%16 = call i64 (...) @fork()
store i64 %16, i64* %9
%17 = load i64, i64* %9
%18 = icmp sgt i64 %17, 0
br i1 %18, label %19, label %43
19: ; preds = %14
%20 = load i32, i32* @SIGINT
%21 = load i32, i32* @SIG_IGN
%22 = call i32 @signal(i32 %20, i32 %21)
%23 = load i32, i32* @SIGTERM
%24 = load i32, i32* @SIG_IGN
%25 = call i32 @signal(i32 %23, i32 %24)
%26 = load i32, i32* @SIGQUIT
%27 = load i32, i32* @SIG_IGN
%28 = call i32 @signal(i32 %26, i32 %27)
%29 = call i32 @wait(i32* %7)
%30 = load i32, i32* @SIGINT
%31 = load i32, i32* @SIG_DFL
%32 = call i32 @signal(i32 %30, i32 %31)
%33 = load i32, i32* @SIGTERM
%34 = load i32, i32* @SIG_DFL
%35 = call i32 @signal(i32 %33, i32 %34)
%36 = load i32, i32* @SIGQUIT
%37 = load i32, i32* @SIG_DFL
%38 = call i32 @signal(i32 %36, i32 %37)
%39 = load i32, i32* %8
%40 = getelementptr inbounds %struct.tms, %struct.tms* %6, i32 0, i32 0
%41 = load i32, i32* %40
%42 = call i32 @print_time(i32 %39, i32 %41)
br label %59
43: ; preds = %14
%44 = bitcast [4 x i8*]* %10 to i8*
%45 = load i8**, i8*** %5
%46 = load i32, i32* %4
%47 = call i8* @glue(i8** %45, i32 1, i32 %46)
%48 = getelementptr inbounds [4 x i8*], [4 x i8*]* %10, i64 0, i64 2
store i8* %47, i8** %48
%49 = call i8* @getenv(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%50 = icmp ne i8* %49, null
br i1 %50, label %51, label %54
51: ; preds = %43
%52 = call i8* @getenv(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%53 = getelementptr inbounds [4 x i8*], [4 x i8*]* %10, i64 0, i64 0
store i8* %52, i8** %53
br label %54
54: ; preds = %51, %43
%55 = getelementptr inbounds [4 x i8*], [4 x i8*]* %10, i64 0, i64 0
%56 = load i8*, i8** %55
%57 = getelementptr inbounds [4 x i8*], [4 x i8*]* %10, i64 0, i64 0
%58 = call i32 @execvp(i8* %56, i8** %57)
store i32 1, i32* %3
br label %69
59: ; preds = %19
%60 = load i32, i32* %7
%61 = call i64 @WIFEXITED(i32 %60)
%62 = icmp ne i64 %61, 0
br i1 %62, label %63, label %68
63: ; preds = %59
%64 = load i32, i32* %7
%65 = call i64 @WEXITSTATUS(i32 %64)
%66 = icmp ne i64 %65, 0
br i1 %66, label %67, label %68
67: ; preds = %63
store i32 1, i32* %3
br label %69
68: ; preds = %63, %59
store i32 0, i32* %3
br label %69
69: ; preds = %68, %67, %54, %13
%70 = load i32, i32* %3
ret i32 %70
}

LLVM IR (-O2):
%struct.tms = type { i32 }
@SIGINT = global i32 0
@SIG_IGN = global i32 0
@SIGTERM = global i32 0
@SIGQUIT = global i32 0
@SIG_DFL = global i32 0
@.str = [3 x i8] c"sh\00"
@.str.1 = [3 x i8] c"-c\00"
@__const.main.args = [4 x i8*] [i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i32 0, i32 0), i8* null, i8* null]
@.str.2 = [6 x i8] c"SHELL\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca %struct.tms
%4 = alloca i32
%5 = alloca [4 x i8*]
%6 = icmp slt i32 %0, 2
br i1 %6, label %58, label %7
7: ; preds = %2
%8 = bitcast %struct.tms* %3 to i8*
%9 = bitcast i32* %4 to i8*
store i32 0, i32* %4
%10 = call i32 @times(%struct.tms* %3)
%11 = tail call i64 (...) @fork()
%12 = icmp sgt i64 %11, 0
br i1 %12, label %13, label %39
13: ; preds = %7
%14 = load i32, i32* @SIGINT
%15 = load i32, i32* @SIG_IGN
%16 = tail call i32 @signal(i32 %14, i32 %15)
%17 = load i32, i32* @SIGTERM
%18 = load i32, i32* @SIG_IGN
%19 = tail call i32 @signal(i32 %17, i32 %18)
%20 = load i32, i32* @SIGQUIT
%21 = load i32, i32* @SIG_IGN
%22 = tail call i32 @signal(i32 %20, i32 %21)
%23 = call i32 @wait(i32* %4)
%24 = load i32, i32* @SIGINT
%25 = load i32, i32* @SIG_DFL
%26 = call i32 @signal(i32 %24, i32 %25)
%27 = load i32, i32* @SIGTERM
%28 = load i32, i32* @SIG_DFL
%29 = call i32 @signal(i32 %27, i32 %28)
%30 = load i32, i32* @SIGQUIT
%31 = load i32, i32* @SIG_DFL
%32 = call i32 @signal(i32 %30, i32 %31)
%33 = getelementptr inbounds %struct.tms, %struct.tms* %3, i64 0, i32 0
%34 = load i32, i32* %33
%35 = call i32 @print_time(i32 %10, i32 %34)
%36 = load i32, i32* %4
%37 = call i64 @WIFEXITED(i32 %36)
%38 = icmp eq i64 %37, 0
br i1 %38, label %55, label %51
39: ; preds = %7
%40 = bitcast [4 x i8*]* %5 to i8*
%41 = tail call i8* @glue(i8** %1, i32 1, i32 %0)
%42 = getelementptr inbounds [4 x i8*], [4 x i8*]* %5, i64 0, i64 2
store i8* %41, i8** %42
%43 = tail call i8* @getenv(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%44 = icmp eq i8* %43, null
br i1 %44, label %47, label %45
45: ; preds = %39
%46 = getelementptr inbounds [4 x i8*], [4 x i8*]* %5, i64 0, i64 0
store i8* %43, i8** %46
br label %47
47: ; preds = %45, %39
%48 = phi i8* [ %43, %45 ], [ getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), %39 ]
%49 = getelementptr inbounds [4 x i8*], [4 x i8*]* %5, i64 0, i64 0
%50 = call i32 @execvp(i8* %48, i8** %49)
br label %56
51: ; preds = %13
%52 = load i32, i32* %4
%53 = call i64 @WEXITSTATUS(i32 %52)
%54 = icmp eq i64 %53, 0
br i1 %54, label %55, label %56
55: ; preds = %51, %13
br label %56
56: ; preds = %51, %55, %47
%57 = phi i32 [ 0, %55 ], [ 1, %47 ], [ 1, %51 ]
br label %58
58: ; preds = %2, %56
%59 = phi i32 [ %57, %56 ], [ 1, %2 ]
ret i32 %59
}