#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 */
struct passwd {
  int /*<<< orphan*/ pw_uid;
  int /*<<< orphan*/ pw_gid;
};

/* Variables and functions */
scalar_t__ chroot(char const *);
struct passwd *getpwnam(char const *);
scalar_t__ setgid(int /*<<< orphan*/);
scalar_t__ setuid(int /*<<< orphan*/);
int serverChangeUserAndJail(const char *user, const char *dir) {
  struct passwd *rec = getpwnam(user);
  if (rec != NULL) {
    if (chroot(dir) == 0) {
      if (setgid(rec->pw_gid) == 0) {
        if (setuid(rec->pw_uid) == 0) {
          return 1;
        }
      }
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<serverChangeUserAndJail>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <getpwnam@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11c1 <serverChangeUserAndJail+0x81>
mov    -0x18(%rbp),%rdi
call   1030 <chroot@plt>
cmp    $0x0,%rax
jne    11bc <serverChangeUserAndJail+0x7c>
mov    -0x20(%rbp),%rax
mov    0x4(%rax),%edi
call   1050 <setgid@plt>
cmp    $0x0,%rax
jne    11b7 <serverChangeUserAndJail+0x77>
mov    -0x20(%rbp),%rax
mov    (%rax),%edi
call   1060 <setuid@plt>
cmp    $0x0,%rax
jne    11b2 <serverChangeUserAndJail+0x72>
movl   $0x1,-0x4(%rbp)
jmp    11c8 <serverChangeUserAndJail+0x88>
jmp    11b7 <serverChangeUserAndJail+0x77>
jmp    11bc <serverChangeUserAndJail+0x7c>
jmp    11c1 <serverChangeUserAndJail+0x81>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<serverChangeUserAndJail>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
call   1040 <getpwnam@plt>
test   %rax,%rax
je     117a <serverChangeUserAndJail+0x3a>
mov    %rax,%rbx
mov    %r14,%rdi
call   1030 <chroot@plt>
test   %rax,%rax
jne    117a <serverChangeUserAndJail+0x3a>
mov    0x4(%rbx),%edi
call   1050 <setgid@plt>
test   %rax,%rax
jne    117a <serverChangeUserAndJail+0x3a>
mov    (%rbx),%edi
call   1060 <setuid@plt>
test   %rax,%rax
je     1184 <serverChangeUserAndJail+0x44>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    $0x1,%eax
jmp    117c <serverChangeUserAndJail+0x3c>

LLVM IR (-O0):
%struct.passwd = type { i32, i32 }
define i32 @serverChangeUserAndJail(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca %struct.passwd*
store i8* %0, i8** %4
store i8* %1, i8** %5
%7 = load i8*, i8** %4
%8 = call %struct.passwd* @getpwnam(i8* %7)
store %struct.passwd* %8, %struct.passwd** %6
%9 = load %struct.passwd*, %struct.passwd** %6
%10 = icmp ne %struct.passwd* %9, null
br i1 %10, label %11, label %31
11: ; preds = %2
%12 = load i8*, i8** %5
%13 = call i64 @chroot(i8* %12)
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %30
15: ; preds = %11
%16 = load %struct.passwd*, %struct.passwd** %6
%17 = getelementptr inbounds %struct.passwd, %struct.passwd* %16, i32 0, i32 1
%18 = load i32, i32* %17
%19 = call i64 @setgid(i32 %18)
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %29
21: ; preds = %15
%22 = load %struct.passwd*, %struct.passwd** %6
%23 = getelementptr inbounds %struct.passwd, %struct.passwd* %22, i32 0, i32 0
%24 = load i32, i32* %23
%25 = call i64 @setuid(i32 %24)
%26 = icmp eq i64 %25, 0
br i1 %26, label %27, label %28
27: ; preds = %21
store i32 1, i32* %3
br label %32
28: ; preds = %21
br label %29
29: ; preds = %28, %15
br label %30
30: ; preds = %29, %11
br label %31
31: ; preds = %30, %2
store i32 0, i32* %3
br label %32
32: ; preds = %31, %27
%33 = load i32, i32* %3
ret i32 %33
}

LLVM IR (-O2):
%struct.passwd = type { i32, i32 }
define i32 @serverChangeUserAndJail(i8* nocapture %0, i8* %1) {
%3 = tail call %struct.passwd* @getpwnam(i8* %0)
%4 = icmp eq %struct.passwd* %3, null
br i1 %4, label %18, label %5
5: ; preds = %2
%6 = tail call i64 @chroot(i8* %1)
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %18
8: ; preds = %5
%9 = getelementptr inbounds %struct.passwd, %struct.passwd* %3, i64 0, i32 1
%10 = load i32, i32* %9
%11 = tail call i64 @setgid(i32 %10)
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %18
13: ; preds = %8
%14 = getelementptr inbounds %struct.passwd, %struct.passwd* %3, i64 0, i32 0
%15 = load i32, i32* %14
%16 = tail call i64 @setuid(i32 %15)
%17 = icmp eq i64 %16, 0
br i1 %17, label %19, label %18
18: ; preds = %5, %13, %8, %2
br label %19
19: ; preds = %13, %18
%20 = phi i32 [ 0, %18 ], [ 1, %13 ]
ret i32 %20
}