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

/* Variables and functions */
int /*<<< orphan*/ LOG_ERR;
int /*<<< orphan*/ STDERR_FILENO;
int /*<<< orphan*/ STDIN_FILENO;
int /*<<< orphan*/ STDOUT_FILENO;
int /*<<< orphan*/ close(int /*<<< orphan*/);
int /*<<< orphan*/ dup2(int, int /*<<< orphan*/);
int execlp(char *, char *, char *, int /*<<< orphan*/ *);
scalar_t__ seteuid(int /*<<< orphan*/);
int /*<<< orphan*/ setsid();
int /*<<< orphan*/ setuid(int /*<<< orphan*/);
int /*<<< orphan*/ syslog(int /*<<< orphan*/, char *);
int launch_nxnode(uid_t user, int comm_fd) {
  setuid(user);
  if (seteuid(user) != 0) {
    syslog(LOG_ERR, "ERROR: Unable to drop back to calling userid: %m\n");
    return 1;
  }
  setsid();
  close(STDIN_FILENO);
  close(STDOUT_FILENO);
  close(STDERR_FILENO);
  dup2(comm_fd, STDIN_FILENO);
  dup2(comm_fd, STDOUT_FILENO);
  dup2(comm_fd, STDERR_FILENO);
  return execlp("/usr/NX/bin/nxnode", "/usr/NX/bin/nxnode", "--slave", NULL);
}


x86 assembly (clang, -O0):
<launch_nxnode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%edi
call   1070 <setuid@plt>
mov    -0x8(%rbp),%edi
call   1090 <seteuid@plt>
cmp    $0x0,%rax
je     11b9 <launch_nxnode+0x49>
mov    0x2e21(%rip),%rax
mov    (%rax),%edi
lea    0xe58(%rip),%rsi
call   1060 <syslog@plt>
movl   $0x1,-0x4(%rbp)
jmp    123a <launch_nxnode+0xca>
mov    $0x0,%al
call   1050 <setsid@plt>
mov    0x2e09(%rip),%rax
mov    (%rax),%edi
call   1040 <close@plt>
mov    0x2e1b(%rip),%rax
mov    (%rax),%edi
call   1040 <close@plt>
mov    0x2df5(%rip),%rax
mov    (%rax),%edi
call   1040 <close@plt>
mov    -0xc(%rbp),%edi
mov    0x2ddc(%rip),%rax
mov    (%rax),%esi
call   1030 <dup2@plt>
mov    -0xc(%rbp),%edi
mov    0x2deb(%rip),%rax
mov    (%rax),%esi
call   1030 <dup2@plt>
mov    -0xc(%rbp),%edi
mov    0x2dc2(%rip),%rax
mov    (%rax),%esi
call   1030 <dup2@plt>
lea    0xe0e(%rip),%rsi
lea    0xe1a(%rip),%rdx
xor    %eax,%eax
mov    %eax,%ecx
mov    %rsi,%rdi
call   1080 <execlp@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<launch_nxnode>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%ebx
mov    %edi,%ebp
call   1070 <setuid@plt>
mov    %ebp,%edi
call   1090 <seteuid@plt>
test   %rax,%rax
je     11b1 <launch_nxnode+0x41>
mov    0x2e2d(%rip),%rax
mov    (%rax),%edi
lea    0xe64(%rip),%rsi
call   1060 <syslog@plt>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %eax,%eax
call   1050 <setsid@plt>
mov    0x2e11(%rip),%rbp
mov    0x0(%rbp),%edi
call   1040 <close@plt>
mov    0x2e22(%rip),%r14
mov    (%r14),%edi
call   1040 <close@plt>
mov    0x2dfb(%rip),%r15
mov    (%r15),%edi
call   1040 <close@plt>
mov    0x0(%rbp),%esi
mov    %ebx,%edi
call   1030 <dup2@plt>
mov    (%r14),%esi
mov    %ebx,%edi
call   1030 <dup2@plt>
mov    (%r15),%esi
mov    %ebx,%edi
call   1030 <dup2@plt>
lea    0xe28(%rip),%rdi
lea    0xe34(%rip),%rdx
mov    %rdi,%rsi
xor    %ecx,%ecx
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1080 <execlp@plt>

LLVM IR (-O0):
@LOG_ERR = global i32 0
@.str = [50 x i8] c"ERROR: Unable to drop back to calling userid: %m\0A\00"
@STDIN_FILENO = global i32 0
@STDOUT_FILENO = global i32 0
@STDERR_FILENO = global i32 0
@.str.1 = [19 x i8] c"/usr/NX/bin/nxnode\00"
@.str.2 = [8 x i8] c"--slave\00"
define i32 @launch_nxnode(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
%6 = load i32, i32* %4
%7 = call i32 @setuid(i32 %6)
%8 = load i32, i32* %4
%9 = call i64 @seteuid(i32 %8)
%10 = icmp ne i64 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = load i32, i32* @LOG_ERR
%13 = call i32 @syslog(i32 %12, i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %32
14: ; preds = %2
%15 = call i32 (...) @setsid()
%16 = load i32, i32* @STDIN_FILENO
%17 = call i32 @close(i32 %16)
%18 = load i32, i32* @STDOUT_FILENO
%19 = call i32 @close(i32 %18)
%20 = load i32, i32* @STDERR_FILENO
%21 = call i32 @close(i32 %20)
%22 = load i32, i32* %5
%23 = load i32, i32* @STDIN_FILENO
%24 = call i32 @dup2(i32 %22, i32 %23)
%25 = load i32, i32* %5
%26 = load i32, i32* @STDOUT_FILENO
%27 = call i32 @dup2(i32 %25, i32 %26)
%28 = load i32, i32* %5
%29 = load i32, i32* @STDERR_FILENO
%30 = call i32 @dup2(i32 %28, i32 %29)
%31 = call i32 @execlp(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32* null)
store i32 %31, i32* %3
br label %32
32: ; preds = %14, %11
%33 = load i32, i32* %3
ret i32 %33
}

LLVM IR (-O2):
@LOG_ERR = global i32 0
@.str = [50 x i8] c"ERROR: Unable to drop back to calling userid: %m\0A\00"
@STDIN_FILENO = global i32 0
@STDOUT_FILENO = global i32 0
@STDERR_FILENO = global i32 0
@.str.1 = [19 x i8] c"/usr/NX/bin/nxnode\00"
@.str.2 = [8 x i8] c"--slave\00"
define i32 @launch_nxnode(i32 %0, i32 %1) {
%3 = tail call i32 @setuid(i32 %0)
%4 = tail call i64 @seteuid(i32 %0)
%5 = icmp eq i64 %4, 0
br i1 %5, label %9, label %6
6: ; preds = %2
%7 = load i32, i32* @LOG_ERR
%8 = tail call i32 @syslog(i32 %7, i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0))
br label %24
9: ; preds = %2
%10 = tail call i32 (...) @setsid()
%11 = load i32, i32* @STDIN_FILENO
%12 = tail call i32 @close(i32 %11)
%13 = load i32, i32* @STDOUT_FILENO
%14 = tail call i32 @close(i32 %13)
%15 = load i32, i32* @STDERR_FILENO
%16 = tail call i32 @close(i32 %15)
%17 = load i32, i32* @STDIN_FILENO
%18 = tail call i32 @dup2(i32 %1, i32 %17)
%19 = load i32, i32* @STDOUT_FILENO
%20 = tail call i32 @dup2(i32 %1, i32 %19)
%21 = load i32, i32* @STDERR_FILENO
%22 = tail call i32 @dup2(i32 %1, i32 %21)
%23 = tail call i32 @execlp(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32* null)
br label %24
24: ; preds = %9, %6
%25 = phi i32 [ 1, %6 ], [ %23, %9 ]
ret i32 %25
}