#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 errno;
int /*<<< orphan*/ execve(char *, char **, char **);
int /*<<< orphan*/ exit(int);
int fork();
int /*<<< orphan*/ print_time();
int /*<<< orphan*/ printf(char *, ...);
char *strerror(int);
int cron_job(char **argv, char **environ) {
  int i;
  int pid;
  print_time();
  printf("cron_job_do : ");
  for (i = 0; argv[i] != NULL; i++) {
    printf("[%s]", argv[i]);
  }
  pid = fork();
  if (pid == -1) {
    printf(" : fork_error : %s (%d)\n", strerror(errno), errno);
  } else if (pid == 0) {
    execve(argv[0], argv, environ);
    printf(" : exec_error : %s (%d)\n", strerror(errno), errno);
    exit(127);
  } else {
    printf(" : OK pid %d\n", pid);
  }
  return pid;
}


x86 assembly (clang, -O0):
<cron_job>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   1050 <print_time@plt>
lea    0xe82(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
je     11c7 <cron_job+0x67>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
lea    0xe5d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    118c <cron_job+0x2c>
mov    $0x0,%al
call   1080 <fork@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    1208 <cron_job+0xa8>
mov    0x2dfe(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    %rax,%rsi
mov    0x2ded(%rip),%rax
mov    (%rax),%edx
lea    0xe18(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    126e <cron_job+0x10e>
cmpl   $0x0,-0x18(%rbp)
jne    1258 <cron_job+0xf8>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rdx
call   1040 <execve@plt>
mov    0x2db3(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    %rax,%rsi
mov    0x2da2(%rip),%rax
mov    (%rax),%edx
lea    0xde6(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x7f,%edi
call   1060 <exit@plt>
mov    -0x18(%rbp),%esi
lea    0xde4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    126e <cron_job+0x10e>
mov    -0x18(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cron_job>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
xor    %eax,%eax
call   1050 <print_time@plt>
lea    0xe85(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    (%r15),%rsi
test   %rsi,%rsi
je     11b6 <cron_job+0x56>
lea    0x8(%r15),%rbx
lea    0xe7a(%rip),%rbp
cs nopw 0x0(%rax,%rax,1)
nop
mov    %rbp,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    (%rbx),%rsi
add    $0x8,%rbx
test   %rsi,%rsi
jne    11a0 <cron_job+0x40>
xor    %eax,%eax
call   1080 <fork@plt>
mov    %eax,%ebp
cmp    $0xffffffff,%eax
je     11da <cron_job+0x7a>
test   %ebp,%ebp
je     1208 <cron_job+0xa8>
lea    0xe77(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1030 <printf@plt>
jmp    11fb <cron_job+0x9b>
mov    0x2dff(%rip),%rbx
mov    (%rbx),%edi
call   1070 <strerror@plt>
mov    (%rbx),%edx
lea    0xe23(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    (%r15),%rdi
mov    %r15,%rsi
mov    %r14,%rdx
call   1040 <execve@plt>
mov    0x2dc3(%rip),%rbx
mov    (%rbx),%edi
call   1070 <strerror@plt>
mov    (%rbx),%edx
lea    0xe00(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0x7f,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [15 x i8] c"cron_job_do : \00"
@.str.1 = [5 x i8] c"[%s]\00"
@.str.2 = [25 x i8] c" : fork_error : %s (%d)\0A\00"
@errno = global i32 0
@.str.3 = [25 x i8] c" : exec_error : %s (%d)\0A\00"
@.str.4 = [14 x i8] c" : OK pid %d\0A\00"
define i32 @cron_job(i8** %0, i8** %1) {
%3 = alloca i8**
%4 = alloca i8**
%5 = alloca i32
%6 = alloca i32
store i8** %0, i8*** %3
store i8** %1, i8*** %4
%7 = call i32 (...) @print_time()
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %5
br label %9
9: ; preds = %23, %2
%10 = load i8**, i8*** %3
%11 = load i32, i32* %5
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds i8*, i8** %10, i64 %12
%14 = load i8*, i8** %13
%15 = icmp ne i8* %14, null
br i1 %15, label %16, label %26
16: ; preds = %9
%17 = load i8**, i8*** %3
%18 = load i32, i32* %5
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i8*, i8** %17, i64 %19
%21 = load i8*, i8** %20
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %21)
br label %23
23: ; preds = %16
%24 = load i32, i32* %5
%25 = add nsw i32 %24, 1
store i32 %25, i32* %5
br label %9
26: ; preds = %9
%27 = call i32 (...) @fork()
store i32 %27, i32* %6
%28 = load i32, i32* %6
%29 = icmp eq i32 %28, -1
br i1 %29, label %30, label %35
30: ; preds = %26
%31 = load i32, i32* @errno
%32 = call i8* @strerror(i32 %31)
%33 = load i32, i32* @errno
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i8* %32, i32 %33)
br label %54
35: ; preds = %26
%36 = load i32, i32* %6
%37 = icmp eq i32 %36, 0
br i1 %37, label %38, label %50
38: ; preds = %35
%39 = load i8**, i8*** %3
%40 = getelementptr inbounds i8*, i8** %39, i64 0
%41 = load i8*, i8** %40
%42 = load i8**, i8*** %3
%43 = load i8**, i8*** %4
%44 = call i32 @execve(i8* %41, i8** %42, i8** %43)
%45 = load i32, i32* @errno
%46 = call i8* @strerror(i32 %45)
%47 = load i32, i32* @errno
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i8* %46, i32 %47)
%49 = call i32 @exit(i32 127)
unreachable
50: ; preds = %35
%51 = load i32, i32* %6
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0), i32 %51)
br label %53
53: ; preds = %50
br label %54
54: ; preds = %53, %30
%55 = load i32, i32* %6
ret i32 %55
}

LLVM IR (-O2):
@.str = [15 x i8] c"cron_job_do : \00"
@.str.1 = [5 x i8] c"[%s]\00"
@.str.2 = [25 x i8] c" : fork_error : %s (%d)\0A\00"
@errno = global i32 0
@.str.3 = [25 x i8] c" : exec_error : %s (%d)\0A\00"
@.str.4 = [14 x i8] c" : OK pid %d\0A\00"
define i32 @cron_job(i8** %0, i8** %1) {
%3 = tail call i32 (...) @print_time()
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%5 = load i8*, i8** %0
%6 = icmp eq i8* %5, null
br i1 %6, label %15, label %7
7: ; preds = %2, %7
%8 = phi i64 [ %11, %7 ], [ 0, %2 ]
%9 = phi i8* [ %13, %7 ], [ %5, %2 ]
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %9)
%11 = add nuw i64 %8, 1
%12 = getelementptr inbounds i8*, i8** %0, i64 %11
%13 = load i8*, i8** %12
%14 = icmp eq i8* %13, null
br i1 %14, label %15, label %7
15: ; preds = %7, %2
%16 = tail call i32 (...) @fork()
switch i32 %16, label %30 [
i32 -1, label %17
i32 0, label %22
]
17: ; preds = %15
%18 = load i32, i32* @errno
%19 = tail call i8* @strerror(i32 %18)
%20 = load i32, i32* @errno
%21 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i8* %19, i32 %20)
br label %32
22: ; preds = %15
%23 = load i8*, i8** %0
%24 = tail call i32 @execve(i8* %23, i8** %0, i8** %1)
%25 = load i32, i32* @errno
%26 = tail call i8* @strerror(i32 %25)
%27 = load i32, i32* @errno
%28 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i8* %26, i32 %27)
%29 = tail call i32 @exit(i32 127)
unreachable
30: ; preds = %15
%31 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0), i32 %16)
br label %32
32: ; preds = %30, %17
ret i32 %16
}