#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 int uid_t;
typedef int gid_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ abort();
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ free(char *);
int getline(char **, size_t *, int /*<<< orphan*/ *);
int sscanf(char *, char *, unsigned int *, unsigned int *, unsigned int *,
           unsigned int *);
int get_fs_ids(uid_t *fsuid, gid_t *fsgid) {
  unsigned r, e, s, fs;
  bool got_u = false, got_g = false;
  char *line = NULL;
  size_t len = 0;
  FILE *fp;
  *fsuid = *fsgid = -1;
  if (!((fp = fopen("/proc/self/status", "r")) != NULL))
    abort();
  while (getline(&line, &len, fp) != -1) {
    if (!got_u && sscanf(line, "Uid: %u %u %u %u", &r, &e, &s, &fs) == 4) {
      got_u = true;
      *fsuid = fs;
    }
    if (!got_g && sscanf(line, "Gid: %u %u %u %u", &r, &e, &s, &fs) == 4) {
      got_g = true;
      *fsgid = fs;
    }
    if (got_u && got_g)
      break;
  }
  if (line)
    free(line);
  return (got_u && got_g) ? 0 : -1;
}


x86 assembly (clang, -O0):
<get_fs_ids>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
mov    -0x10(%rbp),%rax
movl   $0xffffffff,(%rax)
mov    -0x8(%rbp),%rax
movl   $0xffffffff,(%rax)
lea    0xe67(%rip),%rdi
lea    0xe72(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x40(%rbp)
cmp    $0x0,%rax
jne    11ba <get_fs_ids+0x6a>
mov    $0x0,%al
call   1040 <abort@plt>
jmp    11bf <get_fs_ids+0x6f>
mov    -0x40(%rbp),%rdx
lea    -0x30(%rbp),%rdi
lea    -0x38(%rbp),%rsi
call   1070 <getline@plt>
cmp    $0xffffffff,%eax
je     127d <get_fs_ids+0x12d>
cmpl   $0x0,-0x24(%rbp)
jne    121c <get_fs_ids+0xcc>
mov    -0x30(%rbp),%rdi
lea    0xe26(%rip),%rsi
lea    -0x14(%rbp),%rdx
lea    -0x18(%rbp),%rcx
lea    -0x1c(%rbp),%r8
lea    -0x20(%rbp),%r9
call   1050 <sscanf@plt>
cmp    $0x4,%eax
jne    121c <get_fs_ids+0xcc>
movl   $0x1,-0x24(%rbp)
mov    -0x20(%rbp),%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
cmpl   $0x0,-0x28(%rbp)
jne    125f <get_fs_ids+0x10f>
mov    -0x30(%rbp),%rdi
lea    0xdf4(%rip),%rsi
lea    -0x14(%rbp),%rdx
lea    -0x18(%rbp),%rcx
lea    -0x1c(%rbp),%r8
lea    -0x20(%rbp),%r9
call   1050 <sscanf@plt>
cmp    $0x4,%eax
jne    125f <get_fs_ids+0x10f>
movl   $0x1,-0x28(%rbp)
mov    -0x20(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
cmpl   $0x0,-0x24(%rbp)
je     1278 <get_fs_ids+0x128>
cmpl   $0x0,-0x28(%rbp)
je     1278 <get_fs_ids+0x128>
jmp    127d <get_fs_ids+0x12d>
jmp    11bf <get_fs_ids+0x6f>
cmpq   $0x0,-0x30(%rbp)
je     1291 <get_fs_ids+0x141>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
cmpl   $0x0,-0x24(%rbp)
mov    %al,-0x41(%rbp)
je     12aa <get_fs_ids+0x15a>
cmpl   $0x0,-0x28(%rbp)
setne  %al
mov    %al,-0x41(%rbp)
mov    -0x41(%rbp),%dl
mov    $0xffffffff,%eax
xor    %ecx,%ecx
test   $0x1,%dl
cmovne %ecx,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_fs_ids>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
movq   $0x0,0x8(%rsp)
movq   $0x0,0x30(%rsp)
mov    %rsi,0x28(%rsp)
movl   $0xffffffff,(%rsi)
mov    %rdi,0x20(%rsp)
movl   $0xffffffff,(%rdi)
lea    0xe73(%rip),%rdi
lea    0xe7e(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     12d6 <get_fs_ids+0x186>
mov    %rax,%rbx
xor    %r15d,%r15d
xor    %r14d,%r14d
jmp    11c0 <get_fs_ids+0x70>
nopl   (%rax)
and    %r12b,%bpl
mov    %r13d,%r15d
cmp    $0x1,%bpl
je     1299 <get_fs_ids+0x149>
lea    0x8(%rsp),%rdi
lea    0x30(%rsp),%rsi
mov    %rbx,%rdx
call   1070 <getline@plt>
cmp    $0xffffffff,%eax
je     12a5 <get_fs_ids+0x155>
mov    $0x1,%r13d
mov    $0x1,%r12b
mov    $0x1,%bpl
test   %r14d,%r14d
mov    $0x1,%r14d
jne    1240 <get_fs_ids+0xf0>
mov    0x8(%rsp),%rdi
lea    0xe16(%rip),%rsi
lea    0x1c(%rsp),%rdx
lea    0x18(%rsp),%rcx
lea    0x14(%rsp),%r8
lea    0x4(%rsp),%r9
call   1050 <sscanf@plt>
xor    %ebp,%ebp
mov    $0x0,%r14d
cmp    $0x4,%eax
jne    1240 <get_fs_ids+0xf0>
mov    0x4(%rsp),%eax
mov    0x20(%rsp),%rcx
mov    %eax,(%rcx)
mov    $0x1,%bpl
mov    $0x1,%r14d
nopl   0x0(%rax,%rax,1)
test   %r15d,%r15d
jne    11b0 <get_fs_ids+0x60>
mov    0x8(%rsp),%rdi
lea    0xdd0(%rip),%rsi
lea    0x1c(%rsp),%rdx
lea    0x18(%rsp),%rcx
lea    0x14(%rsp),%r8
lea    0x4(%rsp),%r9
call   1050 <sscanf@plt>
xor    %r12d,%r12d
mov    $0x0,%r13d
cmp    $0x4,%eax
jne    11b0 <get_fs_ids+0x60>
mov    0x4(%rsp),%eax
mov    0x28(%rsp),%rcx
mov    %eax,(%rcx)
mov    $0x1,%r12b
mov    $0x1,%r13d
jmp    11b0 <get_fs_ids+0x60>
mov    $0x1,%r15d
mov    $0x1,%r14d
mov    0x8(%rsp),%rdi
test   %rdi,%rdi
je     12b4 <get_fs_ids+0x164>
call   1030 <free@plt>
test   %r14d,%r14d
sete   %al
test   %r15d,%r15d
sete   %cl
or     %al,%cl
movzbl %cl,%eax
neg    %eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %eax,%eax
call   1040 <abort@plt>

LLVM IR (-O0):
@.str = [18 x i8] c"/proc/self/status\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [17 x i8] c"Uid: %u %u %u %u\00"
@.str.3 = [17 x i8] c"Gid: %u %u %u %u\00"
define i32 @get_fs_ids(i32* %0, i32* %1) {
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i8*
%12 = alloca i64
%13 = alloca i32*
store i32* %0, i32** %3
store i32* %1, i32** %4
store i32 0, i32* %9
store i32 0, i32* %10
store i8* null, i8** %11
store i64 0, i64* %12
%14 = load i32*, i32** %4
store i32 -1, i32* %14
%15 = load i32*, i32** %3
store i32 -1, i32* %15
%16 = call i32* @fopen(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %16, i32** %13
%17 = icmp ne i32* %16, null
br i1 %17, label %20, label %18
18: ; preds = %2
%19 = call i32 (...) @abort()
unreachable
20: ; preds = %2
br label %21
21: ; preds = %52, %20
%22 = load i32*, i32** %13
%23 = call i32 @getline(i8** %11, i64* %12, i32* %22)
%24 = icmp ne i32 %23, -1
br i1 %24, label %25, label %53
25: ; preds = %21
%26 = load i32, i32* %9
%27 = icmp ne i32 %26, 0
br i1 %27, label %35, label %28
28: ; preds = %25
%29 = load i8*, i8** %11
%30 = call i32 @sscanf(i8* %29, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i32* %5, i32* %6, i32* %7, i32* %8)
%31 = icmp eq i32 %30, 4
br i1 %31, label %32, label %35
32: ; preds = %28
store i32 1, i32* %9
%33 = load i32, i32* %8
%34 = load i32*, i32** %3
store i32 %33, i32* %34
br label %35
35: ; preds = %32, %28, %25
%36 = load i32, i32* %10
%37 = icmp ne i32 %36, 0
br i1 %37, label %45, label %38
38: ; preds = %35
%39 = load i8*, i8** %11
%40 = call i32 @sscanf(i8* %39, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), i32* %5, i32* %6, i32* %7, i32* %8)
%41 = icmp eq i32 %40, 4
br i1 %41, label %42, label %45
42: ; preds = %38
store i32 1, i32* %10
%43 = load i32, i32* %8
%44 = load i32*, i32** %4
store i32 %43, i32* %44
br label %45
45: ; preds = %42, %38, %35
%46 = load i32, i32* %9
%47 = icmp ne i32 %46, 0
br i1 %47, label %48, label %52
48: ; preds = %45
%49 = load i32, i32* %10
%50 = icmp ne i32 %49, 0
br i1 %50, label %51, label %52
51: ; preds = %48
br label %53
52: ; preds = %48, %45
br label %21
53: ; preds = %51, %21
%54 = load i8*, i8** %11
%55 = icmp ne i8* %54, null
br i1 %55, label %56, label %59
56: ; preds = %53
%57 = load i8*, i8** %11
%58 = call i32 @free(i8* %57)
br label %59
59: ; preds = %56, %53
%60 = load i32, i32* %9
%61 = icmp ne i32 %60, 0
br i1 %61, label %62, label %65
62: ; preds = %59
%63 = load i32, i32* %10
%64 = icmp ne i32 %63, 0
br label %65
65: ; preds = %62, %59
%66 = phi i1 [ false, %59 ], [ %64, %62 ]
%67 = zext i1 %66 to i64
%68 = select i1 %66, i32 0, i32 -1
ret i32 %68
}

LLVM IR (-O2):
@.str = [18 x i8] c"/proc/self/status\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [17 x i8] c"Uid: %u %u %u %u\00"
@.str.3 = [17 x i8] c"Gid: %u %u %u %u\00"
define i32 @get_fs_ids(i32* nocapture writeonly %0, i32* nocapture writeonly %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i64
%9 = bitcast i32* %3 to i8*
%10 = bitcast i32* %4 to i8*
%11 = bitcast i32* %5 to i8*
%12 = bitcast i32* %6 to i8*
%13 = bitcast i8** %7 to i8*
store i8* null, i8** %7
%14 = bitcast i64* %8 to i8*
store i64 0, i64* %8
store i32 -1, i32* %1
store i32 -1, i32* %0
%15 = tail call i32* @fopen(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%16 = icmp eq i32* %15, null
br i1 %16, label %17, label %19
17: ; preds = %2
%18 = tail call i32 (...) @abort()
unreachable
19: ; preds = %2, %42
%20 = phi i32 [ %44, %42 ], [ 0, %2 ]
%21 = phi i32 [ %34, %42 ], [ 0, %2 ]
%22 = call i32 @getline(i8** %7, i64* %8, i32* %15)
%23 = icmp eq i32 %22, -1
br i1 %23, label %46, label %24
24: ; preds = %19
%25 = icmp eq i32 %21, 0
br i1 %25, label %26, label %32
26: ; preds = %24
%27 = load i8*, i8** %7
%28 = call i32 @sscanf(i8* %27, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i32* %3, i32* %4, i32* %5, i32* %6)
%29 = icmp eq i32 %28, 4
br i1 %29, label %30, label %32
30: ; preds = %26
%31 = load i32, i32* %6
store i32 %31, i32* %0
br label %32
32: ; preds = %30, %26, %24
%33 = phi i1 [ true, %30 ], [ false, %26 ], [ true, %24 ]
%34 = phi i32 [ 1, %30 ], [ 0, %26 ], [ 1, %24 ]
%35 = icmp eq i32 %20, 0
br i1 %35, label %36, label %42
36: ; preds = %32
%37 = load i8*, i8** %7
%38 = call i32 @sscanf(i8* %37, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), i32* %3, i32* %4, i32* %5, i32* %6)
%39 = icmp eq i32 %38, 4
br i1 %39, label %40, label %42
40: ; preds = %36
%41 = load i32, i32* %6
store i32 %41, i32* %1
br label %42
42: ; preds = %40, %36, %32
%43 = phi i1 [ true, %40 ], [ false, %36 ], [ true, %32 ]
%44 = phi i32 [ 1, %40 ], [ 0, %36 ], [ 1, %32 ]
%45 = and i1 %33, %43
br i1 %45, label %46, label %19
46: ; preds = %42, %19
%47 = phi i32 [ 1, %42 ], [ %20, %19 ]
%48 = phi i32 [ 1, %42 ], [ %21, %19 ]
%49 = load i8*, i8** %7
%50 = icmp eq i8* %49, null
br i1 %50, label %53, label %51
51: ; preds = %46
%52 = call i32 @free(i8* %49)
br label %53
53: ; preds = %51, %46
%54 = icmp eq i32 %48, 0
%55 = icmp eq i32 %47, 0
%56 = or i1 %55, %54
%57 = sext i1 %56 to i32
ret i32 %57
}