#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*/ error(char *);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
scalar_t__ prctl(int /*<<< orphan*/, char *, int /*<<< orphan*/,
                 int /*<<< orphan*/);
scalar_t__ setgid(int /*<<< orphan*/);
scalar_t__ setuid(int /*<<< orphan*/);
int /*<<< orphan*/ strcpy(char *, char *);
int /*<<< orphan*/ strlen(char *);
void mask_prog(char *name) {
  memset(name, 0, strlen(name));
  strcpy(name, "JBRunner/1.0");
  if (prctl(PR_SET_NAME, "JBRunner/1.0", 0, 0) < 0)
    error("prctl");
  if (setuid(0) < 0)
    perror("setuid");
  if (setgid(0) < 0)
    error("setgid");
}


x86 assembly (clang, -O0):
<mask_prog>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x10(%rbp),%rdi
mov    %eax,%edx
xor    %esi,%esi
call   1050 <memset@plt>
mov    -0x8(%rbp),%rdi
lea    0xe4b(%rip),%rsi
call   1030 <strcpy@plt>
mov    0x2e1f(%rip),%rax
mov    (%rax),%edi
lea    0xe36(%rip),%rsi
xor    %ecx,%ecx
mov    %ecx,%edx
call   1060 <prctl@plt>
cmp    $0x0,%rax
jge    11e9 <mask_prog+0x69>
lea    0xe29(%rip),%rdi
call   1070 <error@plt>
xor    %edi,%edi
call   10a0 <setuid@plt>
cmp    $0x0,%rax
jge    1206 <mask_prog+0x86>
lea    0xe12(%rip),%rdi
call   1090 <perror@plt>
xor    %edi,%edi
call   1080 <setgid@plt>
cmp    $0x0,%rax
jge    1223 <mask_prog+0xa3>
lea    0xdfc(%rip),%rdi
call   1070 <error@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mask_prog>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
call   1040 <strlen@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    %eax,%edx
call   1050 <memset@plt>
lea    0xe61(%rip),%r14
mov    %rbx,%rdi
mov    %r14,%rsi
call   1030 <strcpy@plt>
mov    0x2e2f(%rip),%rax
mov    (%rax),%edi
mov    %r14,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
call   1060 <prctl@plt>
test   %rax,%rax
jns    11d0 <mask_prog+0x50>
lea    0xe42(%rip),%rdi
call   1070 <error@plt>
xor    %edi,%edi
call   10a0 <setuid@plt>
test   %rax,%rax
js     1203 <mask_prog+0x83>
xor    %edi,%edi
call   1080 <setgid@plt>
test   %rax,%rax
js     11f0 <mask_prog+0x70>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe23(%rip),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1070 <error@plt>
lea    0xe09(%rip),%rdi
call   1090 <perror@plt>
jmp    11dc <mask_prog+0x5c>

LLVM IR (-O0):
@.str = [13 x i8] c"JBRunner/1.0\00"
@PR_SET_NAME = global i32 0
@.str.1 = [6 x i8] c"prctl\00"
@.str.2 = [7 x i8] c"setuid\00"
@.str.3 = [7 x i8] c"setgid\00"
define void @mask_prog(i8* %0) {
%2 = alloca i8*
store i8* %0, i8** %2
%3 = load i8*, i8** %2
%4 = load i8*, i8** %2
%5 = call i32 @strlen(i8* %4)
%6 = call i32 @memset(i8* %3, i32 0, i32 %5)
%7 = load i8*, i8** %2
%8 = call i32 @strcpy(i8* %7, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%9 = load i32, i32* @PR_SET_NAME
%10 = call i64 @prctl(i32 %9, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 0, i32 0)
%11 = icmp slt i64 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %1
%13 = call i32 @error(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
br label %14
14: ; preds = %12, %1
%15 = call i64 @setuid(i32 0)
%16 = icmp slt i64 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %14
%18 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
br label %19
19: ; preds = %17, %14
%20 = call i64 @setgid(i32 0)
%21 = icmp slt i64 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %19
%23 = call i32 @error(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
br label %24
24: ; preds = %22, %19
ret void
}

LLVM IR (-O2):
@.str = [13 x i8] c"JBRunner/1.0\00"
@PR_SET_NAME = global i32 0
@.str.1 = [6 x i8] c"prctl\00"
@.str.2 = [7 x i8] c"setuid\00"
@.str.3 = [7 x i8] c"setgid\00"
define void @mask_prog(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = tail call i32 @memset(i8* %0, i32 0, i32 %2)
%4 = tail call i32 @strcpy(i8* %0, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%5 = load i32, i32* @PR_SET_NAME
%6 = tail call i64 @prctl(i32 %5, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 0, i32 0)
%7 = icmp slt i64 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %1
%9 = tail call i32 @error(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
br label %10
10: ; preds = %8, %1
%11 = tail call i64 @setuid(i32 0)
%12 = icmp slt i64 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %10
%14 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
br label %15
15: ; preds = %13, %10
%16 = tail call i64 @setgid(i32 0)
%17 = icmp slt i64 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %15
%19 = tail call i32 @error(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
br label %20
20: ; preds = %18, %15
ret void
}