#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 uid_t;
typedef int gid_t;

/* Variables and functions */
int /*<<< orphan*/ err(char *, char *);
int /*<<< orphan*/ msg(char *, char *, int, int);
int setfsgid(int);
int setfsuid(int);
void change_fsid(char *s, uid_t fromuid, gid_t fromgid, uid_t uid, gid_t gid) {
  int u;
  int g;
  msg("%s: changing to %d:%d", s, uid, gid);
  if (fromuid != uid) {
    u = setfsuid(uid);
    if (u == -1)
      err("%s: setfsuid", s);
    else if (u != fromuid)
      msg("%s: setfsuid returned %d (wanted %d)", s, u, fromuid);
  }
  if (fromgid != gid) {
    g = setfsgid(gid);
    if (g == -1)
      err("%s: setfsgid", s);
    if (g != fromgid)
      msg("%s: setfsgid returned %d (wanted %d)", s, g, fromgid);
  }
}


x86 assembly (clang, -O0):
<change_fsid>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    %r8d,-0x18(%rbp)
mov    -0x8(%rbp),%rsi
mov    -0x14(%rbp),%edx
mov    -0x18(%rbp),%ecx
lea    0xe96(%rip),%rdi
call   1060 <msg@plt>
mov    -0xc(%rbp),%eax
cmp    -0x14(%rbp),%eax
je     11d1 <change_fsid+0x91>
mov    -0x14(%rbp),%edi
call   1030 <setfsuid@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    11a5 <change_fsid+0x65>
mov    -0x8(%rbp),%rsi
lea    0xe7b(%rip),%rdi
call   1040 <err@plt>
jmp    11cc <change_fsid+0x8c>
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
je     11c7 <change_fsid+0x87>
mov    -0x8(%rbp),%rsi
mov    -0x1c(%rbp),%edx
mov    -0xc(%rbp),%ecx
lea    0xe61(%rip),%rdi
call   1060 <msg@plt>
jmp    11cc <change_fsid+0x8c>
jmp    11d1 <change_fsid+0x91>
mov    -0x10(%rbp),%eax
cmp    -0x18(%rbp),%eax
je     1229 <change_fsid+0xe9>
mov    -0x18(%rbp),%edi
call   1050 <setfsgid@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0xffffffff,-0x20(%rbp)
jne    1202 <change_fsid+0xc2>
mov    -0x8(%rbp),%rsi
lea    0xe4b(%rip),%rdi
call   1040 <err@plt>
mov    -0x20(%rbp),%eax
cmp    -0x10(%rbp),%eax
je     1224 <change_fsid+0xe4>
mov    -0x8(%rbp),%rsi
mov    -0x20(%rbp),%edx
mov    -0x10(%rbp),%ecx
lea    0xe36(%rip),%rdi
call   1060 <msg@plt>
jmp    1229 <change_fsid+0xe9>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<change_fsid>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %r8d,%ebp
mov    %ecx,%ebx
mov    %edx,%r14d
mov    %esi,%r12d
mov    %rdi,%r15
lea    0xea3(%rip),%rdi
mov    %r15,%rsi
mov    %ecx,%edx
mov    %r8d,%ecx
call   1060 <msg@plt>
cmp    %ebx,%r12d
je     1194 <change_fsid+0x54>
mov    %ebx,%edi
call   1030 <setfsuid@plt>
cmp    $0xffffffff,%eax
je     11ae <change_fsid+0x6e>
cmp    %r12d,%eax
je     1194 <change_fsid+0x54>
lea    0xe9c(%rip),%rdi
mov    %r15,%rsi
mov    %eax,%edx
mov    %r12d,%ecx
call   1060 <msg@plt>
cmp    %ebp,%r14d
je     11d8 <change_fsid+0x98>
mov    %ebp,%edi
call   1050 <setfsgid@plt>
mov    %eax,%ebx
cmp    $0xffffffff,%eax
je     11c4 <change_fsid+0x84>
cmp    %r14d,%ebx
je     11d8 <change_fsid+0x98>
jmp    11e1 <change_fsid+0xa1>
lea    0xe61(%rip),%rdi
mov    %r15,%rsi
call   1040 <err@plt>
cmp    %ebp,%r14d
jne    1199 <change_fsid+0x59>
jmp    11d8 <change_fsid+0x98>
lea    0xe7d(%rip),%rdi
mov    %r15,%rsi
call   1040 <err@plt>
cmp    %r14d,%ebx
jne    11e1 <change_fsid+0xa1>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe6d(%rip),%rdi
mov    %r15,%rsi
mov    %ebx,%edx
mov    %r14d,%ecx
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1060 <msg@plt>

LLVM IR (-O0):
@.str = [22 x i8] c"%s: changing to %d:%d\00"
@.str.1 = [13 x i8] c"%s: setfsuid\00"
@.str.2 = [37 x i8] c"%s: setfsuid returned %d (wanted %d)\00"
@.str.3 = [13 x i8] c"%s: setfsgid\00"
@.str.4 = [37 x i8] c"%s: setfsgid returned %d (wanted %d)\00"
define void @change_fsid(i8* %0, i32 %1, i32 %2, i32 %3, i32 %4) {
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
store i8* %0, i8** %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store i32 %3, i32* %9
store i32 %4, i32* %10
%13 = load i8*, i8** %6
%14 = load i32, i32* %9
%15 = load i32, i32* %10
%16 = call i32 @msg(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %13, i32 %14, i32 %15)
%17 = load i32, i32* %7
%18 = load i32, i32* %9
%19 = icmp ne i32 %17, %18
br i1 %19, label %20, label %39
20: ; preds = %5
%21 = load i32, i32* %9
%22 = call i32 @setfsuid(i32 %21)
store i32 %22, i32* %11
%23 = load i32, i32* %11
%24 = icmp eq i32 %23, -1
br i1 %24, label %25, label %28
25: ; preds = %20
%26 = load i8*, i8** %6
%27 = call i32 @err(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* %26)
br label %38
28: ; preds = %20
%29 = load i32, i32* %11
%30 = load i32, i32* %7
%31 = icmp ne i32 %29, %30
br i1 %31, label %32, label %37
32: ; preds = %28
%33 = load i8*, i8** %6
%34 = load i32, i32* %11
%35 = load i32, i32* %7
%36 = call i32 @msg(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0), i8* %33, i32 %34, i32 %35)
br label %37
37: ; preds = %32, %28
br label %38
38: ; preds = %37, %25
br label %39
39: ; preds = %38, %5
%40 = load i32, i32* %8
%41 = load i32, i32* %10
%42 = icmp ne i32 %40, %41
br i1 %42, label %43, label %61
43: ; preds = %39
%44 = load i32, i32* %10
%45 = call i32 @setfsgid(i32 %44)
store i32 %45, i32* %12
%46 = load i32, i32* %12
%47 = icmp eq i32 %46, -1
br i1 %47, label %48, label %51
48: ; preds = %43
%49 = load i8*, i8** %6
%50 = call i32 @err(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i8* %49)
br label %51
51: ; preds = %48, %43
%52 = load i32, i32* %12
%53 = load i32, i32* %8
%54 = icmp ne i32 %52, %53
br i1 %54, label %55, label %60
55: ; preds = %51
%56 = load i8*, i8** %6
%57 = load i32, i32* %12
%58 = load i32, i32* %8
%59 = call i32 @msg(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.4, i64 0, i64 0), i8* %56, i32 %57, i32 %58)
br label %60
60: ; preds = %55, %51
br label %61
61: ; preds = %60, %39
ret void
}

LLVM IR (-O2):
@.str = [22 x i8] c"%s: changing to %d:%d\00"
@.str.1 = [13 x i8] c"%s: setfsuid\00"
@.str.2 = [37 x i8] c"%s: setfsuid returned %d (wanted %d)\00"
@.str.3 = [13 x i8] c"%s: setfsgid\00"
@.str.4 = [37 x i8] c"%s: setfsgid returned %d (wanted %d)\00"
define void @change_fsid(i8* %0, i32 %1, i32 %2, i32 %3, i32 %4) {
%6 = tail call i32 @msg(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %0, i32 %3, i32 %4)
%7 = icmp eq i32 %1, %3
br i1 %7, label %17, label %8
8: ; preds = %5
%9 = tail call i32 @setfsuid(i32 %3)
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %13
11: ; preds = %8
%12 = tail call i32 @err(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %17
13: ; preds = %8
%14 = icmp eq i32 %9, %1
br i1 %14, label %17, label %15
15: ; preds = %13
%16 = tail call i32 @msg(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0), i8* %0, i32 %9, i32 %1)
br label %17
17: ; preds = %11, %15, %13, %5
%18 = icmp eq i32 %2, %4
br i1 %18, label %28, label %19
19: ; preds = %17
%20 = tail call i32 @setfsgid(i32 %4)
%21 = icmp eq i32 %20, -1
br i1 %21, label %22, label %24
22: ; preds = %19
%23 = tail call i32 @err(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i8* %0)
br label %24
24: ; preds = %22, %19
%25 = icmp eq i32 %20, %2
br i1 %25, label %28, label %26
26: ; preds = %24
%27 = tail call i32 @msg(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.4, i64 0, i64 0), i8* %0, i32 %20, i32 %2)
br label %28
28: ; preds = %24, %26, %17
ret void
}