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

/* Variables and functions */
int EOF;
int /*<<< orphan*/ RLIMIT_NOFILE;
int atoi(char *);
int /*<<< orphan*/ errno;
int execl(char *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, char *, ...);
int getopt(int, char **, char *);
struct passwd *getpwnam(char *);
int /*<<< orphan*/ setgid(int /*<<< orphan*/);
int setrlimit(int /*<<< orphan*/, struct rlimit *);
int /*<<< orphan*/ setuid(int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int /*<<< orphan*/ usage();
int main(int argc, char *argv[]) {
  int ch, ret, rlim_fd_cur, rlim_fd_max;
  struct rlimit rlp;
  struct passwd *pw;
  extern char *optarg;
  extern int optind, opterr, optopt;
  rlim_fd_cur = 4096;
  rlim_fd_max = 8096;
  while ((ch = getopt(argc, argv, "c:m:h")) != EOF) {
    switch (ch) {
    case 'c':
      rlim_fd_cur = atoi(optarg);
      break;
    case 'm':
      rlim_fd_max = atoi(optarg);
      break;
    case 'h':
    case '?':
    default:
      usage();
    }
  }
  argc -= optind;
  if (argc != 0)
    usage();
  rlp.rlim_cur = rlim_fd_cur;
  rlp.rlim_max = rlim_fd_max;
  if ((ret = setrlimit(RLIMIT_NOFILE, &rlp)) < 0) {
    fprintf(stderr, "%s: unable to set resource limits (%s)\n", argv[0],
            strerror(errno));
    exit(ret);
  }
  if ((pw = getpwnam("ircd")) == (struct passwd *)NULL) {
    fprintf(stderr, "%s: no such user %s\n", argv[0], "ircd");
    exit(-1);
  }
  setuid(pw->pw_uid);
  setgid(pw->pw_gid);
  if ((ret = execl("/usr/local/bin/ircd", "/usr/local/bin/ircd", 0)) < 0) {
    fprintf(stderr, "%s: execl() failed for %s (reason: %s)\n", argv[0],
            "/usr/local/bin/ircd", strerror(errno));
    exit(ret);
  }
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x1000,-0x1c(%rbp)
movl   $0x1fa0,-0x20(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe1e(%rip),%rdx
call   1080 <getopt@plt>
mov    %eax,-0x14(%rbp)
mov    0x2def(%rip),%rcx
cmp    (%rcx),%eax
je     127f <main+0xcf>
mov    -0x14(%rbp),%eax
mov    %eax,-0x34(%rbp)
sub    $0x3f,%eax
je     126e <main+0xbe>
jmp    120d <main+0x5d>
mov    -0x34(%rbp),%eax
sub    $0x63,%eax
je     1240 <main+0x90>
jmp    121e <main+0x6e>
mov    -0x34(%rbp),%eax
sub    $0x68,%eax
je     126e <main+0xbe>
jmp    122f <main+0x7f>
mov    -0x34(%rbp),%eax
sub    $0x6d,%eax
je     1257 <main+0xa7>
jmp    1273 <main+0xc3>
mov    0x2d89(%rip),%rax
mov    (%rax),%rdi
call   1090 <atoi@plt>
mov    %eax,-0x1c(%rbp)
jmp    127a <main+0xca>
mov    0x2d72(%rip),%rax
mov    (%rax),%rdi
call   1090 <atoi@plt>
mov    %eax,-0x20(%rbp)
jmp    127a <main+0xca>
jmp    1273 <main+0xc3>
mov    $0x0,%al
call   1060 <usage@plt>
jmp    11d4 <main+0x24>
mov    0x2d32(%rip),%rax
mov    (%rax),%ecx
mov    -0x8(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     12a1 <main+0xf1>
mov    $0x0,%al
call   1060 <usage@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x20(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    0x2d34(%rip),%rax
mov    (%rax),%edi
lea    -0x28(%rbp),%rsi
call   1050 <setrlimit@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
jge    1310 <main+0x160>
mov    0x2cf6(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x44(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x40(%rbp)
mov    0x2cd7(%rip),%rax
mov    (%rax),%edi
call   10c0 <strerror@plt>
mov    -0x44(%rbp),%edi
mov    -0x40(%rbp),%rdx
mov    %rax,%rcx
lea    0xd05(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x18(%rbp),%edi
call   10a0 <exit@plt>
lea    0xd3b(%rip),%rdi
call   1030 <getpwnam@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
jne    1359 <main+0x1a9>
mov    0x2c97(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xced(%rip),%rsi
lea    0xd0a(%rip),%rcx
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>
mov    -0x30(%rbp),%rax
mov    0x4(%rax),%edi
call   10b0 <setuid@plt>
mov    -0x30(%rbp),%rax
mov    (%rax),%edi
call   1070 <setgid@plt>
lea    0xccc(%rip),%rsi
xor    %edx,%edx
mov    %rsi,%rdi
call   10d0 <execl@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
jge    13d9 <main+0x229>
mov    0x2c34(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x54(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x50(%rbp)
mov    0x2c15(%rip),%rax
mov    (%rax),%edi
call   10c0 <strerror@plt>
mov    -0x54(%rbp),%edi
mov    -0x50(%rbp),%rdx
mov    %rax,%r8
lea    0xc94(%rip),%rsi
lea    0xc79(%rip),%rcx
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x18(%rbp),%edi
call   10a0 <exit@plt>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%ebp
lea    0xe39(%rip),%rdx
call   1080 <getopt@plt>
mov    0x2e0d(%rip),%r13
cmp    0x0(%r13),%eax
jne    126f <main+0xbf>
mov    $0x1fa0,%r14d
mov    $0x1000,%r15d
mov    0x2dc8(%rip),%rax
cmp    %ebp,(%rax)
je     11fb <main+0x4b>
xor    %eax,%eax
call   1060 <usage@plt>
mov    %r15d,(%rsp)
mov    %r14d,0x4(%rsp)
mov    0x2ddd(%rip),%rax
mov    (%rax),%edi
mov    %rsp,%rsi
call   1050 <setrlimit@plt>
test   %eax,%eax
js     12e9 <main+0x139>
lea    0xe2e(%rip),%rdi
call   1030 <getpwnam@plt>
test   %rax,%rax
je     1324 <main+0x174>
mov    %rax,%rbp
mov    0x4(%rax),%edi
call   10b0 <setuid@plt>
mov    0x0(%rbp),%edi
call   1070 <setgid@plt>
lea    0xdf7(%rip),%rdi
mov    %rdi,%rsi
xor    %edx,%edx
call   10d0 <execl@plt>
test   %eax,%eax
js     134f <main+0x19f>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0x1000,%r15d
mov    $0x1fa0,%r14d
lea    0xd7e(%rip),%r12
jmp    12b9 <main+0x109>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    0x2d39(%rip),%rax
mov    (%rax),%rdi
call   1090 <atoi@plt>
mov    %eax,%r14d
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r12,%rdx
call   1080 <getopt@plt>
cmp    0x0(%r13),%eax
je     11e9 <main+0x39>
cmp    $0x6d,%eax
je     1290 <main+0xe0>
cmp    $0x63,%eax
jne    12e0 <main+0x130>
mov    0x2d06(%rip),%rax
mov    (%rax),%rdi
call   1090 <atoi@plt>
mov    %eax,%r15d
jmp    12a2 <main+0xf2>
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1060 <usage@plt>
jmp    12a2 <main+0xf2>
mov    %eax,%ebp
mov    0x2cd6(%rip),%rax
mov    (%rax),%r14d
mov    (%rbx),%rbx
mov    0x2cc1(%rip),%rax
mov    (%rax),%edi
call   10c0 <strerror@plt>
lea    0xcf9(%rip),%rsi
mov    %r14d,%edi
mov    %rbx,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    %ebp,%edi
call   10a0 <exit@plt>
mov    0x2c9d(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xcf7(%rip),%rsi
lea    0xd14(%rip),%rcx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>
mov    %eax,%ebp
mov    0x2c70(%rip),%rax
mov    (%rax),%r14d
mov    (%rbx),%rbx
mov    0x2c5b(%rip),%rax
mov    (%rax),%edi
call   10c0 <strerror@plt>
lea    0xce4(%rip),%rsi
lea    0xcc9(%rip),%rcx
mov    %r14d,%edi
mov    %rbx,%rdx
mov    %rax,%r8
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    %ebp,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
%struct.rlimit = type { i32, i32 }
%struct.passwd = type { i32, i32 }
@.str = [6 x i8] c"c:m:h\00"
@EOF = global i32 0
@optarg = external global i8*
@optind = external global i32
@RLIMIT_NOFILE = global i32 0
@stderr = global i32 0
@.str.1 = [40 x i8] c"%s: unable to set resource limits (%s)\0A\00"
@errno = global i32 0
@.str.2 = [5 x i8] c"ircd\00"
@.str.3 = [21 x i8] c"%s: no such user %s\0A\00"
@.str.4 = [20 x i8] c"/usr/local/bin/ircd\00"
@.str.5 = [40 x i8] c"%s: execl() failed for %s (reason: %s)\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca %struct.rlimit
%11 = alloca %struct.passwd*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 4096, i32* %8
store i32 8096, i32* %9
br label %12
12: ; preds = %29, %2
%13 = load i32, i32* %4
%14 = load i8**, i8*** %5
%15 = call i32 @getopt(i32 %13, i8** %14, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
store i32 %15, i32* %6
%16 = load i32, i32* @EOF
%17 = icmp ne i32 %15, %16
br i1 %17, label %18, label %30
18: ; preds = %12
%19 = load i32, i32* %6
switch i32 %19, label %27 [
i32 99, label %20
i32 109, label %23
i32 104, label %26
i32 63, label %26
]
20: ; preds = %18
%21 = load i8*, i8** @optarg
%22 = call i32 @atoi(i8* %21)
store i32 %22, i32* %8
br label %29
23: ; preds = %18
%24 = load i8*, i8** @optarg
%25 = call i32 @atoi(i8* %24)
store i32 %25, i32* %9
br label %29
26: ; preds = %18, %18
br label %27
27: ; preds = %18, %26
%28 = call i32 (...) @usage()
br label %29
29: ; preds = %27, %23, %20
br label %12
30: ; preds = %12
%31 = load i32, i32* @optind
%32 = load i32, i32* %4
%33 = sub nsw i32 %32, %31
store i32 %33, i32* %4
%34 = load i32, i32* %4
%35 = icmp ne i32 %34, 0
br i1 %35, label %36, label %38
36: ; preds = %30
%37 = call i32 (...) @usage()
br label %38
38: ; preds = %36, %30
%39 = load i32, i32* %8
%40 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %10, i32 0, i32 0
store i32 %39, i32* %40
%41 = load i32, i32* %9
%42 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %10, i32 0, i32 1
store i32 %41, i32* %42
%43 = load i32, i32* @RLIMIT_NOFILE
%44 = call i32 @setrlimit(i32 %43, %struct.rlimit* %10)
store i32 %44, i32* %7
%45 = icmp slt i32 %44, 0
br i1 %45, label %46, label %56
46: ; preds = %38
%47 = load i32, i32* @stderr
%48 = load i8**, i8*** %5
%49 = getelementptr inbounds i8*, i8** %48, i64 0
%50 = load i8*, i8** %49
%51 = load i32, i32* @errno
%52 = call i8* @strerror(i32 %51)
%53 = call i32 (i32, i8*, i8*, i8*, ...) @fprintf(i32 %47, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0), i8* %50, i8* %52)
%54 = load i32, i32* %7
%55 = call i32 @exit(i32 %54)
unreachable
56: ; preds = %38
%57 = call %struct.passwd* @getpwnam(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
store %struct.passwd* %57, %struct.passwd** %11
%58 = icmp eq %struct.passwd* %57, null
br i1 %58, label %59, label %66
59: ; preds = %56
%60 = load i32, i32* @stderr
%61 = load i8**, i8*** %5
%62 = getelementptr inbounds i8*, i8** %61, i64 0
%63 = load i8*, i8** %62
%64 = call i32 (i32, i8*, i8*, i8*, ...) @fprintf(i32 %60, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i8* %63, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%65 = call i32 @exit(i32 -1)
unreachable
66: ; preds = %56
%67 = load %struct.passwd*, %struct.passwd** %11
%68 = getelementptr inbounds %struct.passwd, %struct.passwd* %67, i32 0, i32 1
%69 = load i32, i32* %68
%70 = call i32 @setuid(i32 %69)
%71 = load %struct.passwd*, %struct.passwd** %11
%72 = getelementptr inbounds %struct.passwd, %struct.passwd* %71, i32 0, i32 0
%73 = load i32, i32* %72
%74 = call i32 @setgid(i32 %73)
%75 = call i32 @execl(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0), i32 0)
store i32 %75, i32* %7
%76 = icmp slt i32 %75, 0
br i1 %76, label %77, label %87
77: ; preds = %66
%78 = load i32, i32* @stderr
%79 = load i8**, i8*** %5
%80 = getelementptr inbounds i8*, i8** %79, i64 0
%81 = load i8*, i8** %80
%82 = load i32, i32* @errno
%83 = call i8* @strerror(i32 %82)
%84 = call i32 (i32, i8*, i8*, i8*, ...) @fprintf(i32 %78, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.5, i64 0, i64 0), i8* %81, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0), i8* %83)
%85 = load i32, i32* %7
%86 = call i32 @exit(i32 %85)
unreachable
87: ; preds = %66
ret i32 0
}

LLVM IR (-O2):
%struct.rlimit = type { i32, i32 }
%struct.passwd = type { i32, i32 }
@.str = [6 x i8] c"c:m:h\00"
@EOF = global i32 0
@optarg = external global i8*
@optind = external global i32
@RLIMIT_NOFILE = global i32 0
@stderr = global i32 0
@.str.1 = [40 x i8] c"%s: unable to set resource limits (%s)\0A\00"
@errno = global i32 0
@.str.2 = [5 x i8] c"ircd\00"
@.str.3 = [21 x i8] c"%s: no such user %s\0A\00"
@.str.4 = [20 x i8] c"/usr/local/bin/ircd\00"
@.str.5 = [40 x i8] c"%s: execl() failed for %s (reason: %s)\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca %struct.rlimit
%4 = bitcast %struct.rlimit* %3 to i8*
%5 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%6 = load i32, i32* @EOF
%7 = icmp eq i32 %5, %6
br i1 %7, label %26, label %8
8: ; preds = %2, %20
%9 = phi i32 [ %23, %20 ], [ %5, %2 ]
%10 = phi i32 [ %22, %20 ], [ 8096, %2 ]
%11 = phi i32 [ %21, %20 ], [ 4096, %2 ]
switch i32 %9, label %18 [
i32 99, label %12
i32 109, label %15
]
12: ; preds = %8
%13 = load i8*, i8** @optarg
%14 = tail call i32 @atoi(i8* %13)
br label %20
15: ; preds = %8
%16 = load i8*, i8** @optarg
%17 = tail call i32 @atoi(i8* %16)
br label %20
18: ; preds = %8
%19 = tail call i32 (...) @usage()
br label %20
20: ; preds = %18, %15, %12
%21 = phi i32 [ %11, %18 ], [ %11, %15 ], [ %14, %12 ]
%22 = phi i32 [ %10, %18 ], [ %17, %15 ], [ %10, %12 ]
%23 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%24 = load i32, i32* @EOF
%25 = icmp eq i32 %23, %24
br i1 %25, label %26, label %8
26: ; preds = %20, %2
%27 = phi i32 [ 4096, %2 ], [ %21, %20 ]
%28 = phi i32 [ 8096, %2 ], [ %22, %20 ]
%29 = load i32, i32* @optind
%30 = icmp eq i32 %29, %0
br i1 %30, label %33, label %31
31: ; preds = %26
%32 = tail call i32 (...) @usage()
br label %33
33: ; preds = %31, %26
%34 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %3, i64 0, i32 0
store i32 %27, i32* %34
%35 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %3, i64 0, i32 1
store i32 %28, i32* %35
%36 = load i32, i32* @RLIMIT_NOFILE
%37 = call i32 @setrlimit(i32 %36, %struct.rlimit* %3)
%38 = icmp slt i32 %37, 0
br i1 %38, label %39, label %46
39: ; preds = %33
%40 = load i32, i32* @stderr
%41 = load i8*, i8** %1
%42 = load i32, i32* @errno
%43 = call i8* @strerror(i32 %42)
%44 = call i32 (i32, i8*, i8*, i8*, ...) @fprintf(i32 %40, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0), i8* %41, i8* %43)
%45 = call i32 @exit(i32 %37)
unreachable
46: ; preds = %33
%47 = call %struct.passwd* @getpwnam(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%48 = icmp eq %struct.passwd* %47, null
br i1 %48, label %49, label %54
49: ; preds = %46
%50 = load i32, i32* @stderr
%51 = load i8*, i8** %1
%52 = call i32 (i32, i8*, i8*, i8*, ...) @fprintf(i32 %50, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i8* %51, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%53 = call i32 @exit(i32 -1)
unreachable
54: ; preds = %46
%55 = getelementptr inbounds %struct.passwd, %struct.passwd* %47, i64 0, i32 1
%56 = load i32, i32* %55
%57 = call i32 @setuid(i32 %56)
%58 = getelementptr inbounds %struct.passwd, %struct.passwd* %47, i64 0, i32 0
%59 = load i32, i32* %58
%60 = call i32 @setgid(i32 %59)
%61 = call i32 @execl(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0), i32 0)
%62 = icmp slt i32 %61, 0
br i1 %62, label %63, label %70
63: ; preds = %54
%64 = load i32, i32* @stderr
%65 = load i8*, i8** %1
%66 = load i32, i32* @errno
%67 = call i8* @strerror(i32 %66)
%68 = call i32 (i32, i8*, i8*, i8*, ...) @fprintf(i32 %64, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.5, i64 0, i64 0), i8* %65, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0), i8* %67)
%69 = call i32 @exit(i32 %61)
unreachable
70: ; preds = %54
ret i32 0
}