#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*/ u_char;

/* Variables and functions */
int /*<<< orphan*/ memcpy(char *, char const *, size_t);
int /*<<< orphan*/ memset(char *, char, size_t);
int /*<<< orphan*/ smp_cpy_environs();
int /*<<< orphan*/ smp_init_set_proc_title(int, char **);
int /*<<< orphan*/ smp_reset_proc_titel(int /*<<< orphan*/ *, size_t, int,
                                        char **);
size_t strlen(char const *);
int smp_set_proc_titel(const char *title, int argc, char **argv) {
  size_t tlen = 0;
  if (title == NULL)
    return (-1);
  tlen = strlen(title);
  if (tlen <= strlen(argv[0])) {
    memset(argv[0], '\0', strlen(argv[0]));
    memcpy(argv[0], title, tlen);
    return (0);
  }
  smp_init_set_proc_title(argc, argv);
  smp_cpy_environs();
  smp_reset_proc_titel((u_char *)title, tlen, argc, argv);
  return (0);
}


x86 assembly (clang, -O0):
<smp_set_proc_titel>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1192 <smp_set_proc_titel+0x32>
movl   $0xffffffff,-0x4(%rbp)
jmp    1236 <smp_set_proc_titel+0xd6>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rax
mov    (%rax),%rdi
call   1030 <strlen@plt>
mov    %rax,%rcx
mov    -0x30(%rbp),%rax
cmp    %rcx,%rax
ja     1208 <smp_set_proc_titel+0xa8>
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x38(%rbp)
mov    -0x20(%rbp),%rax
mov    (%rax),%rdi
call   1030 <strlen@plt>
mov    -0x38(%rbp),%rdi
mov    %rax,%rdx
xor    %esi,%esi
call   1040 <memset@plt>
mov    -0x20(%rbp),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1060 <memcpy@plt>
movl   $0x0,-0x4(%rbp)
jmp    1236 <smp_set_proc_titel+0xd6>
mov    -0x14(%rbp),%edi
mov    -0x20(%rbp),%rsi
call   1050 <smp_init_set_proc_title@plt>
mov    $0x0,%al
call   1070 <smp_cpy_environs@plt>
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x14(%rbp),%edx
mov    -0x20(%rbp),%rcx
call   1080 <smp_reset_proc_titel@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<smp_set_proc_titel>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %rdi,%rdi
je     11b9 <smp_set_proc_titel+0x59>
mov    %rdx,%r14
mov    %esi,%r12d
mov    %rdi,%rbx
call   1030 <strlen@plt>
mov    %rax,%r15
mov    (%r14),%rbp
mov    %rbp,%rdi
call   1030 <strlen@plt>
cmp    %rax,%r15
jbe    11c1 <smp_set_proc_titel+0x61>
mov    %r12d,%edi
mov    %r14,%rsi
call   1050 <smp_init_set_proc_title@plt>
xor    %r13d,%r13d
xor    %eax,%eax
call   1070 <smp_cpy_environs@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r12d,%edx
mov    %r14,%rcx
call   1080 <smp_reset_proc_titel@plt>
jmp    11df <smp_set_proc_titel+0x7f>
mov    $0xffffffff,%r13d
jmp    11df <smp_set_proc_titel+0x7f>
xor    %r13d,%r13d
mov    %rbp,%rdi
xor    %esi,%esi
mov    %rax,%rdx
call   1040 <memset@plt>
mov    (%r14),%rdi
mov    %rbx,%rsi
mov    %r15,%rdx
call   1060 <memcpy@plt>
mov    %r13d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @smp_set_proc_titel(i8* %0, i32 %1, i8** %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8**
%8 = alloca i64
store i8* %0, i8** %5
store i32 %1, i32* %6
store i8** %2, i8*** %7
store i64 0, i64* %8
%9 = load i8*, i8** %5
%10 = icmp eq i8* %9, null
br i1 %10, label %11, label %12
11: ; preds = %3
store i32 -1, i32* %4
br label %47
12: ; preds = %3
%13 = load i8*, i8** %5
%14 = call i64 @strlen(i8* %13)
store i64 %14, i64* %8
%15 = load i64, i64* %8
%16 = load i8**, i8*** %7
%17 = getelementptr inbounds i8*, i8** %16, i64 0
%18 = load i8*, i8** %17
%19 = call i64 @strlen(i8* %18)
%20 = icmp ule i64 %15, %19
br i1 %20, label %21, label %36
21: ; preds = %12
%22 = load i8**, i8*** %7
%23 = getelementptr inbounds i8*, i8** %22, i64 0
%24 = load i8*, i8** %23
%25 = load i8**, i8*** %7
%26 = getelementptr inbounds i8*, i8** %25, i64 0
%27 = load i8*, i8** %26
%28 = call i64 @strlen(i8* %27)
%29 = call i32 @memset(i8* %24, i8 signext 0, i64 %28)
%30 = load i8**, i8*** %7
%31 = getelementptr inbounds i8*, i8** %30, i64 0
%32 = load i8*, i8** %31
%33 = load i8*, i8** %5
%34 = load i64, i64* %8
%35 = call i32 @memcpy(i8* %32, i8* %33, i64 %34)
store i32 0, i32* %4
br label %47
36: ; preds = %12
%37 = load i32, i32* %6
%38 = load i8**, i8*** %7
%39 = call i32 @smp_init_set_proc_title(i32 %37, i8** %38)
%40 = call i32 (...) @smp_cpy_environs()
%41 = load i8*, i8** %5
%42 = bitcast i8* %41 to i32*
%43 = load i64, i64* %8
%44 = load i32, i32* %6
%45 = load i8**, i8*** %7
%46 = call i32 @smp_reset_proc_titel(i32* %42, i64 %43, i32 %44, i8** %45)
store i32 0, i32* %4
br label %47
47: ; preds = %36, %21, %11
%48 = load i32, i32* %4
ret i32 %48
}

LLVM IR (-O2):
define i32 @smp_set_proc_titel(i8* %0, i32 %1, i8** %2) {
%4 = icmp eq i8* %0, null
br i1 %4, label %19, label %5
5: ; preds = %3
%6 = tail call i64 @strlen(i8* %0)
%7 = load i8*, i8** %2
%8 = tail call i64 @strlen(i8* dereferenceable(1) %7)
%9 = icmp ugt i64 %6, %8
br i1 %9, label %14, label %10
10: ; preds = %5
%11 = tail call i32 @memset(i8* %7, i8 signext 0, i64 %8)
%12 = load i8*, i8** %2
%13 = tail call i32 @memcpy(i8* %12, i8* %0, i64 %6)
br label %19
14: ; preds = %5
%15 = tail call i32 @smp_init_set_proc_title(i32 %1, i8** %2)
%16 = tail call i32 (...) @smp_cpy_environs()
%17 = bitcast i8* %0 to i32*
%18 = tail call i32 @smp_reset_proc_titel(i32* %17, i64 %6, i32 %1, i8** %2)
br label %19
19: ; preds = %3, %14, %10
%20 = phi i32 [ 0, %10 ], [ 0, %14 ], [ -1, %3 ]
ret i32 %20
}