#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 execv(char *, char **);
int /*<<< orphan*/ printf(char *, ...);
void doBullshit(int argc, char **argv) {
  if (!argc) {
    printf("N-am foita sa rulez...\n");
    return;
  }
  printf("%s\n\n", argv[0]);
  argv[argc] = NULL;
  if (execv(argv[0], argv) == -1)
    printf("Shit happeded: %d\n", errno);
}


x86 assembly (clang, -O0):
<doBullshit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x0,-0x4(%rbp)
jne    114c <doBullshit+0x2c>
lea    0xec0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11a1 <doBullshit+0x81>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xebe(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rax
movslq -0x4(%rbp),%rcx
movq   $0x0,(%rax,%rcx,8)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <execv@plt>
cmp    $0xffffffff,%eax
jne    11a1 <doBullshit+0x81>
mov    0x2e4f(%rip),%rax
mov    (%rax),%esi
lea    0xe83(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<doBullshit>:
push   %rbp
push   %rbx
push   %rax
test   %edi,%edi
je     116f <doBullshit+0x3f>
mov    %rsi,%rbx
mov    %edi,%ebp
mov    (%rsi),%rsi
lea    0xeba(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
movslq %ebp,%rax
movq   $0x0,(%rbx,%rax,8)
mov    (%rbx),%rdi
mov    %rbx,%rsi
call   1050 <execv@plt>
cmp    $0xffffffff,%eax
je     1181 <doBullshit+0x51>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xea2(%rip),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1030 <puts@plt>
mov    0x2e58(%rip),%rax
mov    (%rax),%esi
lea    0xe74(%rip),%rdi
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1040 <printf@plt>

LLVM IR (-O0):
@.str = [24 x i8] c"N-am foita sa rulez...\0A\00"
@.str.1 = [5 x i8] c"%s\0A\0A\00"
@.str.2 = [19 x i8] c"Shit happeded: %d\0A\00"
@errno = global i32 0
define void @doBullshit(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
store i32 %0, i32* %3
store i8** %1, i8*** %4
%5 = load i32, i32* %3
%6 = icmp ne i32 %5, 0
br i1 %6, label %9, label %7
7: ; preds = %2
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
br label %27
9: ; preds = %2
%10 = load i8**, i8*** %4
%11 = getelementptr inbounds i8*, i8** %10, i64 0
%12 = load i8*, i8** %11
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %12)
%14 = load i8**, i8*** %4
%15 = load i32, i32* %3
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i8*, i8** %14, i64 %16
store i8* null, i8** %17
%18 = load i8**, i8*** %4
%19 = getelementptr inbounds i8*, i8** %18, i64 0
%20 = load i8*, i8** %19
%21 = load i8**, i8*** %4
%22 = call i32 @execv(i8* %20, i8** %21)
%23 = icmp eq i32 %22, -1
br i1 %23, label %24, label %27
24: ; preds = %9
%25 = load i32, i32* @errno
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i32 %25)
br label %27
27: ; preds = %7, %24, %9
ret void
}

LLVM IR (-O2):
@.str.1 = [5 x i8] c"%s\0A\0A\00"
@.str.2 = [19 x i8] c"Shit happeded: %d\0A\00"
@errno = global i32 0
@str = [23 x i8] c"N-am foita sa rulez...\00"
define void @doBullshit(i32 %0, i8** %1) {
%3 = icmp eq i32 %0, 0
br i1 %3, label %4, label %6
4: ; preds = %2
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str, i64 0, i64 0))
br label %17
6: ; preds = %2
%7 = load i8*, i8** %1
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %7)
%9 = sext i32 %0 to i64
%10 = getelementptr inbounds i8*, i8** %1, i64 %9
store i8* null, i8** %10
%11 = load i8*, i8** %1
%12 = tail call i32 @execv(i8* %11, i8** %1)
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %17
14: ; preds = %6
%15 = load i32, i32* @errno
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i32 %15)
br label %17
17: ; preds = %4, %14, %6
ret void
}