#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 rlimit {
  scalar_t__ rlim_max;
  scalar_t__ rlim_cur;
};

/* Variables and functions */
int /*<<< orphan*/ RLIMIT_NPROC;
scalar_t__ arg_get_bool(int, char **, char *);
int /*<<< orphan*/ do_detach(int, char **);
int getrlimit(int /*<<< orphan*/, struct rlimit *);
int /*<<< orphan*/ no_detach(int, char **);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ pthread_self();
int /*<<< orphan*/ show_time();
int /*<<< orphan*/ show_usage(int, char **);
int main(int argc, char *argv[]) {
  show_usage(argc, argv);
  struct rlimit rlim;
  int err = getrlimit(RLIMIT_NPROC, &rlim);
  if (0 != err) {
    do {
      show_time();
      printf(" -- [%lu]", (unsigned long int)pthread_self());
      printf("getrlimit faild");
      printf("\n");
    } while (0);
  } else {
    do {
      show_time();
      printf(" -- [%lu]", (unsigned long int)pthread_self());
      printf("RLIMIT_NPROC : cur = [%lld], max = [%lld]",
             (long long)rlim.rlim_cur, (long long)rlim.rlim_max);
      printf("\n");
    } while (0);
  }
  if (arg_get_bool(argc, argv, "-no")) {
    no_detach(argc, argv);
  } else {
    do_detach(argc, argv);
  }
  do {
    show_time();
    printf(" -- [%lu]", (unsigned long int)pthread_self());
    printf("main over");
    printf("\n");
  } while (0);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1080 <show_usage@plt>
mov    0x2e3f(%rip),%rax
mov    (%rax),%edi
lea    -0x20(%rbp),%rsi
call   1090 <getrlimit@plt>
mov    %eax,-0x24(%rbp)
xor    %eax,%eax
cmp    -0x24(%rbp),%eax
je     1207 <main+0x87>
jmp    11c7 <main+0x47>
mov    $0x0,%al
call   1040 <show_time@plt>
mov    $0x0,%al
call   1070 <pthread_self@plt>
mov    %rax,%rsi
lea    0xe21(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe1d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe1f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1254 <main+0xd4>
jmp    120c <main+0x8c>
mov    $0x0,%al
call   1040 <show_time@plt>
mov    $0x0,%al
call   1070 <pthread_self@plt>
mov    %rax,%rsi
lea    0xddc(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
lea    0xde2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xdd2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1254 <main+0xd4>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xde4(%rip),%rdx
call   10a0 <arg_get_bool@plt>
cmp    $0x0,%rax
je     1282 <main+0x102>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1050 <no_detach@plt>
jmp    128e <main+0x10e>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1060 <do_detach@plt>
jmp    1293 <main+0x113>
mov    $0x0,%al
call   1040 <show_time@plt>
mov    $0x0,%al
call   1070 <pthread_self@plt>
mov    %rax,%rsi
lea    0xd55(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xd91(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xd53(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
mov    %edi,%ebp
call   1090 <show_usage@plt>
mov    0x2e3f(%rip),%rax
mov    (%rax),%edi
mov    %rsp,%rsi
call   10a0 <getrlimit@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1050 <show_time@plt>
xor    %eax,%eax
call   1080 <pthread_self@plt>
lea    0xe36(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
test   %ebx,%ebx
je     11e8 <main+0x58>
lea    0xe2b(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    11ff <main+0x6f>
mov    (%rsp),%rdx
mov    0x8(%rsp),%rsi
lea    0xe22(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    0xe34(%rip),%rdx
mov    %ebp,%edi
mov    %r14,%rsi
call   10b0 <arg_get_bool@plt>
mov    %ebp,%edi
mov    %r14,%rsi
test   %rax,%rax
je     122b <main+0x9b>
call   1060 <no_detach@plt>
jmp    1230 <main+0xa0>
call   1070 <do_detach@plt>
xor    %eax,%eax
call   1050 <show_time@plt>
xor    %eax,%eax
call   1080 <pthread_self@plt>
lea    0xdbb(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xdf2(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.rlimit = type { i64, i64 }
@RLIMIT_NPROC = global i32 0
@.str = [10 x i8] c" -- [%lu]\00"
@.str.1 = [16 x i8] c"getrlimit faild\00"
@.str.2 = [2 x i8] c"\0A\00"
@.str.3 = [42 x i8] c"RLIMIT_NPROC : cur = [%lld], max = [%lld]\00"
@.str.4 = [4 x i8] c"-no\00"
@.str.5 = [10 x i8] c"main over\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.rlimit
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = load i8**, i8*** %5
%10 = call i32 @show_usage(i32 %8, i8** %9)
%11 = load i32, i32* @RLIMIT_NPROC
%12 = call i32 @getrlimit(i32 %11, %struct.rlimit* %6)
store i32 %12, i32* %7
%13 = load i32, i32* %7
%14 = icmp ne i32 0, %13
br i1 %14, label %15, label %23
15: ; preds = %2
br label %16
16: ; preds = %15
%17 = call i32 (...) @show_time()
%18 = call i64 (...) @pthread_self()
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i64 %18)
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %22
22: ; preds = %16
br label %35
23: ; preds = %2
br label %24
24: ; preds = %23
%25 = call i32 (...) @show_time()
%26 = call i64 (...) @pthread_self()
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i64 %26)
%28 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %6, i32 0, i32 1
%29 = load i64, i64* %28
%30 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %6, i32 0, i32 0
%31 = load i64, i64* %30
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.3, i64 0, i64 0), i64 %29, i64 %31)
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %34
34: ; preds = %24
br label %35
35: ; preds = %34, %22
%36 = load i32, i32* %4
%37 = load i8**, i8*** %5
%38 = call i64 @arg_get_bool(i32 %36, i8** %37, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
%39 = icmp ne i64 %38, 0
br i1 %39, label %40, label %44
40: ; preds = %35
%41 = load i32, i32* %4
%42 = load i8**, i8*** %5
%43 = call i32 @no_detach(i32 %41, i8** %42)
br label %48
44: ; preds = %35
%45 = load i32, i32* %4
%46 = load i8**, i8*** %5
%47 = call i32 @do_detach(i32 %45, i8** %46)
br label %48
48: ; preds = %44, %40
br label %49
49: ; preds = %48
%50 = call i32 (...) @show_time()
%51 = call i64 (...) @pthread_self()
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i64 %51)
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0))
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %55
55: ; preds = %49
ret i32 0
}

LLVM IR (-O2):
%struct.rlimit = type { i64, i64 }
@RLIMIT_NPROC = global i32 0
@.str = [10 x i8] c" -- [%lu]\00"
@.str.1 = [16 x i8] c"getrlimit faild\00"
@.str.3 = [42 x i8] c"RLIMIT_NPROC : cur = [%lld], max = [%lld]\00"
@.str.4 = [4 x i8] c"-no\00"
@.str.5 = [10 x i8] c"main over\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca %struct.rlimit
%4 = tail call i32 @show_usage(i32 %0, i8** %1)
%5 = bitcast %struct.rlimit* %3 to i8*
%6 = load i32, i32* @RLIMIT_NPROC
%7 = call i32 @getrlimit(i32 %6, %struct.rlimit* %3)
%8 = icmp eq i32 %7, 0
%9 = call i32 (...) @show_time()
%10 = call i64 (...) @pthread_self()
%11 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i64 %10)
br i1 %8, label %14, label %12
12: ; preds = %2
%13 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
br label %20
14: ; preds = %2
%15 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %3, i64 0, i32 1
%16 = load i64, i64* %15
%17 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %3, i64 0, i32 0
%18 = load i64, i64* %17
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str.3, i64 0, i64 0), i64 %16, i64 %18)
br label %20
20: ; preds = %14, %12
%21 = call i32 @putchar(i32 10)
%22 = call i64 @arg_get_bool(i32 %0, i8** %1, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
%23 = icmp eq i64 %22, 0
br i1 %23, label %26, label %24
24: ; preds = %20
%25 = call i32 @no_detach(i32 %0, i8** %1)
br label %28
26: ; preds = %20
%27 = call i32 @do_detach(i32 %0, i8** %1)
br label %28
28: ; preds = %24, %26
%29 = call i32 (...) @show_time()
%30 = call i64 (...) @pthread_self()
%31 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i64 %30)
%32 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0))
%33 = call i32 @putchar(i32 10)
ret i32 0
}