#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*/ O_WRONLY;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ err(int, char *);
int /*<<< orphan*/ execl(char const *, char *, int /*<<< orphan*/ *);
int open(char const *, int /*<<< orphan*/, int);
int read_file(int);
int /*<<< orphan*/ usage();
void do_exec_file(int argc, char *argv[]) {
  if (argc > 0)
    usage();
  const char *destname = "/tmp/execfile";
  int fid = open(destname, O_WRONLY, 0777);
  int len = read_file(fid);
  close(fid);
  if (len > 0) {
    execl(destname, "execfile", NULL);
    err(1, "execl failed!");
  }
}


x86 assembly (clang, -O0):
<do_exec_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x0,-0x4(%rbp)
jle    1180 <do_exec_file+0x20>
mov    $0x0,%al
call   1060 <usage@plt>
lea    0xe79(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    0x2e42(%rip),%rax
mov    (%rax),%esi
mov    $0x1ff,%edx
call   1070 <open@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%edi
call   1040 <read_file@plt>
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%edi
call   1030 <close@plt>
cmpl   $0x0,-0x20(%rbp)
jle    11e7 <do_exec_file+0x87>
mov    -0x18(%rbp),%rdi
lea    0xe38(%rip),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1080 <execl@plt>
mov    $0x1,%edi
lea    0xe2c(%rip),%rsi
call   1050 <err@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_exec_file>:
push   %rbp
push   %rbx
push   %rax
test   %edi,%edi
jle    116e <do_exec_file+0xe>
xor    %eax,%eax
call   1060 <usage@plt>
mov    0x2e63(%rip),%rax
mov    (%rax),%esi
lea    0xe82(%rip),%rdi
mov    $0x1ff,%edx
call   1070 <open@plt>
mov    %eax,%ebx
mov    %eax,%edi
call   1040 <read_file@plt>
mov    %eax,%ebp
mov    %ebx,%edi
call   1030 <close@plt>
test   %ebp,%ebp
jle    11ca <do_exec_file+0x6a>
lea    0xe5b(%rip),%rdi
lea    0xe59(%rip),%rsi
xor    %edx,%edx
call   1080 <execl@plt>
lea    0xe54(%rip),%rsi
mov    $0x1,%edi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1050 <err@plt>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [14 x i8] c"/tmp/execfile\00"
@O_WRONLY = global i32 0
@.str.1 = [9 x i8] c"execfile\00"
@.str.2 = [14 x i8] c"execl failed!\00"
define void @do_exec_file(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %3
store i8** %1, i8*** %4
%8 = load i32, i32* %3
%9 = icmp sgt i32 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %2
%11 = call i32 (...) @usage()
br label %12
12: ; preds = %10, %2
store i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8** %5
%13 = load i8*, i8** %5
%14 = load i32, i32* @O_WRONLY
%15 = call i32 @open(i8* %13, i32 %14, i32 511)
store i32 %15, i32* %6
%16 = load i32, i32* %6
%17 = call i32 @read_file(i32 %16)
store i32 %17, i32* %7
%18 = load i32, i32* %6
%19 = call i32 @close(i32 %18)
%20 = load i32, i32* %7
%21 = icmp sgt i32 %20, 0
br i1 %21, label %22, label %26
22: ; preds = %12
%23 = load i8*, i8** %5
%24 = call i32 @execl(i8* %23, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32* null)
%25 = call i32 @err(i32 1, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
br label %26
26: ; preds = %22, %12
ret void
}

LLVM IR (-O2):
@.str = [14 x i8] c"/tmp/execfile\00"
@O_WRONLY = global i32 0
@.str.1 = [9 x i8] c"execfile\00"
@.str.2 = [14 x i8] c"execl failed!\00"
define void @do_exec_file(i32 %0, i8** nocapture readnone %1) {
%3 = icmp sgt i32 %0, 0
br i1 %3, label %4, label %6
4: ; preds = %2
%5 = tail call i32 (...) @usage()
br label %6
6: ; preds = %4, %2
%7 = load i32, i32* @O_WRONLY
%8 = tail call i32 @open(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %7, i32 511)
%9 = tail call i32 @read_file(i32 %8)
%10 = tail call i32 @close(i32 %8)
%11 = icmp sgt i32 %9, 0
br i1 %11, label %12, label %15
12: ; preds = %6
%13 = tail call i32 @execl(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32* null)
%14 = tail call i32 @err(i32 1, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
br label %15
15: ; preds = %12, %6
ret void
}