#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 daemon(int /*<<< orphan*/, int /*<<< orphan*/);
int setresgid(int, int, int);
int setresuid(int, int, int);
int daemonize() {
  int ret = -1;
  if ((daemon(0, 0)) == -1)
    return ret;
  if ((setresgid(1998, 1998, 1998)) == -1)
    return ret;
  if ((setresuid(1998, 1998, 1998)) == -1)
    return ret;
  ret = 0;
  return ret;
}


x86 assembly (clang, -O0):
<daemonize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0xffffffff,-0x8(%rbp)
xor    %esi,%esi
mov    %esi,%edi
call   1050 <daemon@plt>
cmp    $0xffffffff,%eax
jne    115c <daemonize+0x2c>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11ad <daemonize+0x7d>
mov    $0x7ce,%edx
mov    %edx,%edi
mov    %edx,%esi
call   1040 <setresgid@plt>
cmp    $0xffffffff,%eax
jne    117e <daemonize+0x4e>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11ad <daemonize+0x7d>
mov    $0x7ce,%edx
mov    %edx,%edi
mov    %edx,%esi
call   1030 <setresuid@plt>
cmp    $0xffffffff,%eax
jne    11a0 <daemonize+0x70>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11ad <daemonize+0x7d>
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<daemonize>:
push   %rbx
xor    %edi,%edi
xor    %esi,%esi
call   1050 <daemon@plt>
mov    $0xffffffff,%ebx
cmp    $0xffffffff,%eax
je     117b <daemonize+0x4b>
mov    $0x7ce,%edi
mov    $0x7ce,%esi
mov    $0x7ce,%edx
call   1040 <setresgid@plt>
cmp    $0xffffffff,%eax
je     117b <daemonize+0x4b>
mov    $0x7ce,%edi
mov    $0x7ce,%esi
mov    $0x7ce,%edx
call   1030 <setresuid@plt>
xor    %ebx,%ebx
cmp    $0xffffffff,%eax
sete   %bl
neg    %ebx
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
define i32 @daemonize() {
%1 = alloca i32
%2 = alloca i32
store i32 -1, i32* %2
%3 = call i32 @daemon(i32 0, i32 0)
%4 = icmp eq i32 %3, -1
br i1 %4, label %5, label %7
5: ; preds = %0
%6 = load i32, i32* %2
store i32 %6, i32* %1
br label %19
7: ; preds = %0
%8 = call i32 @setresgid(i32 1998, i32 1998, i32 1998)
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %12
10: ; preds = %7
%11 = load i32, i32* %2
store i32 %11, i32* %1
br label %19
12: ; preds = %7
%13 = call i32 @setresuid(i32 1998, i32 1998, i32 1998)
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %17
15: ; preds = %12
%16 = load i32, i32* %2
store i32 %16, i32* %1
br label %19
17: ; preds = %12
store i32 0, i32* %2
%18 = load i32, i32* %2
store i32 %18, i32* %1
br label %19
19: ; preds = %17, %15, %10, %5
%20 = load i32, i32* %1
ret i32 %20
}

LLVM IR (-O2):
define i32 @daemonize() {
%1 = tail call i32 @daemon(i32 0, i32 0)
%2 = icmp eq i32 %1, -1
br i1 %2, label %10, label %3
3: ; preds = %0
%4 = tail call i32 @setresgid(i32 1998, i32 1998, i32 1998)
%5 = icmp eq i32 %4, -1
br i1 %5, label %10, label %6
6: ; preds = %3
%7 = tail call i32 @setresuid(i32 1998, i32 1998, i32 1998)
%8 = icmp eq i32 %7, -1
%9 = sext i1 %8 to i32
br label %10
10: ; preds = %6, %3, %0
%11 = phi i32 [ -1, %0 ], [ -1, %3 ], [ %9, %6 ]
ret i32 %11
}