#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 scalar_t__ pid_t;

/* Variables and functions */
int CLONE_NEWUSER;
scalar_t__ EINVAL;
int SIGCHLD;
int /*<<< orphan*/ __NR_clone;
scalar_t__ errno;
scalar_t__ syscall(int /*<<< orphan*/, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ sysf_printf(char *, char *);
pid_t do_clone(int *flags) {
  pid_t pid;
  *flags |= SIGCHLD;
  pid = syscall(__NR_clone, *flags, NULL);
  if (pid < 0) {
    if (errno == EINVAL) {
      *flags &= ~(CLONE_NEWUSER);
      pid = syscall(__NR_clone, *flags, NULL);
    }
  }
  do {
    if ((pid < 0))
      sysf_printf("Error cloning process", "");
  } while (0);
  return pid;
}


x86 assembly (clang, -O0):
<do_clone>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    0x2ea5(%rip),%rax
mov    (%rax),%ecx
mov    -0x8(%rbp),%rax
or     (%rax),%ecx
mov    %ecx,(%rax)
mov    0x2eac(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rax
mov    (%rax),%esi
xor    %eax,%eax
mov    %eax,%edx
call   1030 <syscall@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jge    11b3 <do_clone+0x93>
mov    0x2e5d(%rip),%rax
mov    (%rax),%rax
mov    0x2e4b(%rip),%rcx
cmp    (%rcx),%rax
jne    11ae <do_clone+0x8e>
mov    0x2e5b(%rip),%rax
mov    (%rax),%ecx
xor    $0xffffffff,%ecx
mov    -0x8(%rbp),%rax
and    (%rax),%ecx
mov    %ecx,(%rax)
mov    0x2e57(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rax
mov    (%rax),%esi
xor    %eax,%eax
mov    %eax,%edx
call   1030 <syscall@plt>
mov    %rax,-0x10(%rbp)
jmp    11b3 <do_clone+0x93>
jmp    11b8 <do_clone+0x98>
cmpq   $0x0,-0x10(%rbp)
jge    11d6 <do_clone+0xb6>
lea    0xe36(%rip),%rdi
lea    0xe44(%rip),%rsi
call   1040 <sysf_printf@plt>
jmp    11db <do_clone+0xbb>
mov    -0x10(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_clone>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
mov    0x2ea9(%rip),%rax
mov    (%rdi),%esi
or     (%rax),%esi
mov    %esi,(%rdi)
mov    0x2eb4(%rip),%r15
mov    (%r15),%edi
xor    %edx,%edx
call   1030 <syscall@plt>
mov    %rax,%rbx
test   %rax,%rax
jns    119a <do_clone+0x7a>
mov    0x2e73(%rip),%rax
mov    (%rax),%rax
mov    0x2e61(%rip),%rcx
cmp    (%rcx),%rax
jne    1187 <do_clone+0x67>
mov    0x2e75(%rip),%rax
mov    (%rax),%esi
not    %esi
and    (%r14),%esi
mov    %esi,(%r14)
mov    (%r15),%edi
xor    %edx,%edx
call   1030 <syscall@plt>
mov    %rax,%rbx
test   %rax,%rax
jns    119a <do_clone+0x7a>
lea    0xe72(%rip),%rdi
lea    0xe80(%rip),%rsi
call   1040 <sysf_printf@plt>
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@SIGCHLD = global i32 0
@__NR_clone = global i32 0
@errno = global i64 0
@EINVAL = global i64 0
@CLONE_NEWUSER = global i32 0
@.str = [22 x i8] c"Error cloning process\00"
@.str.1 = [1 x i8] zeroinitializer
define i64 @do_clone(i32* %0) {
%2 = alloca i32*
%3 = alloca i64
store i32* %0, i32** %2
%4 = load i32, i32* @SIGCHLD
%5 = load i32*, i32** %2
%6 = load i32, i32* %5
%7 = or i32 %6, %4
store i32 %7, i32* %5
%8 = load i32, i32* @__NR_clone
%9 = load i32*, i32** %2
%10 = load i32, i32* %9
%11 = call i64 @syscall(i32 %8, i32 %10, i32* null)
store i64 %11, i64* %3
%12 = load i64, i64* %3
%13 = icmp slt i64 %12, 0
br i1 %13, label %14, label %29
14: ; preds = %1
%15 = load i64, i64* @errno
%16 = load i64, i64* @EINVAL
%17 = icmp eq i64 %15, %16
br i1 %17, label %18, label %28
18: ; preds = %14
%19 = load i32, i32* @CLONE_NEWUSER
%20 = xor i32 %19, -1
%21 = load i32*, i32** %2
%22 = load i32, i32* %21
%23 = and i32 %22, %20
store i32 %23, i32* %21
%24 = load i32, i32* @__NR_clone
%25 = load i32*, i32** %2
%26 = load i32, i32* %25
%27 = call i64 @syscall(i32 %24, i32 %26, i32* null)
store i64 %27, i64* %3
br label %28
28: ; preds = %18, %14
br label %29
29: ; preds = %28, %1
br label %30
30: ; preds = %29
%31 = load i64, i64* %3
%32 = icmp slt i64 %31, 0
br i1 %32, label %33, label %35
33: ; preds = %30
%34 = call i32 @sysf_printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0))
br label %35
35: ; preds = %33, %30
br label %36
36: ; preds = %35
%37 = load i64, i64* %3
ret i64 %37
}

LLVM IR (-O2):
@SIGCHLD = global i32 0
@__NR_clone = global i32 0
@errno = global i64 0
@EINVAL = global i64 0
@CLONE_NEWUSER = global i32 0
@.str = [22 x i8] c"Error cloning process\00"
@.str.1 = [1 x i8] zeroinitializer
define i64 @do_clone(i32* nocapture %0) {
%2 = load i32, i32* @SIGCHLD
%3 = load i32, i32* %0
%4 = or i32 %3, %2
store i32 %4, i32* %0
%5 = load i32, i32* @__NR_clone
%6 = tail call i64 @syscall(i32 %5, i32 %4, i32* null)
%7 = icmp slt i64 %6, 0
br i1 %7, label %8, label %23
8: ; preds = %1
%9 = load i64, i64* @errno
%10 = load i64, i64* @EINVAL
%11 = icmp eq i64 %9, %10
br i1 %11, label %12, label %20
12: ; preds = %8
%13 = load i32, i32* @CLONE_NEWUSER
%14 = xor i32 %13, -1
%15 = load i32, i32* %0
%16 = and i32 %15, %14
store i32 %16, i32* %0
%17 = load i32, i32* @__NR_clone
%18 = tail call i64 @syscall(i32 %17, i32 %16, i32* null)
%19 = icmp slt i64 %18, 0
br i1 %19, label %20, label %23
20: ; preds = %8, %12
%21 = phi i64 [ %18, %12 ], [ %6, %8 ]
%22 = tail call i32 @sysf_printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0))
br label %23
23: ; preds = %1, %20, %12
%24 = phi i64 [ %21, %20 ], [ %18, %12 ], [ %6, %1 ]
ret i64 %24
}