#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*/ PR_SET_NAME;
int /*<<< orphan*/ prctl(int /*<<< orphan*/, char const *);
void setprocname(const char *name, char *argv0) {
  prctl(PR_SET_NAME, name);
  while (*argv0 && *name)
    *argv0++ = *name++;
  while (*argv0)
    *argv0++ = 0;
}


x86 assembly (clang, -O0):
<setprocname>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2eb9(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rsi
call   1030 <prctl@plt>
mov    -0x10(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x11(%rbp)
je     1157 <setprocname+0x47>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
setne  %al
mov    %al,-0x11(%rbp)
mov    -0x11(%rbp),%al
test   $0x1,%al
jne    1167 <setprocname+0x57>
jmp    118e <setprocname+0x7e>
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
mov    (%rax),%cl
mov    -0x10(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x10(%rbp)
mov    %cl,(%rax)
jmp    1132 <setprocname+0x22>
jmp    1193 <setprocname+0x83>
mov    -0x10(%rbp),%rax
cmpb   $0x0,(%rax)
je     11b7 <setprocname+0xa7>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movb   $0x0,(%rax)
jmp    1193 <setprocname+0x83>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<setprocname>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r14
mov    0x2ebf(%rip),%rax
mov    (%rax),%edi
mov    %r14,%rsi
call   1030 <prctl@plt>
cmpb   $0x0,(%rbx)
je     116d <setprocname+0x5d>
add    $0x1,%rbx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movzbl (%r14),%eax
test   %al,%al
je     1160 <setprocname+0x50>
add    $0x1,%r14
mov    %al,-0x1(%rbx)
cmpb   $0x0,(%rbx)
lea    0x1(%rbx),%rbx
jne    1140 <setprocname+0x30>
jmp    116d <setprocname+0x5d>
nopw   0x0(%rax,%rax,1)
movb   $0x0,-0x1(%rbx)
cmpb   $0x0,(%rbx)
lea    0x1(%rbx),%rbx
jne    1160 <setprocname+0x50>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@PR_SET_NAME = global i32 0
define void @setprocname(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
store i8* %0, i8** %3
store i8* %1, i8** %4
%5 = load i32, i32* @PR_SET_NAME
%6 = load i8*, i8** %3
%7 = call i32 @prctl(i32 %5, i8* %6)
br label %8
8: ; preds = %20, %2
%9 = load i8*, i8** %4
%10 = load i8, i8* %9
%11 = sext i8 %10 to i32
%12 = icmp ne i32 %11, 0
br i1 %12, label %13, label %18
13: ; preds = %8
%14 = load i8*, i8** %3
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
%17 = icmp ne i32 %16, 0
br label %18
18: ; preds = %13, %8
%19 = phi i1 [ false, %8 ], [ %17, %13 ]
br i1 %19, label %20, label %26
20: ; preds = %18
%21 = load i8*, i8** %3
%22 = getelementptr inbounds i8, i8* %21, i32 1
store i8* %22, i8** %3
%23 = load i8, i8* %21
%24 = load i8*, i8** %4
%25 = getelementptr inbounds i8, i8* %24, i32 1
store i8* %25, i8** %4
store i8 %23, i8* %24
br label %8
26: ; preds = %18
br label %27
27: ; preds = %31, %26
%28 = load i8*, i8** %4
%29 = load i8, i8* %28
%30 = icmp ne i8 %29, 0
br i1 %30, label %31, label %34
31: ; preds = %27
%32 = load i8*, i8** %4
%33 = getelementptr inbounds i8, i8* %32, i32 1
store i8* %33, i8** %4
store i8 0, i8* %32
br label %27
34: ; preds = %27
ret void
}

LLVM IR (-O2):
@PR_SET_NAME = global i32 0
define void @setprocname(i8* %0, i8* nocapture %1) {
%3 = load i32, i32* @PR_SET_NAME
%4 = tail call i32 @prctl(i32 %3, i8* %0)
%5 = load i8, i8* %1
%6 = icmp eq i8 %5, 0
br i1 %6, label %22, label %7
7: ; preds = %2, %12
%8 = phi i8* [ %14, %12 ], [ %1, %2 ]
%9 = phi i8* [ %13, %12 ], [ %0, %2 ]
%10 = load i8, i8* %9
%11 = icmp eq i8 %10, 0
br i1 %11, label %17, label %12
12: ; preds = %7
%13 = getelementptr inbounds i8, i8* %9, i64 1
%14 = getelementptr inbounds i8, i8* %8, i64 1
store i8 %10, i8* %8
%15 = load i8, i8* %14
%16 = icmp eq i8 %15, 0
br i1 %16, label %22, label %7
17: ; preds = %7, %17
%18 = phi i8* [ %19, %17 ], [ %8, %7 ]
%19 = getelementptr inbounds i8, i8* %18, i64 1
store i8 0, i8* %18
%20 = load i8, i8* %19
%21 = icmp eq i8 %20, 0
br i1 %21, label %22, label %17
22: ; preds = %12, %17, %2
ret void
}