#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 stat {
  int /*<<< orphan*/ member_0;
};

/* Variables and functions */
int O_CREAT;
int O_RDWR;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ close(int);
int dup(int);
int /*<<< orphan*/ errno;
int fchmod(int, int);
int fchown(int, int, int);
int fdatasync(int);
int fgetxattr(int, char *, int /*<<< orphan*/ *, int /*<<< orphan*/);
int flistxattr(int, int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int fremovexattr(int, char *);
int fsetxattr(int, char *, char *, int, int /*<<< orphan*/);
int fstat(int, struct stat *);
int fsync(int);
int ftruncate(int, int /*<<< orphan*/);
int lseek(int, int /*<<< orphan*/, int /*<<< orphan*/);
int memcmp(char *, char *, int /*<<< orphan*/);
int open(char *, int, int);
int read(int, char *, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcpy(char *, char *);
char *strerror(int /*<<< orphan*/);
int /*<<< orphan*/ strlen(char *);
int unlink(char *);
int write(int, char *, int /*<<< orphan*/);
int dup_fd_based_fops(char *filename) {
  int fd = 0;
  int result = 0;
  int newfd = 0;
  int ret = -1;
  struct stat stbuf = {
      0,
  };
  char wstr[50] = {
      0,
  };
  char rstr[50] = {
      0,
  };
  fd = open(filename, O_RDWR | O_CREAT, 0666);
  if (fd < 0) {
    fprintf(stderr, "open failed : %s\n", strerror(errno));
    return ret;
  }
  newfd = dup(fd);
  if (newfd < 0) {
    fprintf(stderr, "dup failed: %s\n", strerror(errno));
    result |= ret;
  }
  close(fd);
  strcpy(wstr, "This is my string\n");
  ret = write(newfd, wstr, strlen(wstr));
  if (ret <= 0) {
    fprintf(stderr, "write failed: %s\n", strerror(errno));
    result |= ret;
  }
  ret = lseek(newfd, 0, SEEK_SET);
  if (ret < 0) {
    fprintf(stderr, "lseek failed: %s\n", strerror(errno));
    result |= ret;
  }
  ret = read(newfd, rstr, strlen(wstr));
  if (ret <= 0) {
    fprintf(stderr, "read failed: %s\n", strerror(errno));
    result |= ret;
  }
  ret = memcmp(rstr, wstr, strlen(wstr));
  if (ret != 0) {
    fprintf(stderr, "read returning junk\n");
    result |= ret;
  }
  ret = ftruncate(newfd, 0);
  if (ret < 0) {
    fprintf(stderr, "ftruncate failed : %s\n", strerror(errno));
    result |= ret;
  }
  ret = fstat(newfd, &stbuf);
  if (ret < 0) {
    fprintf(stderr, "fstat failed : %s\n", strerror(errno));
    result |= ret;
  }
  ret = fchmod(newfd, 0640);
  if (ret < 0) {
    fprintf(stderr, "fchmod failed : %s\n", strerror(errno));
    result |= ret;
  }
  ret = fchown(newfd, 10001, 10001);
  if (ret < 0) {
    fprintf(stderr, "fchown failed : %s\n", strerror(errno));
    result |= ret;
  }
  ret = fsync(newfd);
  if (ret < 0) {
    fprintf(stderr, "fsync failed : %s\n", strerror(errno));
    result |= ret;
  }
  ret = fsetxattr(newfd, "trusted.xattr-test", "working", 8, 0);
  if (ret < 0) {
    fprintf(stderr, "fsetxattr failed : %s\n", strerror(errno));
    result |= ret;
  }
  ret = fdatasync(newfd);
  if (ret < 0) {
    fprintf(stderr, "fdatasync failed : %s\n", strerror(errno));
    result |= ret;
  }
  ret = flistxattr(newfd, NULL, 0);
  if (ret <= 0) {
    fprintf(stderr, "flistxattr failed : %s\n", strerror(errno));
    result |= ret;
  }
  ret = fgetxattr(newfd, "trusted.xattr-test", NULL, 0);
  if (ret <= 0) {
    fprintf(stderr, "fgetxattr failed : %s\n", strerror(errno));
    result |= ret;
  }
  ret = fremovexattr(newfd, "trusted.xattr-test");
  if (ret < 0) {
    fprintf(stderr, "fremovexattr failed : %s\n", strerror(errno));
    result |= ret;
  }
  if (newfd)
    close(newfd);
  ret = unlink(filename);
  if (ret < 0) {
    fprintf(stderr, "unlink failed : %s\n", strerror(errno));
    result |= ret;
  }
  return result;
}


x86 assembly (clang, -O0):
<dup_fd_based_fops>:
push   %rbp
mov    %rsp,%rbp
sub    $0x110,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0xffffffff,-0x20(%rbp)
lea    -0x28(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   10e0 <memset@plt>
lea    -0x60(%rbp),%rdi
xor    %esi,%esi
mov    $0x32,%edx
call   10e0 <memset@plt>
lea    -0xa0(%rbp),%rdi
xor    %esi,%esi
mov    $0x32,%edx
call   10e0 <memset@plt>
mov    -0x10(%rbp),%rdi
mov    0x2d07(%rip),%rax
mov    (%rax),%esi
mov    0x2d16(%rip),%rax
or     (%rax),%esi
mov    $0x1b6,%edx
call   1160 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    133a <dup_fd_based_fops+0xca>
mov    0x2cce(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xa4(%rbp)
mov    0x2cb7(%rip),%rax
mov    (%rax),%edi
call   1180 <strerror@plt>
mov    -0xa4(%rbp),%edi
mov    %rax,%rdx
lea    0xcd8(%rip),%rsi
mov    $0x0,%al
call   1120 <fprintf@plt>
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    193f <dup_fd_based_fops+0x6cf>
mov    -0x14(%rbp),%edi
call   10c0 <dup@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    138c <dup_fd_based_fops+0x11c>
mov    0x2c7a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xa8(%rbp)
mov    0x2c63(%rip),%rax
mov    (%rax),%edi
call   1180 <strerror@plt>
mov    -0xa8(%rbp),%edi
mov    %rax,%rdx
lea    0xc96(%rip),%rsi
mov    $0x0,%al
call   1120 <fprintf@plt>
mov    -0x20(%rbp),%eax
or     -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%edi
call   10f0 <close@plt>
lea    -0x60(%rbp),%rdi
lea    0xc83(%rip),%rsi
call   1050 <strcpy@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0xb4(%rbp)
lea    -0x60(%rbp),%rax
mov    %rax,-0xb0(%rbp)
lea    -0x60(%rbp),%rdi
call   10a0 <strlen@plt>
mov    -0xb4(%rbp),%edi
mov    -0xb0(%rbp),%rsi
mov    %eax,%edx
call   1080 <write@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jg     141f <dup_fd_based_fops+0x1af>
mov    0x2be7(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xb8(%rbp)
mov    0x2bd0(%rip),%rax
mov    (%rax),%edi
call   1180 <strerror@plt>
mov    -0xb8(%rbp),%edi
mov    %rax,%rdx
lea    0xc26(%rip),%rsi
mov    $0x0,%al
call   1120 <fprintf@plt>
mov    -0x20(%rbp),%eax
or     -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x1c(%rbp),%edi
mov    0x2b97(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   10d0 <lseek@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jge    147c <dup_fd_based_fops+0x20c>
mov    0x2b8a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xbc(%rbp)
mov    0x2b73(%rip),%rax
mov    (%rax),%edi
call   1180 <strerror@plt>
mov    -0xbc(%rbp),%edi
mov    %rax,%rdx
lea    0xbdb(%rip),%rsi
mov    $0x0,%al
call   1120 <fprintf@plt>
mov    -0x20(%rbp),%eax
or     -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0xcc(%rbp)
lea    -0xa0(%rbp),%rax
mov    %rax,-0xc8(%rbp)
lea    -0x60(%rbp),%rdi
call   10a0 <strlen@plt>
mov    -0xcc(%rbp),%edi
mov    -0xc8(%rbp),%rsi
mov    %eax,%edx
call   1100 <read@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jg     14fa <dup_fd_based_fops+0x28a>
mov    0x2b0c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xd0(%rbp)
mov    0x2af5(%rip),%rax
mov    (%rax),%edi
call   1180 <strerror@plt>
mov    -0xd0(%rbp),%edi
mov    %rax,%rdx
lea    0xb6f(%rip),%rsi
mov    $0x0,%al
call   1120 <fprintf@plt>
mov    -0x20(%rbp),%eax
or     -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
lea    -0xa0(%rbp),%rax
mov    %rax,-0xe0(%rbp)
lea    -0x60(%rbp),%rax
mov    %rax,-0xd8(%rbp)
lea    -0x60(%rbp),%rdi
call   10a0 <strlen@plt>
mov    -0xe0(%rbp),%rdi
mov    -0xd8(%rbp),%rsi
mov    %eax,%edx
call   1110 <memcmp@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
je     155e <dup_fd_based_fops+0x2ee>
mov    0x2a8b(%rip),%rax
mov    (%rax),%edi
lea    0xb1c(%rip),%rsi
mov    $0x0,%al
call   1120 <fprintf@plt>
mov    -0x20(%rbp),%eax
or     -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x1c(%rbp),%edi
xor    %esi,%esi
call   10b0 <ftruncate@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jge    15b2 <dup_fd_based_fops+0x342>
mov    0x2a54(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xe4(%rbp)
mov    0x2a3d(%rip),%rax
mov    (%rax),%edi
call   1180 <strerror@plt>
mov    -0xe4(%rbp),%edi
mov    %rax,%rdx
lea    0xadd(%rip),%rsi
mov    $0x0,%al
call   1120 <fprintf@plt>
mov    -0x20(%rbp),%eax
or     -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x1c(%rbp),%edi
lea    -0x28(%rbp),%rsi
call   1190 <fstat@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jge    1608 <dup_fd_based_fops+0x398>
mov    0x29fe(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xe8(%rbp)
mov    0x29e7(%rip),%rax
mov    (%rax),%edi
call   1180 <strerror@plt>
mov    -0xe8(%rbp),%edi
mov    %rax,%rdx
lea    0xa9e(%rip),%rsi
mov    $0x0,%al
call   1120 <fprintf@plt>
mov    -0x20(%rbp),%eax
or     -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x1c(%rbp),%edi
mov    $0x1a0,%esi
call   1140 <fchmod@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jge    165f <dup_fd_based_fops+0x3ef>
mov    0x29a7(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xec(%rbp)
mov    0x2990(%rip),%rax
mov    (%rax),%edi
call   1180 <strerror@plt>
mov    -0xec(%rbp),%edi
mov    %rax,%rdx
lea    0xa5a(%rip),%rsi
mov    $0x0,%al
call   1120 <fprintf@plt>
mov    -0x20(%rbp),%eax
or     -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x1c(%rbp),%edi
mov    $0x2711,%edx
mov    %edx,%esi
call   1170 <fchown@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jge    16b8 <dup_fd_based_fops+0x448>
mov    0x294e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xf0(%rbp)
mov    0x2937(%rip),%rax
mov    (%rax),%edi
call   1180 <strerror@plt>
mov    -0xf0(%rbp),%edi
mov    %rax,%rdx
lea    0xa15(%rip),%rsi
mov    $0x0,%al
call   1120 <fprintf@plt>
mov    -0x20(%rbp),%eax
or     -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x1c(%rbp),%edi
call   1150 <fsync@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jge    170a <dup_fd_based_fops+0x49a>
mov    0x28fc(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xf4(%rbp)
mov    0x28e5(%rip),%rax
mov    (%rax),%edi
call   1180 <strerror@plt>
mov    -0xf4(%rbp),%edi
mov    %rax,%rdx
lea    0x9d7(%rip),%rsi
mov    $0x0,%al
call   1120 <fprintf@plt>
mov    -0x20(%rbp),%eax
or     -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x1c(%rbp),%edi
lea    0x9d0(%rip),%rsi
lea    0x9dc(%rip),%rdx
mov    $0x8,%ecx
xor    %r8d,%r8d
call   1070 <fsetxattr@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jge    1772 <dup_fd_based_fops+0x502>
mov    0x2894(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xf8(%rbp)
mov    0x287d(%rip),%rax
mov    (%rax),%edi
call   1180 <strerror@plt>
mov    -0xf8(%rbp),%edi
mov    %rax,%rdx
lea    0x99d(%rip),%rsi
mov    $0x0,%al
call   1120 <fprintf@plt>
mov    -0x20(%rbp),%eax
or     -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x1c(%rbp),%edi
call   1030 <fdatasync@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jge    17c4 <dup_fd_based_fops+0x554>
mov    0x2842(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xfc(%rbp)
mov    0x282b(%rip),%rax
mov    (%rax),%edi
call   1180 <strerror@plt>
mov    -0xfc(%rbp),%edi
mov    %rax,%rdx
lea    0x962(%rip),%rsi
mov    $0x0,%al
call   1120 <fprintf@plt>
mov    -0x20(%rbp),%eax
or     -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x1c(%rbp),%edi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1060 <flistxattr@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jg     181c <dup_fd_based_fops+0x5ac>
mov    0x27ea(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x100(%rbp)
mov    0x27d3(%rip),%rax
mov    (%rax),%edi
call   1180 <strerror@plt>
mov    -0x100(%rbp),%edi
mov    %rax,%rdx
lea    0x921(%rip),%rsi
mov    $0x0,%al
call   1120 <fprintf@plt>
mov    -0x20(%rbp),%eax
or     -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x1c(%rbp),%edi
lea    0x8be(%rip),%rsi
xor    %eax,%eax
mov    %eax,%edx
xor    %ecx,%ecx
call   1130 <fgetxattr@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jg     187b <dup_fd_based_fops+0x60b>
mov    0x278b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x104(%rbp)
mov    0x2774(%rip),%rax
mov    (%rax),%edi
call   1180 <strerror@plt>
mov    -0x104(%rbp),%edi
mov    %rax,%rdx
lea    0x8da(%rip),%rsi
mov    $0x0,%al
call   1120 <fprintf@plt>
mov    -0x20(%rbp),%eax
or     -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x1c(%rbp),%edi
lea    0x85f(%rip),%rsi
call   1090 <fremovexattr@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jge    18d4 <dup_fd_based_fops+0x664>
mov    0x2732(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x108(%rbp)
mov    0x271b(%rip),%rax
mov    (%rax),%edi
call   1180 <strerror@plt>
mov    -0x108(%rbp),%edi
mov    %rax,%rdx
lea    0x898(%rip),%rsi
mov    $0x0,%al
call   1120 <fprintf@plt>
mov    -0x20(%rbp),%eax
or     -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     18e6 <dup_fd_based_fops+0x676>
mov    -0x1c(%rbp),%edi
call   10f0 <close@plt>
mov    -0x10(%rbp),%rdi
call   1040 <unlink@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jge    1939 <dup_fd_based_fops+0x6c9>
mov    0x26cd(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10c(%rbp)
mov    0x26b6(%rip),%rax
mov    (%rax),%edi
call   1180 <strerror@plt>
mov    -0x10c(%rbp),%edi
mov    %rax,%rdx
lea    0x84d(%rip),%rsi
mov    $0x0,%al
call   1120 <fprintf@plt>
mov    -0x20(%rbp),%eax
or     -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x110,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dup_fd_based_fops>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x90,%rsp
mov    %rdi,%r14
movl   $0x0,0x8(%rsp)
xorps  %xmm0,%xmm0
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movw   $0x0,0x40(%rsp)
movaps %xmm0,0x70(%rsp)
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x50(%rsp)
movw   $0x0,0x80(%rsp)
mov    0x2d2d(%rip),%rax
mov    0x2d3e(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    $0x1b6,%edx
call   1150 <open@plt>
test   %eax,%eax
js     16fd <dup_fd_based_fops+0x49d>
mov    %eax,%ebp
mov    %eax,%edi
call   10c0 <dup@plt>
mov    %eax,%ebx
xor    %r15d,%r15d
test   %eax,%eax
jns    1314 <dup_fd_based_fops+0xb4>
mov    0x2ce7(%rip),%rax
mov    (%rax),%r15d
mov    0x2cd5(%rip),%rax
mov    (%rax),%edi
call   1170 <strerror@plt>
lea    0xd11(%rip),%rsi
mov    %r15d,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1110 <fprintf@plt>
mov    $0xffffffff,%r15d
mov    %ebp,%edi
call   10e0 <close@plt>
lea    0xd00(%rip),%rsi
lea    0x10(%rsp),%rbp
mov    %rbp,%rdi
call   1050 <strcpy@plt>
mov    %rbp,%rdi
call   10a0 <strlen@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
mov    %eax,%edx
call   1080 <write@plt>
test   %eax,%eax
jg     1378 <dup_fd_based_fops+0x118>
mov    %eax,%ebp
mov    0x2c80(%rip),%rax
mov    (%rax),%r12d
mov    0x2c6e(%rip),%rax
mov    (%rax),%edi
call   1170 <strerror@plt>
lea    0xccd(%rip),%rsi
mov    %r12d,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1110 <fprintf@plt>
or     %ebp,%r15d
mov    0x2c41(%rip),%rax
mov    (%rax),%edx
mov    %ebx,%edi
xor    %esi,%esi
call   10d0 <lseek@plt>
test   %eax,%eax
jns    13bf <dup_fd_based_fops+0x15f>
mov    %eax,%ebp
mov    0x2c39(%rip),%rax
mov    (%rax),%r12d
mov    0x2c27(%rip),%rax
mov    (%rax),%edi
call   1170 <strerror@plt>
lea    0xc98(%rip),%rsi
mov    %r12d,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1110 <fprintf@plt>
or     %ebp,%r15d
lea    0x10(%rsp),%rdi
call   10a0 <strlen@plt>
lea    0x50(%rsp),%rsi
mov    %ebx,%edi
mov    %eax,%edx
call   10f0 <read@plt>
test   %eax,%eax
jg     140c <dup_fd_based_fops+0x1ac>
mov    %eax,%ebp
mov    0x2bec(%rip),%rax
mov    (%rax),%r12d
mov    0x2bda(%rip),%rax
mov    (%rax),%edi
call   1170 <strerror@plt>
lea    0xc5d(%rip),%rsi
mov    %r12d,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1110 <fprintf@plt>
or     %ebp,%r15d
lea    0x10(%rsp),%rbp
mov    %rbp,%rdi
call   10a0 <strlen@plt>
lea    0x50(%rsp),%rdi
mov    %rbp,%rsi
mov    %eax,%edx
call   1100 <memcmp@plt>
test   %eax,%eax
je     1448 <dup_fd_based_fops+0x1e8>
mov    %eax,%ebp
mov    0x2b9b(%rip),%rax
mov    (%rax),%edi
lea    0xc2c(%rip),%rsi
xor    %eax,%eax
call   1110 <fprintf@plt>
or     %ebp,%r15d
mov    %ebx,%edi
xor    %esi,%esi
call   10b0 <ftruncate@plt>
test   %eax,%eax
jns    1486 <dup_fd_based_fops+0x226>
mov    %eax,%ebp
mov    0x2b72(%rip),%rax
mov    (%rax),%r12d
mov    0x2b60(%rip),%rax
mov    (%rax),%edi
call   1170 <strerror@plt>
lea    0xc09(%rip),%rsi
mov    %r12d,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1110 <fprintf@plt>
or     %ebp,%r15d
lea    0x8(%rsp),%rsi
mov    %ebx,%edi
call   1180 <fstat@plt>
test   %eax,%eax
jns    14c7 <dup_fd_based_fops+0x267>
mov    %eax,%ebp
mov    0x2b31(%rip),%rax
mov    (%rax),%r12d
mov    0x2b1f(%rip),%rax
mov    (%rax),%edi
call   1170 <strerror@plt>
lea    0xbdf(%rip),%rsi
mov    %r12d,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1110 <fprintf@plt>
or     %ebp,%r15d
mov    %ebx,%edi
mov    $0x1a0,%esi
call   1130 <fchmod@plt>
test   %eax,%eax
jns    1508 <dup_fd_based_fops+0x2a8>
mov    %eax,%ebp
mov    0x2af0(%rip),%rax
mov    (%rax),%r12d
mov    0x2ade(%rip),%rax
mov    (%rax),%edi
call   1170 <strerror@plt>
lea    0xbb1(%rip),%rsi
mov    %r12d,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1110 <fprintf@plt>
or     %ebp,%r15d
mov    %ebx,%edi
mov    $0x2711,%esi
mov    $0x2711,%edx
call   1160 <fchown@plt>
test   %eax,%eax
jns    154e <dup_fd_based_fops+0x2ee>
mov    %eax,%ebp
mov    0x2aaa(%rip),%rax
mov    (%rax),%r12d
mov    0x2a98(%rip),%rax
mov    (%rax),%edi
call   1170 <strerror@plt>
lea    0xb7f(%rip),%rsi
mov    %r12d,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1110 <fprintf@plt>
or     %ebp,%r15d
mov    %ebx,%edi
call   1140 <fsync@plt>
test   %eax,%eax
jns    158a <dup_fd_based_fops+0x32a>
mov    %eax,%ebp
mov    0x2a6e(%rip),%rax
mov    (%rax),%r12d
mov    0x2a5c(%rip),%rax
mov    (%rax),%edi
call   1170 <strerror@plt>
lea    0xb57(%rip),%rsi
mov    %r12d,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1110 <fprintf@plt>
or     %ebp,%r15d
lea    0xb53(%rip),%rsi
lea    0xb5f(%rip),%rdx
mov    %ebx,%edi
mov    $0x8,%ecx
xor    %r8d,%r8d
call   1070 <fsetxattr@plt>
test   %eax,%eax
jns    15dc <dup_fd_based_fops+0x37c>
mov    %eax,%ebp
mov    0x2a1c(%rip),%rax
mov    (%rax),%r12d
mov    0x2a0a(%rip),%rax
mov    (%rax),%edi
call   1170 <strerror@plt>
lea    0xb33(%rip),%rsi
mov    %r12d,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1110 <fprintf@plt>
or     %ebp,%r15d
mov    %ebx,%edi
call   1030 <fdatasync@plt>
test   %eax,%eax
jns    1618 <dup_fd_based_fops+0x3b8>
mov    %eax,%ebp
mov    0x29e0(%rip),%rax
mov    (%rax),%r12d
mov    0x29ce(%rip),%rax
mov    (%rax),%edi
call   1170 <strerror@plt>
lea    0xb0e(%rip),%rsi
mov    %r12d,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1110 <fprintf@plt>
or     %ebp,%r15d
mov    %ebx,%edi
xor    %esi,%esi
xor    %edx,%edx
call   1060 <flistxattr@plt>
test   %eax,%eax
jg     1658 <dup_fd_based_fops+0x3f8>
mov    %eax,%ebp
mov    0x29a0(%rip),%rax
mov    (%rax),%r12d
mov    0x298e(%rip),%rax
mov    (%rax),%edi
call   1170 <strerror@plt>
lea    0xae5(%rip),%rsi
mov    %r12d,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1110 <fprintf@plt>
or     %ebp,%r15d
lea    0xa85(%rip),%rsi
mov    %ebx,%edi
xor    %edx,%edx
xor    %ecx,%ecx
call   1120 <fgetxattr@plt>
test   %eax,%eax
jg     169f <dup_fd_based_fops+0x43f>
mov    %eax,%ebp
mov    0x2959(%rip),%rax
mov    (%rax),%r12d
mov    0x2947(%rip),%rax
mov    (%rax),%edi
call   1170 <strerror@plt>
lea    0xab6(%rip),%rsi
mov    %r12d,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1110 <fprintf@plt>
or     %ebp,%r15d
lea    0xa3e(%rip),%rsi
mov    %ebx,%edi
call   1090 <fremovexattr@plt>
test   %eax,%eax
js     1740 <dup_fd_based_fops+0x4e0>
test   %ebx,%ebx
je     16c0 <dup_fd_based_fops+0x460>
mov    %ebx,%edi
call   10e0 <close@plt>
mov    %r14,%rdi
call   1040 <unlink@plt>
test   %eax,%eax
jns    172d <dup_fd_based_fops+0x4cd>
mov    %eax,%ebx
mov    0x28fb(%rip),%rax
mov    (%rax),%ebp
mov    0x28ea(%rip),%rax
mov    (%rax),%edi
call   1170 <strerror@plt>
lea    0xa8a(%rip),%rsi
mov    %ebp,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1110 <fprintf@plt>
or     %ebx,%r15d
jmp    172d <dup_fd_based_fops+0x4cd>
mov    0x28cc(%rip),%rax
mov    (%rax),%ebx
mov    0x28bb(%rip),%rax
mov    (%rax),%edi
call   1170 <strerror@plt>
lea    0x8e5(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1110 <fprintf@plt>
mov    $0xffffffff,%r15d
mov    %r15d,%eax
add    $0x90,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %eax,%ebp
mov    0x2887(%rip),%rax
mov    (%rax),%r12d
mov    0x2875(%rip),%rax
mov    (%rax),%edi
call   1170 <strerror@plt>
lea    0x9fb(%rip),%rsi
mov    %r12d,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1110 <fprintf@plt>
or     %ebp,%r15d
test   %ebx,%ebx
jne    16b9 <dup_fd_based_fops+0x459>
jmp    16c0 <dup_fd_based_fops+0x460>

LLVM IR (-O0):
%struct.stat = type { i32 }
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@stderr = global i32 0
@.str = [18 x i8] c"open failed : %s\0A\00"
@errno = global i32 0
@.str.1 = [16 x i8] c"dup failed: %s\0A\00"
@.str.2 = [19 x i8] c"This is my string\0A\00"
@.str.3 = [18 x i8] c"write failed: %s\0A\00"
@SEEK_SET = global i32 0
@.str.4 = [18 x i8] c"lseek failed: %s\0A\00"
@.str.5 = [17 x i8] c"read failed: %s\0A\00"
@.str.6 = [21 x i8] c"read returning junk\0A\00"
@.str.7 = [23 x i8] c"ftruncate failed : %s\0A\00"
@.str.8 = [19 x i8] c"fstat failed : %s\0A\00"
@.str.9 = [20 x i8] c"fchmod failed : %s\0A\00"
@.str.10 = [20 x i8] c"fchown failed : %s\0A\00"
@.str.11 = [19 x i8] c"fsync failed : %s\0A\00"
@.str.12 = [19 x i8] c"trusted.xattr-test\00"
@.str.13 = [8 x i8] c"working\00"
@.str.14 = [23 x i8] c"fsetxattr failed : %s\0A\00"
@.str.15 = [23 x i8] c"fdatasync failed : %s\0A\00"
@.str.16 = [24 x i8] c"flistxattr failed : %s\0A\00"
@.str.17 = [23 x i8] c"fgetxattr failed : %s\0A\00"
@.str.18 = [26 x i8] c"fremovexattr failed : %s\0A\00"
@.str.19 = [20 x i8] c"unlink failed : %s\0A\00"
define i32 @dup_fd_based_fops(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca %struct.stat
%9 = alloca [50 x i8]
%10 = alloca [50 x i8]
store i8* %0, i8** %3
store i32 0, i32* %4
store i32 0, i32* %5
store i32 0, i32* %6
store i32 -1, i32* %7
%11 = bitcast %struct.stat* %8 to i8*
%12 = bitcast [50 x i8]* %9 to i8*
%13 = bitcast [50 x i8]* %10 to i8*
%14 = load i8*, i8** %3
%15 = load i32, i32* @O_RDWR
%16 = load i32, i32* @O_CREAT
%17 = or i32 %15, %16
%18 = call i32 @open(i8* %14, i32 %17, i32 438)
store i32 %18, i32* %4
%19 = load i32, i32* %4
%20 = icmp slt i32 %19, 0
br i1 %20, label %21, label %27
21: ; preds = %1
%22 = load i32, i32* @stderr
%23 = load i32, i32* @errno
%24 = call i8* @strerror(i32 %23)
%25 = call i32 (i32, i8*, ...) @fprintf(i32 %22, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %24)
%26 = load i32, i32* %7
store i32 %26, i32* %2
br label %255
27: ; preds = %1
%28 = load i32, i32* %4
%29 = call i32 @dup(i32 %28)
store i32 %29, i32* %6
%30 = load i32, i32* %6
%31 = icmp slt i32 %30, 0
br i1 %31, label %32, label %40
32: ; preds = %27
%33 = load i32, i32* @stderr
%34 = load i32, i32* @errno
%35 = call i8* @strerror(i32 %34)
%36 = call i32 (i32, i8*, ...) @fprintf(i32 %33, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* %35)
%37 = load i32, i32* %7
%38 = load i32, i32* %5
%39 = or i32 %38, %37
store i32 %39, i32* %5
br label %40
40: ; preds = %32, %27
%41 = load i32, i32* %4
%42 = call i32 @close(i32 %41)
%43 = getelementptr inbounds [50 x i8], [50 x i8]* %9, i64 0, i64 0
%44 = call i32 @strcpy(i8* %43, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
%45 = load i32, i32* %6
%46 = getelementptr inbounds [50 x i8], [50 x i8]* %9, i64 0, i64 0
%47 = getelementptr inbounds [50 x i8], [50 x i8]* %9, i64 0, i64 0
%48 = call i32 @strlen(i8* %47)
%49 = call i32 @write(i32 %45, i8* %46, i32 %48)
store i32 %49, i32* %7
%50 = load i32, i32* %7
%51 = icmp sle i32 %50, 0
br i1 %51, label %52, label %60
52: ; preds = %40
%53 = load i32, i32* @stderr
%54 = load i32, i32* @errno
%55 = call i8* @strerror(i32 %54)
%56 = call i32 (i32, i8*, ...) @fprintf(i32 %53, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i8* %55)
%57 = load i32, i32* %7
%58 = load i32, i32* %5
%59 = or i32 %58, %57
store i32 %59, i32* %5
br label %60
60: ; preds = %52, %40
%61 = load i32, i32* %6
%62 = load i32, i32* @SEEK_SET
%63 = call i32 @lseek(i32 %61, i32 0, i32 %62)
store i32 %63, i32* %7
%64 = load i32, i32* %7
%65 = icmp slt i32 %64, 0
br i1 %65, label %66, label %74
66: ; preds = %60
%67 = load i32, i32* @stderr
%68 = load i32, i32* @errno
%69 = call i8* @strerror(i32 %68)
%70 = call i32 (i32, i8*, ...) @fprintf(i32 %67, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), i8* %69)
%71 = load i32, i32* %7
%72 = load i32, i32* %5
%73 = or i32 %72, %71
store i32 %73, i32* %5
br label %74
74: ; preds = %66, %60
%75 = load i32, i32* %6
%76 = getelementptr inbounds [50 x i8], [50 x i8]* %10, i64 0, i64 0
%77 = getelementptr inbounds [50 x i8], [50 x i8]* %9, i64 0, i64 0
%78 = call i32 @strlen(i8* %77)
%79 = call i32 @read(i32 %75, i8* %76, i32 %78)
store i32 %79, i32* %7
%80 = load i32, i32* %7
%81 = icmp sle i32 %80, 0
br i1 %81, label %82, label %90
82: ; preds = %74
%83 = load i32, i32* @stderr
%84 = load i32, i32* @errno
%85 = call i8* @strerror(i32 %84)
%86 = call i32 (i32, i8*, ...) @fprintf(i32 %83, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0), i8* %85)
%87 = load i32, i32* %7
%88 = load i32, i32* %5
%89 = or i32 %88, %87
store i32 %89, i32* %5
br label %90
90: ; preds = %82, %74
%91 = getelementptr inbounds [50 x i8], [50 x i8]* %10, i64 0, i64 0
%92 = getelementptr inbounds [50 x i8], [50 x i8]* %9, i64 0, i64 0
%93 = getelementptr inbounds [50 x i8], [50 x i8]* %9, i64 0, i64 0
%94 = call i32 @strlen(i8* %93)
%95 = call i32 @memcmp(i8* %91, i8* %92, i32 %94)
store i32 %95, i32* %7
%96 = load i32, i32* %7
%97 = icmp ne i32 %96, 0
br i1 %97, label %98, label %104
98: ; preds = %90
%99 = load i32, i32* @stderr
%100 = call i32 (i32, i8*, ...) @fprintf(i32 %99, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.6, i64 0, i64 0))
%101 = load i32, i32* %7
%102 = load i32, i32* %5
%103 = or i32 %102, %101
store i32 %103, i32* %5
br label %104
104: ; preds = %98, %90
%105 = load i32, i32* %6
%106 = call i32 @ftruncate(i32 %105, i32 0)
store i32 %106, i32* %7
%107 = load i32, i32* %7
%108 = icmp slt i32 %107, 0
br i1 %108, label %109, label %117
109: ; preds = %104
%110 = load i32, i32* @stderr
%111 = load i32, i32* @errno
%112 = call i8* @strerror(i32 %111)
%113 = call i32 (i32, i8*, ...) @fprintf(i32 %110, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.7, i64 0, i64 0), i8* %112)
%114 = load i32, i32* %7
%115 = load i32, i32* %5
%116 = or i32 %115, %114
store i32 %116, i32* %5
br label %117
117: ; preds = %109, %104
%118 = load i32, i32* %6
%119 = call i32 @fstat(i32 %118, %struct.stat* %8)
store i32 %119, i32* %7
%120 = load i32, i32* %7
%121 = icmp slt i32 %120, 0
br i1 %121, label %122, label %130
122: ; preds = %117
%123 = load i32, i32* @stderr
%124 = load i32, i32* @errno
%125 = call i8* @strerror(i32 %124)
%126 = call i32 (i32, i8*, ...) @fprintf(i32 %123, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.8, i64 0, i64 0), i8* %125)
%127 = load i32, i32* %7
%128 = load i32, i32* %5
%129 = or i32 %128, %127
store i32 %129, i32* %5
br label %130
130: ; preds = %122, %117
%131 = load i32, i32* %6
%132 = call i32 @fchmod(i32 %131, i32 416)
store i32 %132, i32* %7
%133 = load i32, i32* %7
%134 = icmp slt i32 %133, 0
br i1 %134, label %135, label %143
135: ; preds = %130
%136 = load i32, i32* @stderr
%137 = load i32, i32* @errno
%138 = call i8* @strerror(i32 %137)
%139 = call i32 (i32, i8*, ...) @fprintf(i32 %136, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.9, i64 0, i64 0), i8* %138)
%140 = load i32, i32* %7
%141 = load i32, i32* %5
%142 = or i32 %141, %140
store i32 %142, i32* %5
br label %143
143: ; preds = %135, %130
%144 = load i32, i32* %6
%145 = call i32 @fchown(i32 %144, i32 10001, i32 10001)
store i32 %145, i32* %7
%146 = load i32, i32* %7
%147 = icmp slt i32 %146, 0
br i1 %147, label %148, label %156
148: ; preds = %143
%149 = load i32, i32* @stderr
%150 = load i32, i32* @errno
%151 = call i8* @strerror(i32 %150)
%152 = call i32 (i32, i8*, ...) @fprintf(i32 %149, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.10, i64 0, i64 0), i8* %151)
%153 = load i32, i32* %7
%154 = load i32, i32* %5
%155 = or i32 %154, %153
store i32 %155, i32* %5
br label %156
156: ; preds = %148, %143
%157 = load i32, i32* %6
%158 = call i32 @fsync(i32 %157)
store i32 %158, i32* %7
%159 = load i32, i32* %7
%160 = icmp slt i32 %159, 0
br i1 %160, label %161, label %169
161: ; preds = %156
%162 = load i32, i32* @stderr
%163 = load i32, i32* @errno
%164 = call i8* @strerror(i32 %163)
%165 = call i32 (i32, i8*, ...) @fprintf(i32 %162, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.11, i64 0, i64 0), i8* %164)
%166 = load i32, i32* %7
%167 = load i32, i32* %5
%168 = or i32 %167, %166
store i32 %168, i32* %5
br label %169
169: ; preds = %161, %156
%170 = load i32, i32* %6
%171 = call i32 @fsetxattr(i32 %170, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.12, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.13, i64 0, i64 0), i32 8, i32 0)
store i32 %171, i32* %7
%172 = load i32, i32* %7
%173 = icmp slt i32 %172, 0
br i1 %173, label %174, label %182
174: ; preds = %169
%175 = load i32, i32* @stderr
%176 = load i32, i32* @errno
%177 = call i8* @strerror(i32 %176)
%178 = call i32 (i32, i8*, ...) @fprintf(i32 %175, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.14, i64 0, i64 0), i8* %177)
%179 = load i32, i32* %7
%180 = load i32, i32* %5
%181 = or i32 %180, %179
store i32 %181, i32* %5
br label %182
182: ; preds = %174, %169
%183 = load i32, i32* %6
%184 = call i32 @fdatasync(i32 %183)
store i32 %184, i32* %7
%185 = load i32, i32* %7
%186 = icmp slt i32 %185, 0
br i1 %186, label %187, label %195
187: ; preds = %182
%188 = load i32, i32* @stderr
%189 = load i32, i32* @errno
%190 = call i8* @strerror(i32 %189)
%191 = call i32 (i32, i8*, ...) @fprintf(i32 %188, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.15, i64 0, i64 0), i8* %190)
%192 = load i32, i32* %7
%193 = load i32, i32* %5
%194 = or i32 %193, %192
store i32 %194, i32* %5
br label %195
195: ; preds = %187, %182
%196 = load i32, i32* %6
%197 = call i32 @flistxattr(i32 %196, i32* null, i32 0)
store i32 %197, i32* %7
%198 = load i32, i32* %7
%199 = icmp sle i32 %198, 0
br i1 %199, label %200, label %208
200: ; preds = %195
%201 = load i32, i32* @stderr
%202 = load i32, i32* @errno
%203 = call i8* @strerror(i32 %202)
%204 = call i32 (i32, i8*, ...) @fprintf(i32 %201, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.16, i64 0, i64 0), i8* %203)
%205 = load i32, i32* %7
%206 = load i32, i32* %5
%207 = or i32 %206, %205
store i32 %207, i32* %5
br label %208
208: ; preds = %200, %195
%209 = load i32, i32* %6
%210 = call i32 @fgetxattr(i32 %209, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.12, i64 0, i64 0), i32* null, i32 0)
store i32 %210, i32* %7
%211 = load i32, i32* %7
%212 = icmp sle i32 %211, 0
br i1 %212, label %213, label %221
213: ; preds = %208
%214 = load i32, i32* @stderr
%215 = load i32, i32* @errno
%216 = call i8* @strerror(i32 %215)
%217 = call i32 (i32, i8*, ...) @fprintf(i32 %214, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.17, i64 0, i64 0), i8* %216)
%218 = load i32, i32* %7
%219 = load i32, i32* %5
%220 = or i32 %219, %218
store i32 %220, i32* %5
br label %221
221: ; preds = %213, %208
%222 = load i32, i32* %6
%223 = call i32 @fremovexattr(i32 %222, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.12, i64 0, i64 0))
store i32 %223, i32* %7
%224 = load i32, i32* %7
%225 = icmp slt i32 %224, 0
br i1 %225, label %226, label %234
226: ; preds = %221
%227 = load i32, i32* @stderr
%228 = load i32, i32* @errno
%229 = call i8* @strerror(i32 %228)
%230 = call i32 (i32, i8*, ...) @fprintf(i32 %227, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.18, i64 0, i64 0), i8* %229)
%231 = load i32, i32* %7
%232 = load i32, i32* %5
%233 = or i32 %232, %231
store i32 %233, i32* %5
br label %234
234: ; preds = %226, %221
%235 = load i32, i32* %6
%236 = icmp ne i32 %235, 0
br i1 %236, label %237, label %240
237: ; preds = %234
%238 = load i32, i32* %6
%239 = call i32 @close(i32 %238)
br label %240
240: ; preds = %237, %234
%241 = load i8*, i8** %3
%242 = call i32 @unlink(i8* %241)
store i32 %242, i32* %7
%243 = load i32, i32* %7
%244 = icmp slt i32 %243, 0
br i1 %244, label %245, label %253
245: ; preds = %240
%246 = load i32, i32* @stderr
%247 = load i32, i32* @errno
%248 = call i8* @strerror(i32 %247)
%249 = call i32 (i32, i8*, ...) @fprintf(i32 %246, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.19, i64 0, i64 0), i8* %248)
%250 = load i32, i32* %7
%251 = load i32, i32* %5
%252 = or i32 %251, %250
store i32 %252, i32* %5
br label %253
253: ; preds = %245, %240
%254 = load i32, i32* %5
store i32 %254, i32* %2
br label %255
255: ; preds = %253, %21
%256 = load i32, i32* %2
ret i32 %256
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@stderr = global i32 0
@.str = [18 x i8] c"open failed : %s\0A\00"
@errno = global i32 0
@.str.1 = [16 x i8] c"dup failed: %s\0A\00"
@.str.2 = [19 x i8] c"This is my string\0A\00"
@.str.3 = [18 x i8] c"write failed: %s\0A\00"
@SEEK_SET = global i32 0
@.str.4 = [18 x i8] c"lseek failed: %s\0A\00"
@.str.5 = [17 x i8] c"read failed: %s\0A\00"
@.str.6 = [21 x i8] c"read returning junk\0A\00"
@.str.7 = [23 x i8] c"ftruncate failed : %s\0A\00"
@.str.8 = [19 x i8] c"fstat failed : %s\0A\00"
@.str.9 = [20 x i8] c"fchmod failed : %s\0A\00"
@.str.10 = [20 x i8] c"fchown failed : %s\0A\00"
@.str.11 = [19 x i8] c"fsync failed : %s\0A\00"
@.str.12 = [19 x i8] c"trusted.xattr-test\00"
@.str.13 = [8 x i8] c"working\00"
@.str.14 = [23 x i8] c"fsetxattr failed : %s\0A\00"
@.str.15 = [23 x i8] c"fdatasync failed : %s\0A\00"
@.str.16 = [24 x i8] c"flistxattr failed : %s\0A\00"
@.str.17 = [23 x i8] c"fgetxattr failed : %s\0A\00"
@.str.18 = [26 x i8] c"fremovexattr failed : %s\0A\00"
@.str.19 = [20 x i8] c"unlink failed : %s\0A\00"
define i32 @dup_fd_based_fops(i8* nocapture %0) {
%2 = alloca %struct.stat
%3 = alloca [50 x i8]
%4 = alloca [50 x i8]
%5 = bitcast %struct.stat* %2 to i8*
%6 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 0
store i32 0, i32* %6
%7 = getelementptr inbounds [50 x i8], [50 x i8]* %3, i64 0, i64 0
%8 = getelementptr inbounds [50 x i8], [50 x i8]* %4, i64 0, i64 0
%9 = load i32, i32* @O_RDWR
%10 = load i32, i32* @O_CREAT
%11 = or i32 %10, %9
%12 = tail call i32 @open(i8* %0, i32 %11, i32 438)
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %19
14: ; preds = %1
%15 = load i32, i32* @stderr
%16 = load i32, i32* @errno
%17 = tail call i8* @strerror(i32 %16)
%18 = tail call i32 (i32, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %17)
br label %185
19: ; preds = %1
%20 = tail call i32 @dup(i32 %12)
%21 = icmp slt i32 %20, 0
br i1 %21, label %22, label %27
22: ; preds = %19
%23 = load i32, i32* @stderr
%24 = load i32, i32* @errno
%25 = tail call i8* @strerror(i32 %24)
%26 = tail call i32 (i32, i8*, ...) @fprintf(i32 %23, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* %25)
br label %27
27: ; preds = %22, %19
%28 = phi i32 [ -1, %22 ], [ 0, %19 ]
%29 = tail call i32 @close(i32 %12)
%30 = call i32 @strcpy(i8* %7, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
%31 = call i32 @strlen(i8* %7)
%32 = call i32 @write(i32 %20, i8* %7, i32 %31)
%33 = icmp slt i32 %32, 1
br i1 %33, label %34, label %40
34: ; preds = %27
%35 = load i32, i32* @stderr
%36 = load i32, i32* @errno
%37 = call i8* @strerror(i32 %36)
%38 = call i32 (i32, i8*, ...) @fprintf(i32 %35, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i8* %37)
%39 = or i32 %32, %28
br label %40
40: ; preds = %34, %27
%41 = phi i32 [ %39, %34 ], [ %28, %27 ]
%42 = load i32, i32* @SEEK_SET
%43 = call i32 @lseek(i32 %20, i32 0, i32 %42)
%44 = icmp slt i32 %43, 0
br i1 %44, label %45, label %51
45: ; preds = %40
%46 = load i32, i32* @stderr
%47 = load i32, i32* @errno
%48 = call i8* @strerror(i32 %47)
%49 = call i32 (i32, i8*, ...) @fprintf(i32 %46, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), i8* %48)
%50 = or i32 %43, %41
br label %51
51: ; preds = %45, %40
%52 = phi i32 [ %50, %45 ], [ %41, %40 ]
%53 = call i32 @strlen(i8* %7)
%54 = call i32 @read(i32 %20, i8* %8, i32 %53)
%55 = icmp slt i32 %54, 1
br i1 %55, label %56, label %62
56: ; preds = %51
%57 = load i32, i32* @stderr
%58 = load i32, i32* @errno
%59 = call i8* @strerror(i32 %58)
%60 = call i32 (i32, i8*, ...) @fprintf(i32 %57, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0), i8* %59)
%61 = or i32 %54, %52
br label %62
62: ; preds = %56, %51
%63 = phi i32 [ %61, %56 ], [ %52, %51 ]
%64 = call i32 @strlen(i8* %7)
%65 = call i32 @memcmp(i8* %8, i8* %7, i32 %64)
%66 = icmp eq i32 %65, 0
br i1 %66, label %71, label %67
67: ; preds = %62
%68 = load i32, i32* @stderr
%69 = call i32 (i32, i8*, ...) @fprintf(i32 %68, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.6, i64 0, i64 0))
%70 = or i32 %65, %63
br label %71
71: ; preds = %67, %62
%72 = phi i32 [ %70, %67 ], [ %63, %62 ]
%73 = call i32 @ftruncate(i32 %20, i32 0)
%74 = icmp slt i32 %73, 0
br i1 %74, label %75, label %81
75: ; preds = %71
%76 = load i32, i32* @stderr
%77 = load i32, i32* @errno
%78 = call i8* @strerror(i32 %77)
%79 = call i32 (i32, i8*, ...) @fprintf(i32 %76, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.7, i64 0, i64 0), i8* %78)
%80 = or i32 %73, %72
br label %81
81: ; preds = %75, %71
%82 = phi i32 [ %80, %75 ], [ %72, %71 ]
%83 = call i32 @fstat(i32 %20, %struct.stat* %2)
%84 = icmp slt i32 %83, 0
br i1 %84, label %85, label %91
85: ; preds = %81
%86 = load i32, i32* @stderr
%87 = load i32, i32* @errno
%88 = call i8* @strerror(i32 %87)
%89 = call i32 (i32, i8*, ...) @fprintf(i32 %86, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.8, i64 0, i64 0), i8* %88)
%90 = or i32 %83, %82
br label %91
91: ; preds = %85, %81
%92 = phi i32 [ %90, %85 ], [ %82, %81 ]
%93 = call i32 @fchmod(i32 %20, i32 416)
%94 = icmp slt i32 %93, 0
br i1 %94, label %95, label %101
95: ; preds = %91
%96 = load i32, i32* @stderr
%97 = load i32, i32* @errno
%98 = call i8* @strerror(i32 %97)
%99 = call i32 (i32, i8*, ...) @fprintf(i32 %96, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.9, i64 0, i64 0), i8* %98)
%100 = or i32 %93, %92
br label %101
101: ; preds = %95, %91
%102 = phi i32 [ %100, %95 ], [ %92, %91 ]
%103 = call i32 @fchown(i32 %20, i32 10001, i32 10001)
%104 = icmp slt i32 %103, 0
br i1 %104, label %105, label %111
105: ; preds = %101
%106 = load i32, i32* @stderr
%107 = load i32, i32* @errno
%108 = call i8* @strerror(i32 %107)
%109 = call i32 (i32, i8*, ...) @fprintf(i32 %106, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.10, i64 0, i64 0), i8* %108)
%110 = or i32 %103, %102
br label %111
111: ; preds = %105, %101
%112 = phi i32 [ %110, %105 ], [ %102, %101 ]
%113 = call i32 @fsync(i32 %20)
%114 = icmp slt i32 %113, 0
br i1 %114, label %115, label %121
115: ; preds = %111
%116 = load i32, i32* @stderr
%117 = load i32, i32* @errno
%118 = call i8* @strerror(i32 %117)
%119 = call i32 (i32, i8*, ...) @fprintf(i32 %116, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.11, i64 0, i64 0), i8* %118)
%120 = or i32 %113, %112
br label %121
121: ; preds = %115, %111
%122 = phi i32 [ %120, %115 ], [ %112, %111 ]
%123 = call i32 @fsetxattr(i32 %20, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.12, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.13, i64 0, i64 0), i32 8, i32 0)
%124 = icmp slt i32 %123, 0
br i1 %124, label %125, label %131
125: ; preds = %121
%126 = load i32, i32* @stderr
%127 = load i32, i32* @errno
%128 = call i8* @strerror(i32 %127)
%129 = call i32 (i32, i8*, ...) @fprintf(i32 %126, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.14, i64 0, i64 0), i8* %128)
%130 = or i32 %123, %122
br label %131
131: ; preds = %125, %121
%132 = phi i32 [ %130, %125 ], [ %122, %121 ]
%133 = call i32 @fdatasync(i32 %20)
%134 = icmp slt i32 %133, 0
br i1 %134, label %135, label %141
135: ; preds = %131
%136 = load i32, i32* @stderr
%137 = load i32, i32* @errno
%138 = call i8* @strerror(i32 %137)
%139 = call i32 (i32, i8*, ...) @fprintf(i32 %136, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.15, i64 0, i64 0), i8* %138)
%140 = or i32 %133, %132
br label %141
141: ; preds = %135, %131
%142 = phi i32 [ %140, %135 ], [ %132, %131 ]
%143 = call i32 @flistxattr(i32 %20, i32* null, i32 0)
%144 = icmp slt i32 %143, 1
br i1 %144, label %145, label %151
145: ; preds = %141
%146 = load i32, i32* @stderr
%147 = load i32, i32* @errno
%148 = call i8* @strerror(i32 %147)
%149 = call i32 (i32, i8*, ...) @fprintf(i32 %146, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.16, i64 0, i64 0), i8* %148)
%150 = or i32 %143, %142
br label %151
151: ; preds = %145, %141
%152 = phi i32 [ %150, %145 ], [ %142, %141 ]
%153 = call i32 @fgetxattr(i32 %20, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.12, i64 0, i64 0), i32* null, i32 0)
%154 = icmp slt i32 %153, 1
br i1 %154, label %155, label %161
155: ; preds = %151
%156 = load i32, i32* @stderr
%157 = load i32, i32* @errno
%158 = call i8* @strerror(i32 %157)
%159 = call i32 (i32, i8*, ...) @fprintf(i32 %156, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.17, i64 0, i64 0), i8* %158)
%160 = or i32 %153, %152
br label %161
161: ; preds = %155, %151
%162 = phi i32 [ %160, %155 ], [ %152, %151 ]
%163 = call i32 @fremovexattr(i32 %20, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.12, i64 0, i64 0))
%164 = icmp slt i32 %163, 0
br i1 %164, label %165, label %171
165: ; preds = %161
%166 = load i32, i32* @stderr
%167 = load i32, i32* @errno
%168 = call i8* @strerror(i32 %167)
%169 = call i32 (i32, i8*, ...) @fprintf(i32 %166, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.18, i64 0, i64 0), i8* %168)
%170 = or i32 %163, %162
br label %171
171: ; preds = %165, %161
%172 = phi i32 [ %170, %165 ], [ %162, %161 ]
%173 = icmp eq i32 %20, 0
br i1 %173, label %176, label %174
174: ; preds = %171
%175 = call i32 @close(i32 %20)
br label %176
176: ; preds = %174, %171
%177 = call i32 @unlink(i8* %0)
%178 = icmp slt i32 %177, 0
br i1 %178, label %179, label %185
179: ; preds = %176
%180 = load i32, i32* @stderr
%181 = load i32, i32* @errno
%182 = call i8* @strerror(i32 %181)
%183 = call i32 (i32, i8*, ...) @fprintf(i32 %180, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.19, i64 0, i64 0), i8* %182)
%184 = or i32 %177, %172
br label %185
185: ; preds = %176, %179, %14
%186 = phi i32 [ -1, %14 ], [ %184, %179 ], [ %172, %176 ]
ret i32 %186
}