#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*/ execl(char *, char *, char *);
scalar_t__ fork();
int /*<<< orphan*/ info(char *, scalar_t__);
int /*<<< orphan*/ perror(char *);
int exec(char *filename) {
  pid_t pid = fork();
  if (pid < 0) {
    perror("Can not fork.");
    return -1;
  }
  if (pid > 0) {
    info("Executed: %d", pid);
    return pid;
  }
  execl(filename, filename, (char *)NULL);
  perror("execl");
  return -1;
}


x86 assembly (clang, -O0):
<exec>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    $0x0,%al
call   1050 <fork@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jge    117a <exec+0x3a>
lea    0xe97(%rip),%rdi
call   1030 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c5 <exec+0x85>
cmpq   $0x0,-0x18(%rbp)
jle    11a1 <exec+0x61>
mov    -0x18(%rbp),%rsi
lea    0xe7e(%rip),%rdi
call   1060 <info@plt>
mov    -0x18(%rbp),%rax
mov    %eax,-0x4(%rbp)
jmp    11c5 <exec+0x85>
mov    -0x10(%rbp),%rdi
mov    -0x10(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1040 <execl@plt>
lea    0xe62(%rip),%rdi
call   1030 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<exec>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
xor    %eax,%eax
call   1050 <fork@plt>
test   %rax,%rax
js     1171 <exec+0x31>
je     117a <exec+0x3a>
mov    %rax,%rbx
lea    0xeaf(%rip),%rdi
mov    %rax,%rsi
call   1060 <info@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe88(%rip),%rdi
jmp    118e <exec+0x4e>
mov    %r14,%rdi
mov    %r14,%rsi
xor    %edx,%edx
call   1040 <execl@plt>
lea    0xe8d(%rip),%rdi
call   1030 <perror@plt>
mov    $0xffffffff,%ebx
jmp    1167 <exec+0x27>

LLVM IR (-O0):
@.str = [14 x i8] c"Can not fork.\00"
@.str.1 = [13 x i8] c"Executed: %d\00"
@.str.2 = [6 x i8] c"execl\00"
define i32 @exec(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i64
store i8* %0, i8** %3
%5 = call i64 (...) @fork()
store i64 %5, i64* %4
%6 = load i64, i64* %4
%7 = icmp slt i64 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %1
%9 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %2
br label %23
10: ; preds = %1
%11 = load i64, i64* %4
%12 = icmp sgt i64 %11, 0
br i1 %12, label %13, label %18
13: ; preds = %10
%14 = load i64, i64* %4
%15 = call i32 @info(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i64 %14)
%16 = load i64, i64* %4
%17 = trunc i64 %16 to i32
store i32 %17, i32* %2
br label %23
18: ; preds = %10
%19 = load i8*, i8** %3
%20 = load i8*, i8** %3
%21 = call i32 @execl(i8* %19, i8* %20, i8* null)
%22 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %2
br label %23
23: ; preds = %18, %13, %8
%24 = load i32, i32* %2
ret i32 %24
}

LLVM IR (-O2):
@.str = [14 x i8] c"Can not fork.\00"
@.str.1 = [13 x i8] c"Executed: %d\00"
@.str.2 = [6 x i8] c"execl\00"
define i32 @exec(i8* %0) {
%2 = tail call i64 (...) @fork()
%3 = icmp slt i64 %2, 0
br i1 %3, label %4, label %6
4: ; preds = %1
%5 = tail call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %14
6: ; preds = %1
%7 = icmp eq i64 %2, 0
br i1 %7, label %11, label %8
8: ; preds = %6
%9 = tail call i32 @info(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i64 %2)
%10 = trunc i64 %2 to i32
br label %14
11: ; preds = %6
%12 = tail call i32 @execl(i8* %0, i8* %0, i8* null)
%13 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
br label %14
14: ; preds = %11, %8, %4
%15 = phi i32 [ -1, %4 ], [ %10, %8 ], [ -1, %11 ]
ret i32 %15
}