#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 passwd {
  scalar_t__ pw_uid;
  scalar_t__ pw_gid;
  int /*<<< orphan*/ pw_name;
};
struct group {
  int /*<<< orphan*/ gr_name;
};
typedef int mode_t;

/* Variables and functions */
struct group *getgrgid(scalar_t__);
scalar_t__ strcmp(int /*<<< orphan*/, int /*<<< orphan*/);
int umask(int);
void setup_limits(const struct passwd *info) {
  const struct group *grp;
  mode_t oldmask;
  if (info->pw_uid != 0 && info->pw_uid == info->pw_gid) {
    grp = getgrgid(info->pw_gid);
    if (grp && (strcmp(info->pw_name, grp->gr_name) == 0)) {
      oldmask = umask(0777);
      umask((oldmask & ~070) | ((oldmask >> 3) & 070));
    }
  }
}


x86 assembly (clang, -O0):
<setup_limits>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
cmpq   $0x0,(%rax)
je     11bf <setup_limits+0x8f>
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    -0x8(%rbp),%rcx
cmp    0x8(%rcx),%rax
jne    11bf <setup_limits+0x8f>
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%rdi
call   1030 <getgrgid@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11ba <setup_limits+0x8a>
mov    -0x8(%rbp),%rax
mov    0x10(%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%esi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    11ba <setup_limits+0x8a>
mov    $0x1ff,%edi
call   1050 <umask@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
and    $0xffffffc7,%edi
mov    -0x14(%rbp),%eax
sar    $0x3,%eax
and    $0x38,%eax
or     %eax,%edi
call   1050 <umask@plt>
jmp    11bf <setup_limits+0x8f>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<setup_limits>:
push   %rbx
mov    %rdi,%rbx
mov    (%rdi),%rdi
test   %rdi,%rdi
je     115b <setup_limits+0x2b>
cmp    0x8(%rbx),%rdi
jne    115b <setup_limits+0x2b>
call   1030 <getgrgid@plt>
test   %rax,%rax
je     115b <setup_limits+0x2b>
mov    0x10(%rbx),%edi
mov    (%rax),%esi
call   1040 <strcmp@plt>
test   %rax,%rax
je     115d <setup_limits+0x2d>
pop    %rbx
ret
mov    $0x1ff,%edi
call   1050 <umask@plt>
mov    %eax,%edi
and    $0xffffffc7,%edi
shr    $0x3,%eax
and    $0x38,%eax
or     %eax,%edi
pop    %rbx
jmp    1050 <umask@plt>

LLVM IR (-O0):
%struct.passwd = type { i64, i64, i32 }
%struct.group = type { i32 }
define void @setup_limits(%struct.passwd* %0) {
%2 = alloca %struct.passwd*
%3 = alloca %struct.group*
%4 = alloca i32
store %struct.passwd* %0, %struct.passwd** %2
%5 = load %struct.passwd*, %struct.passwd** %2
%6 = getelementptr inbounds %struct.passwd, %struct.passwd* %5, i32 0, i32 0
%7 = load i64, i64* %6
%8 = icmp ne i64 %7, 0
br i1 %8, label %9, label %43
9: ; preds = %1
%10 = load %struct.passwd*, %struct.passwd** %2
%11 = getelementptr inbounds %struct.passwd, %struct.passwd* %10, i32 0, i32 0
%12 = load i64, i64* %11
%13 = load %struct.passwd*, %struct.passwd** %2
%14 = getelementptr inbounds %struct.passwd, %struct.passwd* %13, i32 0, i32 1
%15 = load i64, i64* %14
%16 = icmp eq i64 %12, %15
br i1 %16, label %17, label %43
17: ; preds = %9
%18 = load %struct.passwd*, %struct.passwd** %2
%19 = getelementptr inbounds %struct.passwd, %struct.passwd* %18, i32 0, i32 1
%20 = load i64, i64* %19
%21 = call %struct.group* @getgrgid(i64 %20)
store %struct.group* %21, %struct.group** %3
%22 = load %struct.group*, %struct.group** %3
%23 = icmp ne %struct.group* %22, null
br i1 %23, label %24, label %42
24: ; preds = %17
%25 = load %struct.passwd*, %struct.passwd** %2
%26 = getelementptr inbounds %struct.passwd, %struct.passwd* %25, i32 0, i32 2
%27 = load i32, i32* %26
%28 = load %struct.group*, %struct.group** %3
%29 = getelementptr inbounds %struct.group, %struct.group* %28, i32 0, i32 0
%30 = load i32, i32* %29
%31 = call i64 @strcmp(i32 %27, i32 %30)
%32 = icmp eq i64 %31, 0
br i1 %32, label %33, label %42
33: ; preds = %24
%34 = call i32 @umask(i32 511)
store i32 %34, i32* %4
%35 = load i32, i32* %4
%36 = and i32 %35, -57
%37 = load i32, i32* %4
%38 = ashr i32 %37, 3
%39 = and i32 %38, 56
%40 = or i32 %36, %39
%41 = call i32 @umask(i32 %40)
br label %42
42: ; preds = %33, %24, %17
br label %43
43: ; preds = %42, %9, %1
ret void
}

LLVM IR (-O2):
%struct.passwd = type { i64, i64, i32 }
%struct.group = type { i32 }
define void @setup_limits(%struct.passwd* nocapture %0) {
%2 = getelementptr inbounds %struct.passwd, %struct.passwd* %0, i64 0, i32 0
%3 = load i64, i64* %2
%4 = icmp eq i64 %3, 0
br i1 %4, label %26, label %5
5: ; preds = %1
%6 = getelementptr inbounds %struct.passwd, %struct.passwd* %0, i64 0, i32 1
%7 = load i64, i64* %6
%8 = icmp eq i64 %3, %7
br i1 %8, label %9, label %26
9: ; preds = %5
%10 = tail call %struct.group* @getgrgid(i64 %3)
%11 = icmp eq %struct.group* %10, null
br i1 %11, label %26, label %12
12: ; preds = %9
%13 = getelementptr inbounds %struct.passwd, %struct.passwd* %0, i64 0, i32 2
%14 = load i32, i32* %13
%15 = getelementptr inbounds %struct.group, %struct.group* %10, i64 0, i32 0
%16 = load i32, i32* %15
%17 = tail call i64 @strcmp(i32 %14, i32 %16)
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %26
19: ; preds = %12
%20 = tail call i32 @umask(i32 511)
%21 = and i32 %20, -57
%22 = lshr i32 %20, 3
%23 = and i32 %22, 56
%24 = or i32 %23, %21
%25 = tail call i32 @umask(i32 %24)
br label %26
26: ; preds = %9, %12, %19, %5, %1
ret void
}