#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 int /*<<< orphan*/ libucw_path;
typedef int /*<<< orphan*/ exec_path;

/* Variables and functions */
int PATH_MAX;
char *dirname(char *);
int /*<<< orphan*/ execvp(char *, char **);
int /*<<< orphan*/ get_self(char *, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ setenv(char *, char *, int);
int /*<<< orphan*/ snprintf(char *, int, char *, char *, char *);
int /*<<< orphan*/ usage();
int main(int argc, char *argv[]) {
  char exec_path[PATH_MAX];
  char *libdir;
  char libucw_path[PATH_MAX];
  if (argc <= 1) {
    usage();
    return 1;
  }
  get_self(exec_path, sizeof(exec_path));
  libdir = dirname(exec_path);
  snprintf(libucw_path, sizeof(libucw_path), "%s/../lib/ucw/%s", libdir,
           "${LIB}/libucw.so");
  setenv("LD_PRELOAD", libucw_path, 1);
  execvp(argv[1], &argv[1]);
  perror("Error executing command");
  return 1;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e63(%rip),%rax
mov    (%rax),%ecx
mov    %rcx,-0x58(%rbp)
mov    %rsp,%rdx
mov    %rdx,-0x18(%rbp)
mov    %rcx,%rsi
add    $0xf,%rsi
and    $0xfffffffffffffff0,%rsi
mov    %rsp,%rdx
sub    %rsi,%rdx
mov    %rdx,-0x50(%rbp)
mov    %rdx,%rsp
mov    %rcx,-0x20(%rbp)
mov    (%rax),%eax
mov    %rax,-0x48(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x40(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x30(%rbp)
cmpl   $0x1,-0x8(%rbp)
jg     11fc <main+0x8c>
mov    $0x0,%al
call   1070 <usage@plt>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x34(%rbp)
jmp    1280 <main+0x110>
mov    -0x50(%rbp),%rdi
mov    -0x58(%rbp),%rax
mov    %eax,%esi
call   1040 <get_self@plt>
mov    -0x50(%rbp),%rdi
call   1060 <dirname@plt>
mov    -0x40(%rbp),%rdi
mov    %rax,%rcx
mov    -0x48(%rbp),%rax
mov    %rcx,-0x28(%rbp)
mov    %eax,%esi
mov    -0x28(%rbp),%rcx
lea    0xdd0(%rip),%rdx
lea    0xdda(%rip),%r8
call   1050 <snprintf@plt>
mov    -0x40(%rbp),%rsi
lea    0xddb(%rip),%rdi
mov    $0x1,%edx
call   1030 <setenv@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x10(%rbp),%rsi
add    $0x8,%rsi
call   1090 <execvp@plt>
lea    0xdc0(%rip),%rdi
call   1080 <perror@plt>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x34(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    0x2e6e(%rip),%rax
mov    (%rax),%r15d
mov    %rsp,%rbx
lea    0xf(%r15),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %rsp,%r12
sub    %rax,%r12
mov    %r12,%rsp
cmp    $0x1,%edi
jg     11bd <main+0x4d>
xor    %eax,%eax
call   1070 <usage@plt>
mov    $0x1,%eax
lea    -0x20(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %rsi,%r14
mov    %rbx,%rdi
mov    %r15d,%esi
call   1040 <get_self@plt>
mov    %rbx,%rdi
call   1060 <dirname@plt>
lea    0xe26(%rip),%rdx
lea    0xe30(%rip),%r8
mov    %r12,%rdi
mov    %r15d,%esi
mov    %rax,%rcx
call   1050 <snprintf@plt>
lea    0xe2c(%rip),%rdi
mov    %r12,%rsi
mov    $0x1,%edx
call   1030 <setenv@plt>
mov    0x8(%r14),%rdi
add    $0x8,%r14
mov    %r14,%rsi
call   1090 <execvp@plt>
lea    0xe13(%rip),%rdi
call   1080 <perror@plt>
jmp    11ab <main+0x3b>

LLVM IR (-O0):
@PATH_MAX = global i32 0
@.str = [17 x i8] c"%s/../lib/ucw/%s\00"
@.str.1 = [17 x i8] c"${LIB}/libucw.so\00"
@.str.2 = [11 x i8] c"LD_PRELOAD\00"
@.str.3 = [24 x i8] c"Error executing command\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* @PATH_MAX
%12 = zext i32 %11 to i64
%13 = call i8* @llvm.stacksave()
store i8* %13, i8** %6
%14 = alloca i8, i64 %12
store i64 %12, i64* %7
%15 = load i32, i32* @PATH_MAX
%16 = zext i32 %15 to i64
%17 = alloca i8, i64 %16
store i64 %16, i64* %9
%18 = load i32, i32* %4
%19 = icmp sle i32 %18, 1
br i1 %19, label %20, label %22
20: ; preds = %2
%21 = call i32 (...) @usage()
store i32 1, i32* %3
store i32 1, i32* %10
br label %37
22: ; preds = %2
%23 = trunc i64 %12 to i32
%24 = call i32 @get_self(i8* %14, i32 %23)
%25 = call i8* @dirname(i8* %14)
store i8* %25, i8** %8
%26 = trunc i64 %16 to i32
%27 = load i8*, i8** %8
%28 = call i32 @snprintf(i8* %17, i32 %26, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %27, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
%29 = call i32 @setenv(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8* %17, i32 1)
%30 = load i8**, i8*** %5
%31 = getelementptr inbounds i8*, i8** %30, i64 1
%32 = load i8*, i8** %31
%33 = load i8**, i8*** %5
%34 = getelementptr inbounds i8*, i8** %33, i64 1
%35 = call i32 @execvp(i8* %32, i8** %34)
%36 = call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0))
store i32 1, i32* %3
store i32 1, i32* %10
br label %37
37: ; preds = %22, %20
%38 = load i8*, i8** %6
%39 = load i32, i32* %3
ret i32 %39
}

LLVM IR (-O2):
@PATH_MAX = global i32 0
@.str = [17 x i8] c"%s/../lib/ucw/%s\00"
@.str.1 = [17 x i8] c"${LIB}/libucw.so\00"
@.str.2 = [11 x i8] c"LD_PRELOAD\00"
@.str.3 = [24 x i8] c"Error executing command\00"
define i32 @main(i32 %0, i8** %1) {
%3 = load i32, i32* @PATH_MAX
%4 = zext i32 %3 to i64
%5 = alloca i8, i64 %4
%6 = alloca i8, i64 %4
%7 = icmp slt i32 %0, 2
br i1 %7, label %8, label %10
8: ; preds = %2
%9 = tail call i32 (...) @usage()
br label %19
10: ; preds = %2
%11 = call i32 @get_self(i8* %5, i32 %3)
%12 = call i8* @dirname(i8* %5)
%13 = call i32 @snprintf(i8* %6, i32 %3, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %12, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
%14 = call i32 @setenv(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8* %6, i32 1)
%15 = getelementptr inbounds i8*, i8** %1, i64 1
%16 = load i8*, i8** %15
%17 = call i32 @execvp(i8* %16, i8** %15)
%18 = call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0))
br label %19
19: ; preds = %10, %8
ret i32 1
}