#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*/ PTRACE_TRACEME;
int /*<<< orphan*/ execl(char *, char *, char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int ptrace(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/,
           int /*<<< orphan*/);
int do_something() {
  if (-1 == ptrace(PTRACE_TRACEME, 0, 0, 0)) {
    perror("PTRACE_TRACEME error");
    return -1;
  }
  execl("/bin/ls", "-l", "/", NULL);
  while (1)
    printf("\n\n################finished...!################\n");
  return 0;
}


x86 assembly (clang, -O0):
<do_something>:
push   %rbp
mov    %rsp,%rbp
mov    0x2e95(%rip),%rax
mov    (%rax),%edi
xor    %ecx,%ecx
mov    %ecx,%esi
mov    %ecx,%edx
call   1040 <ptrace@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    %ecx,%eax
jne    117a <do_something+0x3a>
lea    0xe92(%rip),%rdi
call   1050 <perror@plt>
mov    $0xffffffff,%eax
pop    %rbp
ret
lea    0xe94(%rip),%rdi
lea    0xe95(%rip),%rsi
lea    0xe91(%rip),%rdx
xor    %eax,%eax
mov    %eax,%ecx
call   1060 <execl@plt>
lea    0xe83(%rip),%rdi
call   1030 <printf@plt>
jmp    1198 <do_something+0x58>

x86 assembly (clang, -O2):
<do_something>:
push   %rbx
mov    0x2e98(%rip),%rax
mov    (%rax),%edi
xor    %esi,%esi
xor    %edx,%edx
xor    %ecx,%ecx
call   1040 <ptrace@plt>
cmp    $0xffffffff,%eax
je     118a <do_something+0x4a>
lea    0xeb4(%rip),%rdi
lea    0xeb5(%rip),%rsi
lea    0xeb1(%rip),%rdx
xor    %ecx,%ecx
call   1060 <execl@plt>
lea    0xea5(%rip),%rbx
nopl   (%rax)
mov    %rbx,%rdi
call   1030 <puts@plt>
jmp    1180 <do_something+0x40>
lea    0xe6f(%rip),%rdi
call   1050 <perror@plt>
mov    $0xffffffff,%eax
pop    %rbx
ret

LLVM IR (-O0):
@PTRACE_TRACEME = global i32 0
@.str = [21 x i8] c"PTRACE_TRACEME error\00"
@.str.1 = [8 x i8] c"/bin/ls\00"
@.str.2 = [3 x i8] c"-l\00"
@.str.3 = [2 x i8] c"/\00"
@.str.4 = [48 x i8] c"\0A\0A################finished...!################\0A\00"
define i32 @do_something() {
%1 = load i32, i32* @PTRACE_TRACEME
%2 = call i32 @ptrace(i32 %1, i32 0, i32 0, i32 0)
%3 = icmp eq i32 -1, %2
br i1 %3, label %4, label %6
4: ; preds = %0
%5 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
ret i32 -1
6: ; preds = %0
%7 = call i32 @execl(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), i32* null)
br label %8
8: ; preds = %6, %8
%9 = call i32 @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.4, i64 0, i64 0))
br label %8
}

LLVM IR (-O2):
@PTRACE_TRACEME = global i32 0
@.str = [21 x i8] c"PTRACE_TRACEME error\00"
@.str.1 = [8 x i8] c"/bin/ls\00"
@.str.2 = [3 x i8] c"-l\00"
@.str.3 = [2 x i8] c"/\00"
@str = [47 x i8] c"\0A\0A################finished...!################\00"
define i32 @do_something() {
%1 = load i32, i32* @PTRACE_TRACEME
%2 = tail call i32 @ptrace(i32 %1, i32 0, i32 0, i32 0)
%3 = icmp eq i32 %2, -1
br i1 %3, label %4, label %6
4: ; preds = %0
%5 = tail call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
ret i32 -1
6: ; preds = %0
%7 = tail call i32 @execl(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), i32* null)
br label %8
8: ; preds = %6, %8
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([47 x i8], [47 x i8]* @str, i64 0, i64 0))
br label %8
}