#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__ uid_t;
struct stat {
  scalar_t__ st_uid;
  scalar_t__ st_gid;
};
struct passwd {
  char *pw_name;
  scalar_t__ pw_uid;
};
typedef scalar_t__ gid_t;

/* Variables and functions */
scalar_t__ EPERM;
int O_CREAT;
int O_RDWR;
int O_TRUNC;
int S_IRGRP;
int S_IROTH;
int S_IRUSR;
int S_IWGRP;
int S_IWOTH;
int S_IWUSR;
scalar_t__ errno;
scalar_t__ fstat(int, struct stat *);
scalar_t__ ftruncate(int, int);
struct passwd *getpwent();
scalar_t__ getuid();
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ seteuid(scalar_t__);
int shm_open(char *, int, int);
int /*<<< orphan*/ shm_unlink(char *);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ umask(int /*<<< orphan*/);
int main(void) {
  int fd;
  struct stat stat_buf;
  struct passwd *pw;
  uid_t old_uid;
  gid_t old_gid;
  umask(0);
  fd = shm_open("posixtest_26-2", O_RDWR | O_CREAT,
                S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH);
  if (fd == -1) {
    perror("An error occurs when calling shm_open()");
    return 2;
  }
  if (ftruncate(fd, 8) != 0) {
    perror("An error occurs when calling ftruncate()");
    shm_unlink("posixtest_26-2");
    return 2;
  }
  if (fstat(fd, &stat_buf) != 0) {
    perror("An error occurs when calling fstat()");
    shm_unlink("posixtest_26-2");
    return 2;
  }
  old_uid = stat_buf.st_uid;
  old_gid = stat_buf.st_gid;
  while ((pw = getpwent()) != NULL)
    if (strcmp(pw->pw_name, "root") && pw->pw_uid != getuid())
      break;
  if (pw == NULL) {
    printf("There is no other user than current and root.\n");
    shm_unlink("posixtest_26-2");
    return 2;
  }
  if (seteuid(pw->pw_uid) != 0) {
    if (errno == EPERM) {
      printf("You don't have permission to change your UID.\nTry to rerun this "
             "test as root.\n");
    } else {
      perror("An error occurs when calling seteuid()");
    }
    shm_unlink("posixtest_26-2");
    return 2;
  }
  printf("Testing with user '%s' (uid: %i)\n", pw->pw_name, pw->pw_uid);
  fd = shm_open("posixtest_26-2", O_RDWR | O_TRUNC, 0);
  if (fd == -1) {
    perror("An error occurs when calling shm_open()");
    seteuid(getuid());
    shm_unlink("posixtest_26-2");
    return 2;
  }
  if (fstat(fd, &stat_buf) != 0) {
    perror("An error occurs when calling fstat()");
    seteuid(getuid());
    shm_unlink("posixtest_26-2");
    return 2;
  }
  seteuid(getuid());
  shm_unlink("posixtest_26-2");
  if (stat_buf.st_uid == old_uid && stat_buf.st_gid == old_gid) {
    printf("Test PASSED\n");
    return 0;
  }
  if (stat_buf.st_uid != old_uid)
    printf("The user ID has changed.\n");
  if (stat_buf.st_gid != old_gid)
    printf("The group ID has changed.\n");
  return 1;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
xor    %edi,%edi
call   1070 <umask@plt>
mov    0x2e0b(%rip),%rax
mov    (%rax),%esi
mov    0x2e22(%rip),%rax
or     (%rax),%esi
mov    0x2dc1(%rip),%rax
mov    (%rax),%edx
mov    0x2de0(%rip),%rax
or     (%rax),%edx
mov    0x2dbf(%rip),%rax
or     (%rax),%edx
mov    0x2dd6(%rip),%rax
or     (%rax),%edx
mov    0x2da5(%rip),%rax
or     (%rax),%edx
mov    0x2d84(%rip),%rax
or     (%rax),%edx
lea    0xdeb(%rip),%rdi
call   10a0 <shm_open@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
jne    123f <main+0x8f>
lea    0xde1(%rip),%rdi
call   1090 <perror@plt>
movl   $0x2,-0x4(%rbp)
jmp    1512 <main+0x362>
mov    -0x8(%rbp),%edi
mov    $0x8,%esi
call   1050 <ftruncate@plt>
cmp    $0x0,%rax
je     127a <main+0xca>
lea    0xdda(%rip),%rdi
call   1090 <perror@plt>
lea    0xd97(%rip),%rdi
call   10b0 <shm_unlink@plt>
movl   $0x2,-0x4(%rbp)
jmp    1512 <main+0x362>
mov    -0x8(%rbp),%edi
lea    -0x18(%rbp),%rsi
call   10c0 <fstat@plt>
cmp    $0x0,%rax
je     12b4 <main+0x104>
lea    0xdc9(%rip),%rdi
call   1090 <perror@plt>
lea    0xd5d(%rip),%rdi
call   10b0 <shm_unlink@plt>
movl   $0x2,-0x4(%rbp)
jmp    1512 <main+0x362>
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    $0x0,%al
call   1080 <getpwent@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     1323 <main+0x173>
mov    -0x20(%rbp),%rax
mov    (%rax),%rdi
lea    0xd9e(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
je     131e <main+0x16e>
mov    -0x20(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x38(%rbp)
mov    $0x0,%al
call   1030 <getuid@plt>
mov    %rax,%rcx
mov    -0x38(%rbp),%rax
cmp    %rcx,%rax
je     131e <main+0x16e>
jmp    1323 <main+0x173>
jmp    12c4 <main+0x114>
cmpq   $0x0,-0x20(%rbp)
jne    1354 <main+0x1a4>
lea    0xd55(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xcbd(%rip),%rdi
call   10b0 <shm_unlink@plt>
movl   $0x2,-0x4(%rbp)
jmp    1512 <main+0x362>
mov    -0x20(%rbp),%rax
mov    0x8(%rax),%rdi
call   10d0 <seteuid@plt>
cmp    $0x0,%rax
je     13bc <main+0x20c>
mov    0x2c46(%rip),%rax
mov    (%rax),%rax
mov    0x2c0c(%rip),%rcx
cmp    (%rcx),%rax
jne    1398 <main+0x1e8>
lea    0xd2d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    13a4 <main+0x1f4>
lea    0xd69(%rip),%rdi
call   1090 <perror@plt>
lea    0xc55(%rip),%rdi
call   10b0 <shm_unlink@plt>
movl   $0x2,-0x4(%rbp)
jmp    1512 <main+0x362>
mov    -0x20(%rbp),%rax
mov    (%rax),%rsi
mov    -0x20(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xd5d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2bf8(%rip),%rax
mov    (%rax),%esi
mov    0x2c07(%rip),%rax
or     (%rax),%esi
lea    0xc0e(%rip),%rdi
xor    %edx,%edx
call   10a0 <shm_open@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
jne    1439 <main+0x289>
lea    0xc02(%rip),%rdi
call   1090 <perror@plt>
mov    $0x0,%al
call   1030 <getuid@plt>
mov    %rax,%rdi
call   10d0 <seteuid@plt>
lea    0xbd8(%rip),%rdi
call   10b0 <shm_unlink@plt>
movl   $0x2,-0x4(%rbp)
jmp    1512 <main+0x362>
mov    -0x8(%rbp),%edi
lea    -0x18(%rbp),%rsi
call   10c0 <fstat@plt>
cmp    $0x0,%rax
je     1482 <main+0x2d2>
lea    0xc0a(%rip),%rdi
call   1090 <perror@plt>
mov    $0x0,%al
call   1030 <getuid@plt>
mov    %rax,%rdi
call   10d0 <seteuid@plt>
lea    0xb8f(%rip),%rdi
call   10b0 <shm_unlink@plt>
movl   $0x2,-0x4(%rbp)
jmp    1512 <main+0x362>
mov    $0x0,%al
call   1030 <getuid@plt>
mov    %rax,%rdi
call   10d0 <seteuid@plt>
lea    0xb68(%rip),%rdi
call   10b0 <shm_unlink@plt>
mov    -0x18(%rbp),%rax
cmp    -0x28(%rbp),%rax
jne    14d3 <main+0x323>
mov    -0x10(%rbp),%rax
cmp    -0x30(%rbp),%rax
jne    14d3 <main+0x323>
lea    0xc91(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1512 <main+0x362>
mov    -0x18(%rbp),%rax
cmp    -0x28(%rbp),%rax
je     14ef <main+0x33f>
lea    0xc76(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rax
cmp    -0x30(%rbp),%rax
je     150b <main+0x35b>
lea    0xc74(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
xor    %edi,%edi
call   1080 <umask@plt>
mov    0x2dfc(%rip),%r12
mov    0x2e15(%rip),%rax
mov    (%rax),%esi
or     (%r12),%esi
mov    0x2db0(%rip),%rax
mov    0x2dd1(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    0x2dae(%rip),%rax
or     (%rax),%edx
mov    0x2dc5(%rip),%rax
or     (%rax),%edx
mov    0x2d94(%rip),%rax
or     (%rax),%edx
mov    0x2d73(%rip),%rax
or     (%rax),%edx
lea    0xdda(%rip),%rdi
call   10b0 <shm_open@plt>
cmp    $0xffffffff,%eax
je     13ae <main+0x1ee>
mov    %eax,%ebx
mov    %eax,%edi
mov    $0x8,%esi
call   1060 <ftruncate@plt>
test   %rax,%rax
jne    13bf <main+0x1ff>
lea    0x8(%rsp),%rsi
mov    %ebx,%edi
call   10d0 <fstat@plt>
test   %rax,%rax
jne    13c8 <main+0x208>
mov    0x8(%rsp),%r13
mov    0x10(%rsp),%r15
xor    %eax,%eax
call   1090 <getpwent@plt>
test   %rax,%rax
je     12f0 <main+0x130>
mov    %rax,%rbx
lea    0xe05(%rip),%r14
jmp    129f <main+0xdf>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
xor    %eax,%eax
call   1090 <getpwent@plt>
mov    %rax,%rbx
test   %rax,%rax
je     12f0 <main+0x130>
mov    (%rbx),%rdi
mov    %r14,%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
je     1290 <main+0xd0>
mov    0x8(%rbx),%rbp
xor    %eax,%eax
call   1040 <getuid@plt>
cmp    %rax,%rbp
je     1290 <main+0xd0>
mov    0x8(%rbx),%rdi
call   10e0 <seteuid@plt>
test   %rax,%rax
je     131e <main+0x15e>
mov    0x2ce4(%rip),%rax
mov    (%rax),%rax
mov    0x2caa(%rip),%rcx
cmp    (%rcx),%rax
jne    1409 <main+0x249>
lea    0xe24(%rip),%rdi
jmp    12f7 <main+0x137>
lea    0xe69(%rip),%rdi
call   1030 <puts@plt>
lea    0xcfd(%rip),%rdi
call   10c0 <shm_unlink@plt>
mov    $0x2,%ebx
mov    %ebx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    (%rbx),%rsi
mov    0x8(%rbx),%rdx
lea    0xd85(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x2cb6(%rip),%rax
mov    (%rax),%esi
or     (%r12),%esi
lea    0xcb9(%rip),%rdi
xor    %edx,%edx
call   10b0 <shm_open@plt>
cmp    $0xffffffff,%eax
je     1412 <main+0x252>
lea    0x8(%rsp),%rsi
mov    %eax,%edi
call   10d0 <fstat@plt>
test   %rax,%rax
jne    141b <main+0x25b>
xor    %eax,%eax
call   1040 <getuid@plt>
mov    %rax,%rdi
call   10e0 <seteuid@plt>
lea    0xc7e(%rip),%rdi
call   10c0 <shm_unlink@plt>
mov    0x8(%rsp),%rax
mov    0x10(%rsp),%r14
cmp    %r13,%rax
jne    13d9 <main+0x219>
cmp    %r15,%r14
jne    13d9 <main+0x219>
lea    0xd64(%rip),%rdi
call   1030 <puts@plt>
xor    %ebx,%ebx
jmp    130d <main+0x14d>
lea    0xc5a(%rip),%rdi
call   10a0 <perror@plt>
jmp    1308 <main+0x148>
lea    0xc71(%rip),%rdi
jmp    13cf <main+0x20f>
lea    0xc91(%rip),%rdi
call   10a0 <perror@plt>
jmp    12fc <main+0x13c>
cmp    %r13,%rax
je     13ea <main+0x22a>
lea    0xd08(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%ebx
cmp    %r15,%r14
je     130d <main+0x14d>
lea    0xcd4(%rip),%rdi
call   1030 <puts@plt>
jmp    130d <main+0x14d>
lea    0xc7a(%rip),%rdi
jmp    13cf <main+0x20f>
lea    0xbf6(%rip),%rdi
jmp    1422 <main+0x262>
lea    0xc3e(%rip),%rdi
call   10a0 <perror@plt>
xor    %eax,%eax
call   1040 <getuid@plt>
mov    %rax,%rdi
call   10e0 <seteuid@plt>
jmp    12fc <main+0x13c>

LLVM IR (-O0):
%struct.stat = type { i64, i64 }
%struct.passwd = type { i8*, i64 }
@.str = [15 x i8] c"posixtest_26-2\00"
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@S_IRGRP = global i32 0
@S_IWGRP = global i32 0
@S_IROTH = global i32 0
@S_IWOTH = global i32 0
@.str.1 = [40 x i8] c"An error occurs when calling shm_open()\00"
@.str.2 = [41 x i8] c"An error occurs when calling ftruncate()\00"
@.str.3 = [37 x i8] c"An error occurs when calling fstat()\00"
@.str.4 = [5 x i8] c"root\00"
@.str.5 = [47 x i8] c"There is no other user than current and root.\0A\00"
@errno = global i64 0
@EPERM = global i64 0
@.str.6 = [79 x i8] c"You don't have permission to change your UID.\0ATry to rerun this test as root.\0A\00"
@.str.7 = [39 x i8] c"An error occurs when calling seteuid()\00"
@.str.8 = [34 x i8] c"Testing with user '%s' (uid: %i)\0A\00"
@O_TRUNC = global i32 0
@.str.9 = [13 x i8] c"Test PASSED\0A\00"
@.str.10 = [26 x i8] c"The user ID has changed.\0A\00"
@.str.11 = [27 x i8] c"The group ID has changed.\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca %struct.stat
%4 = alloca %struct.passwd*
%5 = alloca i64
%6 = alloca i64
store i32 0, i32* %1
%7 = call i32 @umask(i32 0)
%8 = load i32, i32* @O_RDWR
%9 = load i32, i32* @O_CREAT
%10 = or i32 %8, %9
%11 = load i32, i32* @S_IRUSR
%12 = load i32, i32* @S_IWUSR
%13 = or i32 %11, %12
%14 = load i32, i32* @S_IRGRP
%15 = or i32 %13, %14
%16 = load i32, i32* @S_IWGRP
%17 = or i32 %15, %16
%18 = load i32, i32* @S_IROTH
%19 = or i32 %17, %18
%20 = load i32, i32* @S_IWOTH
%21 = or i32 %19, %20
%22 = call i32 @shm_open(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %10, i32 %21)
store i32 %22, i32* %2
%23 = load i32, i32* %2
%24 = icmp eq i32 %23, -1
br i1 %24, label %25, label %27
25: ; preds = %0
%26 = call i32 @perror(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0))
store i32 2, i32* %1
br label %143
27: ; preds = %0
%28 = load i32, i32* %2
%29 = call i64 @ftruncate(i32 %28, i32 8)
%30 = icmp ne i64 %29, 0
br i1 %30, label %31, label %34
31: ; preds = %27
%32 = call i32 @perror(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.2, i64 0, i64 0))
%33 = call i32 @shm_unlink(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
store i32 2, i32* %1
br label %143
34: ; preds = %27
%35 = load i32, i32* %2
%36 = call i64 @fstat(i32 %35, %struct.stat* %3)
%37 = icmp ne i64 %36, 0
br i1 %37, label %38, label %41
38: ; preds = %34
%39 = call i32 @perror(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.3, i64 0, i64 0))
%40 = call i32 @shm_unlink(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
store i32 2, i32* %1
br label %143
41: ; preds = %34
%42 = getelementptr inbounds %struct.stat, %struct.stat* %3, i32 0, i32 0
%43 = load i64, i64* %42
store i64 %43, i64* %5
%44 = getelementptr inbounds %struct.stat, %struct.stat* %3, i32 0, i32 1
%45 = load i64, i64* %44
store i64 %45, i64* %6
br label %46
46: ; preds = %62, %41
%47 = call %struct.passwd* (...) @getpwent()
store %struct.passwd* %47, %struct.passwd** %4
%48 = icmp ne %struct.passwd* %47, null
br i1 %48, label %49, label %63
49: ; preds = %46
%50 = load %struct.passwd*, %struct.passwd** %4
%51 = getelementptr inbounds %struct.passwd, %struct.passwd* %50, i32 0, i32 0
%52 = load i8*, i8** %51
%53 = call i64 @strcmp(i8* %52, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%54 = icmp ne i64 %53, 0
br i1 %54, label %55, label %62
55: ; preds = %49
%56 = load %struct.passwd*, %struct.passwd** %4
%57 = getelementptr inbounds %struct.passwd, %struct.passwd* %56, i32 0, i32 1
%58 = load i64, i64* %57
%59 = call i64 (...) @getuid()
%60 = icmp ne i64 %58, %59
br i1 %60, label %61, label %62
61: ; preds = %55
br label %63
62: ; preds = %55, %49
br label %46
63: ; preds = %61, %46
%64 = load %struct.passwd*, %struct.passwd** %4
%65 = icmp eq %struct.passwd* %64, null
br i1 %65, label %66, label %69
66: ; preds = %63
%67 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.5, i64 0, i64 0))
%68 = call i32 @shm_unlink(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
store i32 2, i32* %1
br label %143
69: ; preds = %63
%70 = load %struct.passwd*, %struct.passwd** %4
%71 = getelementptr inbounds %struct.passwd, %struct.passwd* %70, i32 0, i32 1
%72 = load i64, i64* %71
%73 = call i64 @seteuid(i64 %72)
%74 = icmp ne i64 %73, 0
br i1 %74, label %75, label %85
75: ; preds = %69
%76 = load i64, i64* @errno
%77 = load i64, i64* @EPERM
%78 = icmp eq i64 %76, %77
br i1 %78, label %79, label %81
79: ; preds = %75
%80 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([79 x i8], [79 x i8]* @.str.6, i64 0, i64 0))
br label %83
81: ; preds = %75
%82 = call i32 @perror(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.7, i64 0, i64 0))
br label %83
83: ; preds = %81, %79
%84 = call i32 @shm_unlink(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
store i32 2, i32* %1
br label %143
85: ; preds = %69
%86 = load %struct.passwd*, %struct.passwd** %4
%87 = getelementptr inbounds %struct.passwd, %struct.passwd* %86, i32 0, i32 0
%88 = load i8*, i8** %87
%89 = load %struct.passwd*, %struct.passwd** %4
%90 = getelementptr inbounds %struct.passwd, %struct.passwd* %89, i32 0, i32 1
%91 = load i64, i64* %90
%92 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.8, i64 0, i64 0), i8* %88, i64 %91)
%93 = load i32, i32* @O_RDWR
%94 = load i32, i32* @O_TRUNC
%95 = or i32 %93, %94
%96 = call i32 @shm_open(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %95, i32 0)
store i32 %96, i32* %2
%97 = load i32, i32* %2
%98 = icmp eq i32 %97, -1
br i1 %98, label %99, label %104
99: ; preds = %85
%100 = call i32 @perror(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0))
%101 = call i64 (...) @getuid()
%102 = call i64 @seteuid(i64 %101)
%103 = call i32 @shm_unlink(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
store i32 2, i32* %1
br label %143
104: ; preds = %85
%105 = load i32, i32* %2
%106 = call i64 @fstat(i32 %105, %struct.stat* %3)
%107 = icmp ne i64 %106, 0
br i1 %107, label %108, label %113
108: ; preds = %104
%109 = call i32 @perror(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.3, i64 0, i64 0))
%110 = call i64 (...) @getuid()
%111 = call i64 @seteuid(i64 %110)
%112 = call i32 @shm_unlink(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
store i32 2, i32* %1
br label %143
113: ; preds = %104
%114 = call i64 (...) @getuid()
%115 = call i64 @seteuid(i64 %114)
%116 = call i32 @shm_unlink(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%117 = getelementptr inbounds %struct.stat, %struct.stat* %3, i32 0, i32 0
%118 = load i64, i64* %117
%119 = load i64, i64* %5
%120 = icmp eq i64 %118, %119
br i1 %120, label %121, label %128
121: ; preds = %113
%122 = getelementptr inbounds %struct.stat, %struct.stat* %3, i32 0, i32 1
%123 = load i64, i64* %122
%124 = load i64, i64* %6
%125 = icmp eq i64 %123, %124
br i1 %125, label %126, label %128
126: ; preds = %121
%127 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.9, i64 0, i64 0))
store i32 0, i32* %1
br label %143
128: ; preds = %121, %113
%129 = getelementptr inbounds %struct.stat, %struct.stat* %3, i32 0, i32 0
%130 = load i64, i64* %129
%131 = load i64, i64* %5
%132 = icmp ne i64 %130, %131
br i1 %132, label %133, label %135
133: ; preds = %128
%134 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.10, i64 0, i64 0))
br label %135
135: ; preds = %133, %128
%136 = getelementptr inbounds %struct.stat, %struct.stat* %3, i32 0, i32 1
%137 = load i64, i64* %136
%138 = load i64, i64* %6
%139 = icmp ne i64 %137, %138
br i1 %139, label %140, label %142
140: ; preds = %135
%141 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.11, i64 0, i64 0))
br label %142
142: ; preds = %140, %135
store i32 1, i32* %1
br label %143
143: ; preds = %142, %126, %108, %99, %83, %66, %38, %31, %25
%144 = load i32, i32* %1
ret i32 %144
}

LLVM IR (-O2):
%struct.stat = type { i64, i64 }
%struct.passwd = type { i8*, i64 }
@.str = [15 x i8] c"posixtest_26-2\00"
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@S_IRGRP = global i32 0
@S_IWGRP = global i32 0
@S_IROTH = global i32 0
@S_IWOTH = global i32 0
@.str.1 = [40 x i8] c"An error occurs when calling shm_open()\00"
@.str.2 = [41 x i8] c"An error occurs when calling ftruncate()\00"
@.str.3 = [37 x i8] c"An error occurs when calling fstat()\00"
@.str.4 = [5 x i8] c"root\00"
@errno = global i64 0
@EPERM = global i64 0
@.str.7 = [39 x i8] c"An error occurs when calling seteuid()\00"
@.str.8 = [34 x i8] c"Testing with user '%s' (uid: %i)\0A\00"
@O_TRUNC = global i32 0
@str = [26 x i8] c"The group ID has changed.\00"
@str.12 = [25 x i8] c"The user ID has changed.\00"
@str.13 = [12 x i8] c"Test PASSED\00"
@str.14 = [78 x i8] c"You don't have permission to change your UID.\0ATry to rerun this test as root.\00"
@str.15 = [46 x i8] c"There is no other user than current and root.\00"
define i32 @main() {
%1 = alloca %struct.stat
%2 = bitcast %struct.stat* %1 to i8*
%3 = tail call i32 @umask(i32 0)
%4 = load i32, i32* @O_RDWR
%5 = load i32, i32* @O_CREAT
%6 = or i32 %5, %4
%7 = load i32, i32* @S_IRUSR
%8 = load i32, i32* @S_IWUSR
%9 = or i32 %8, %7
%10 = load i32, i32* @S_IRGRP
%11 = or i32 %9, %10
%12 = load i32, i32* @S_IWGRP
%13 = or i32 %11, %12
%14 = load i32, i32* @S_IROTH
%15 = or i32 %13, %14
%16 = load i32, i32* @S_IWOTH
%17 = or i32 %15, %16
%18 = tail call i32 @shm_open(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %6, i32 %17)
%19 = icmp eq i32 %18, -1
br i1 %19, label %20, label %22
20: ; preds = %0
%21 = tail call i32 @perror(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0))
br label %113
22: ; preds = %0
%23 = tail call i64 @ftruncate(i32 %18, i32 8)
%24 = icmp eq i64 %23, 0
br i1 %24, label %28, label %25
25: ; preds = %22
%26 = tail call i32 @perror(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.2, i64 0, i64 0))
%27 = tail call i32 @shm_unlink(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
br label %113
28: ; preds = %22
%29 = call i64 @fstat(i32 %18, %struct.stat* %1)
%30 = icmp eq i64 %29, 0
br i1 %30, label %34, label %31
31: ; preds = %28
%32 = tail call i32 @perror(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.3, i64 0, i64 0))
%33 = tail call i32 @shm_unlink(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
br label %113
34: ; preds = %28
%35 = getelementptr inbounds %struct.stat, %struct.stat* %1, i64 0, i32 0
%36 = load i64, i64* %35
%37 = getelementptr inbounds %struct.stat, %struct.stat* %1, i64 0, i32 1
%38 = load i64, i64* %37
%39 = tail call %struct.passwd* (...) @getpwent()
%40 = icmp eq %struct.passwd* %39, null
br i1 %40, label %55, label %41
41: ; preds = %34, %52
%42 = phi %struct.passwd* [ %53, %52 ], [ %39, %34 ]
%43 = getelementptr inbounds %struct.passwd, %struct.passwd* %42, i64 0, i32 0
%44 = load i8*, i8** %43
%45 = tail call i64 @strcmp(i8* %44, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%46 = icmp eq i64 %45, 0
br i1 %46, label %52, label %47
47: ; preds = %41
%48 = getelementptr inbounds %struct.passwd, %struct.passwd* %42, i64 0, i32 1
%49 = load i64, i64* %48
%50 = tail call i64 (...) @getuid()
%51 = icmp eq i64 %49, %50
br i1 %51, label %52, label %58
52: ; preds = %47, %41
%53 = tail call %struct.passwd* (...) @getpwent()
%54 = icmp eq %struct.passwd* %53, null
br i1 %54, label %55, label %41
55: ; preds = %52, %34
%56 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @str.15, i64 0, i64 0))
%57 = tail call i32 @shm_unlink(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
br label %113
58: ; preds = %47
%59 = getelementptr inbounds %struct.passwd, %struct.passwd* %42, i64 0, i32 1
%60 = load i64, i64* %59
%61 = tail call i64 @seteuid(i64 %60)
%62 = icmp eq i64 %61, 0
br i1 %62, label %73, label %63
63: ; preds = %58
%64 = load i64, i64* @errno
%65 = load i64, i64* @EPERM
%66 = icmp eq i64 %64, %65
br i1 %66, label %67, label %69
67: ; preds = %63
%68 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([78 x i8], [78 x i8]* @str.14, i64 0, i64 0))
br label %71
69: ; preds = %63
%70 = tail call i32 @perror(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.7, i64 0, i64 0))
br label %71
71: ; preds = %69, %67
%72 = tail call i32 @shm_unlink(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
br label %113
73: ; preds = %58
%74 = getelementptr inbounds %struct.passwd, %struct.passwd* %42, i64 0, i32 0
%75 = load i8*, i8** %74
%76 = load i64, i64* %59
%77 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.8, i64 0, i64 0), i8* %75, i64 %76)
%78 = load i32, i32* @O_RDWR
%79 = load i32, i32* @O_TRUNC
%80 = or i32 %79, %78
%81 = tail call i32 @shm_open(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %80, i32 0)
%82 = icmp eq i32 %81, -1
br i1 %82, label %83, label %88
83: ; preds = %73
%84 = tail call i32 @perror(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0))
%85 = tail call i64 (...) @getuid()
%86 = tail call i64 @seteuid(i64 %85)
%87 = tail call i32 @shm_unlink(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
br label %113
88: ; preds = %73
%89 = call i64 @fstat(i32 %81, %struct.stat* %1)
%90 = icmp eq i64 %89, 0
br i1 %90, label %96, label %91
91: ; preds = %88
%92 = tail call i32 @perror(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.3, i64 0, i64 0))
%93 = tail call i64 (...) @getuid()
%94 = tail call i64 @seteuid(i64 %93)
%95 = tail call i32 @shm_unlink(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
br label %113
96: ; preds = %88
%97 = tail call i64 (...) @getuid()
%98 = tail call i64 @seteuid(i64 %97)
%99 = tail call i32 @shm_unlink(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%100 = load i64, i64* %35
%101 = icmp eq i64 %100, %36
%102 = load i64, i64* %37
%103 = icmp eq i64 %102, %38
%104 = select i1 %101, i1 %103, i1 false
br i1 %104, label %105, label %107
105: ; preds = %96
%106 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str.13, i64 0, i64 0))
br label %113
107: ; preds = %96
br i1 %101, label %110, label %108
108: ; preds = %107
%109 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str.12, i64 0, i64 0))
br label %110
110: ; preds = %108, %107
br i1 %103, label %113, label %111
111: ; preds = %110
%112 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str, i64 0, i64 0))
br label %113
113: ; preds = %110, %111, %105, %91, %83, %71, %55, %31, %25, %20
%114 = phi i32 [ 2, %20 ], [ 2, %25 ], [ 2, %31 ], [ 2, %55 ], [ 2, %71 ], [ 2, %83 ], [ 2, %91 ], [ 0, %105 ], [ 1, %111 ], [ 1, %110 ]
ret i32 %114
}