#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 st_uid;
  int /*<<< orphan*/ st_mode;
};
struct passwd {
  int pw_uid;
  int pw_gid;
};
struct dirent {
  char *d_name;
};
typedef int /*<<< orphan*/ DIR;

/* Variables and functions */
int EOF;
int S_ISREG(int /*<<< orphan*/);
scalar_t__ chown(char *, int, int);
int /*<<< orphan*/ closedir(int /*<<< orphan*/ *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int getopt(int, char **, char *);
struct passwd *getpwnam(char *);
scalar_t__ getuid();
int /*<<< orphan*/ *opendir(char *);
int optind;
int optopt;
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
struct dirent *readdir(int /*<<< orphan*/ *);
int /*<<< orphan*/ sprintf(char *, char *, char *, char *);
scalar_t__ stat(char *, struct stat *);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  DIR *dir;
  int uid1, uid2, gid2;
  struct stat info;
  struct dirent *entry;
  struct passwd *user1, *user2;
  char fullname[1024];
  int c, gflag = 0;
  while ((c = getopt(argc, argv, "g")) != EOF) {
    switch (c) {
    case 'g':
      gflag = 1;
      break;
    case '?':
      fprintf(stderr, "invalid option: -%c\n", optopt);
      break;
    }
  }
  argv += optind - 1;
  argc -= optind - 1;
  if (argc != 4) {
    fprintf(stderr, "usage: transfer old_owner new_owner dir\n");
    exit(1);
  }
  dir = opendir(argv[3]);
  if (dir == NULL) {
    perror(argv[3]);
    exit(1);
  }
  if ((user1 = getpwnam(argv[1])) == NULL) {
    fprintf(stderr, "unknown user: %s\n", argv[1]);
    exit(1);
  }
  uid1 = user1->pw_uid;
  if ((user2 = getpwnam(argv[2])) == NULL) {
    fprintf(stderr, "unknown user: %s\n", argv[2]);
    exit(1);
  }
  uid2 = user2->pw_uid;
  gid2 = user2->pw_gid;
  if ((uid2 == 0) && (getuid() != 0)) {
    printf("only root can do that\n");
    exit(1);
  }
  while ((entry = readdir(dir)) != NULL) {
    sprintf(fullname, "%s/%s", argv[3], entry->d_name);
    if (stat(fullname, &info) < 0) {
      fprintf(stderr, "%s: ", fullname);
      perror("stat failed");
      continue;
    }
    if ((info.st_uid == uid1) & S_ISREG(info.st_mode)) {
      if (chown(fullname, uid2, gflag ? gid2 : -1) < 0) {
        perror(fullname);
      }
    }
  }
  closedir(dir);
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x480,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x458(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xdef(%rip),%rdx
call   10e0 <getopt@plt>
mov    %eax,-0x454(%rbp)
mov    0x2dbd(%rip),%rcx
cmp    (%rcx),%eax
je     128d <main+0xad>
mov    -0x454(%rbp),%eax
mov    %eax,-0x45c(%rbp)
sub    $0x3f,%eax
je     1268 <main+0x88>
jmp    1245 <main+0x65>
mov    -0x45c(%rbp),%eax
sub    $0x67,%eax
jne    1288 <main+0xa8>
jmp    1259 <main+0x79>
movl   $0x1,-0x458(%rbp)
jmp    1288 <main+0xa8>
mov    0x2d59(%rip),%rax
mov    (%rax),%edi
mov    0x2d70(%rip),%rax
mov    (%rax),%edx
lea    0xd81(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
jmp    1203 <main+0x23>
mov    0x2d44(%rip),%rax
mov    (%rax),%ecx
sub    $0x1,%ecx
mov    -0x10(%rbp),%rax
movslq %ecx,%rcx
shl    $0x3,%rcx
add    %rcx,%rax
mov    %rax,-0x10(%rbp)
mov    0x2d26(%rip),%rax
mov    (%rax),%ecx
sub    $0x1,%ecx
mov    -0x8(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x8(%rbp)
cmpl   $0x4,-0x8(%rbp)
je     12ea <main+0x10a>
mov    0x2cf8(%rip),%rax
mov    (%rax),%edi
lea    0xd3e(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   1030 <opendir@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    131d <main+0x13d>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   10d0 <perror@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1070 <getpwnam@plt>
mov    %rax,-0x40(%rbp)
cmp    $0x0,%rax
jne    1361 <main+0x181>
mov    0x2c89(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xcf0(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
mov    -0x40(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1070 <getpwnam@plt>
mov    %rax,-0x48(%rbp)
cmp    $0x0,%rax
jne    13ae <main+0x1ce>
mov    0x2c3c(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdx
lea    0xca3(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
mov    -0x48(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    -0x48(%rbp),%rax
mov    0x4(%rax),%eax
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x20(%rbp)
jne    13f2 <main+0x212>
mov    $0x0,%al
call   1040 <getuid@plt>
cmp    $0x0,%rax
je     13f2 <main+0x212>
lea    0xc6f(%rip),%rdi
call   1050 <printf@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
jmp    13f7 <main+0x217>
mov    -0x18(%rbp),%rdi
call   10b0 <readdir@plt>
mov    %rax,-0x38(%rbp)
cmp    $0x0,%rax
je     1522 <main+0x342>
lea    -0x450(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdx
mov    -0x38(%rbp),%rax
mov    (%rax),%rcx
lea    0xc3e(%rip),%rsi
call   10f0 <sprintf@plt>
lea    -0x450(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1090 <stat@plt>
cmp    $0x0,%rax
jge    1479 <main+0x299>
mov    0x2b77(%rip),%rax
mov    (%rax),%edi
lea    -0x450(%rbp),%rdx
lea    0xc0e(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
lea    0xc05(%rip),%rdi
call   10d0 <perror@plt>
jmp    13f7 <main+0x217>
mov    -0x30(%rbp),%eax
cmp    -0x1c(%rbp),%eax
sete   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x460(%rbp)
mov    -0x2c(%rbp),%edi
call   10a0 <S_ISREG@plt>
mov    %eax,%ecx
mov    -0x460(%rbp),%eax
and    %ecx,%eax
cmp    $0x0,%eax
je     151d <main+0x33d>
lea    -0x450(%rbp),%rax
mov    %rax,-0x470(%rbp)
mov    -0x20(%rbp),%eax
mov    %eax,-0x464(%rbp)
cmpl   $0x0,-0x458(%rbp)
je     14da <main+0x2fa>
mov    -0x24(%rbp),%eax
mov    %eax,-0x474(%rbp)
jmp    14ea <main+0x30a>
mov    $0xffffffff,%eax
mov    %eax,-0x474(%rbp)
jmp    14ea <main+0x30a>
mov    -0x464(%rbp),%esi
mov    -0x470(%rbp),%rdi
mov    -0x474(%rbp),%edx
call   10c0 <chown@plt>
cmp    $0x0,%rax
jge    1518 <main+0x338>
lea    -0x450(%rbp),%rdi
call   10d0 <perror@plt>
jmp    151d <main+0x33d>
jmp    13f7 <main+0x217>
mov    -0x18(%rbp),%rdi
call   1060 <closedir@plt>
xor    %edi,%edi
call   1100 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x418,%rsp
mov    %rsi,%r12
mov    %edi,%ebp
lea    0xe03(%rip),%rdx
call   10e0 <getopt@plt>
mov    0x2dd7(%rip),%r15
xor    %r13d,%r13d
cmp    (%r15),%eax
jne    1249 <main+0x69>
mov    0x2dc0(%rip),%rax
movslq (%rax),%rbx
sub    %ebx,%ebp
cmp    $0x3,%ebp
jne    12a0 <main+0xc0>
mov    0x10(%r12,%rbx,8),%rdi
call   1040 <opendir@plt>
test   %rax,%rax
jne    12c1 <main+0xe1>
mov    0x10(%r12,%rbx,8),%rdi
call   10d0 <perror@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
lea    0xdb2(%rip),%r14
lea    0xda9(%rip),%rbx
xor    %r13d,%r13d
jmp    128e <main+0xae>
nopl   0x0(%rax)
mov    0x2d61(%rip),%rax
mov    (%rax),%edi
mov    0x2d78(%rip),%rax
mov    (%rax),%edx
mov    %r14,%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    %ebp,%edi
mov    %r12,%rsi
mov    %rbx,%rdx
call   10e0 <getopt@plt>
cmp    (%r15),%eax
je     1211 <main+0x31>
cmp    $0x3f,%eax
je     1260 <main+0x80>
cmp    $0x67,%eax
jne    127c <main+0x9c>
mov    $0x1,%r13d
jmp    127c <main+0x9c>
mov    0x2d21(%rip),%rax
mov    (%rax),%edi
lea    0xd67(%rip),%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
mov    %rax,%r14
mov    (%r12,%rbx,8),%rdi
call   1070 <getpwnam@plt>
test   %rax,%rax
jne    12e1 <main+0x101>
mov    0x2cef(%rip),%rax
mov    (%rax),%edi
mov    (%r12,%rbx,8),%rdx
jmp    1301 <main+0x121>
mov    (%rax),%r15d
mov    0x8(%r12,%rbx,8),%rdi
call   1070 <getpwnam@plt>
test   %rax,%rax
jne    1319 <main+0x139>
mov    0x2cce(%rip),%rax
mov    (%rax),%edi
mov    0x8(%r12,%rbx,8),%rdx
lea    0xd38(%rip),%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
mov    (%rax),%ecx
mov    0x4(%rax),%ebp
mov    %ecx,0x4(%rsp)
test   %ecx,%ecx
jne    1336 <main+0x156>
xor    %eax,%eax
call   1050 <getuid@plt>
test   %rax,%rax
jne    13fc <main+0x21c>
mov    %r14,%rdi
call   10b0 <readdir@plt>
test   %rax,%rax
jne    1352 <main+0x172>
mov    %r14,%rdi
call   1060 <closedir@plt>
xor    %edi,%edi
call   1100 <exit@plt>
cmp    $0x1,%r13d
sbb    %ecx,%ecx
or     %ebp,%ecx
mov    %ecx,(%rsp)
lea    0x10(%rsp),%rbp
jmp    139d <main+0x1bd>
mov    0x2c5d(%rip),%rax
mov    (%rax),%edi
lea    0xce4(%rip),%rsi
mov    %rbp,%rdx
xor    %eax,%eax
call   1080 <fprintf@plt>
lea    0xcd8(%rip),%rdi
call   10d0 <perror@plt>
nopw   0x0(%rax,%rax,1)
mov    %r14,%rdi
call   10b0 <readdir@plt>
test   %rax,%rax
je     1343 <main+0x163>
mov    0x10(%r12,%rbx,8),%rdx
mov    (%rax),%rcx
mov    %rbp,%rdi
lea    0xca3(%rip),%rsi
call   10f0 <sprintf@plt>
mov    %rbp,%rdi
lea    0x8(%rsp),%rsi
call   1090 <stat@plt>
test   %rax,%rax
js     1364 <main+0x184>
mov    0xc(%rsp),%edi
mov    %rbx,%r13
xor    %ebx,%ebx
cmp    %r15d,0x8(%rsp)
sete   %bl
call   10a0 <S_ISREG@plt>
test   %ebx,%eax
mov    %r13,%rbx
je     1390 <main+0x1b0>
mov    %rbp,%rdi
mov    0x4(%rsp),%esi
mov    (%rsp),%edx
call   10c0 <chown@plt>
test   %rax,%rax
jns    1390 <main+0x1b0>
mov    %rbp,%rdi
jmp    1385 <main+0x1a5>
lea    0xc66(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1100 <exit@plt>

LLVM IR (-O0):
%struct.stat = type { i32, i32 }
%struct.dirent = type { i8* }
%struct.passwd = type { i32, i32 }
@.str = [2 x i8] c"g\00"
@EOF = global i32 0
@stderr = global i32 0
@.str.1 = [21 x i8] c"invalid option: -%c\0A\00"
@optopt = global i32 0
@optind = global i32 0
@.str.2 = [41 x i8] c"usage: transfer old_owner new_owner dir\0A\00"
@.str.3 = [18 x i8] c"unknown user: %s\0A\00"
@.str.4 = [23 x i8] c"only root can do that\0A\00"
@.str.5 = [6 x i8] c"%s/%s\00"
@.str.6 = [5 x i8] c"%s: \00"
@.str.7 = [12 x i8] c"stat failed\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.stat
%11 = alloca %struct.dirent*
%12 = alloca %struct.passwd*
%13 = alloca %struct.passwd*
%14 = alloca [1024 x i8]
%15 = alloca i32
%16 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %16
br label %17
17: ; preds = %30, %2
%18 = load i32, i32* %4
%19 = load i8**, i8*** %5
%20 = call i32 @getopt(i32 %18, i8** %19, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32 %20, i32* %15
%21 = load i32, i32* @EOF
%22 = icmp ne i32 %20, %21
br i1 %22, label %23, label %31
23: ; preds = %17
%24 = load i32, i32* %15
switch i32 %24, label %30 [
i32 103, label %25
i32 63, label %26
]
25: ; preds = %23
store i32 1, i32* %16
br label %30
26: ; preds = %23
%27 = load i32, i32* @stderr
%28 = load i32, i32* @optopt
%29 = call i32 (i32, i8*, ...) @fprintf(i32 %27, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i32 %28)
br label %30
30: ; preds = %23, %26, %25
br label %17
31: ; preds = %17
%32 = load i32, i32* @optind
%33 = sub nsw i32 %32, 1
%34 = load i8**, i8*** %5
%35 = sext i32 %33 to i64
%36 = getelementptr inbounds i8*, i8** %34, i64 %35
store i8** %36, i8*** %5
%37 = load i32, i32* @optind
%38 = sub nsw i32 %37, 1
%39 = load i32, i32* %4
%40 = sub nsw i32 %39, %38
store i32 %40, i32* %4
%41 = load i32, i32* %4
%42 = icmp ne i32 %41, 4
br i1 %42, label %43, label %47
43: ; preds = %31
%44 = load i32, i32* @stderr
%45 = call i32 (i32, i8*, ...) @fprintf(i32 %44, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.2, i64 0, i64 0))
%46 = call i32 @exit(i32 1)
unreachable
47: ; preds = %31
%48 = load i8**, i8*** %5
%49 = getelementptr inbounds i8*, i8** %48, i64 3
%50 = load i8*, i8** %49
%51 = call i32* @opendir(i8* %50)
store i32* %51, i32** %6
%52 = load i32*, i32** %6
%53 = icmp eq i32* %52, null
br i1 %53, label %54, label %60
54: ; preds = %47
%55 = load i8**, i8*** %5
%56 = getelementptr inbounds i8*, i8** %55, i64 3
%57 = load i8*, i8** %56
%58 = call i32 @perror(i8* %57)
%59 = call i32 @exit(i32 1)
unreachable
60: ; preds = %47
%61 = load i8**, i8*** %5
%62 = getelementptr inbounds i8*, i8** %61, i64 1
%63 = load i8*, i8** %62
%64 = call %struct.passwd* @getpwnam(i8* %63)
store %struct.passwd* %64, %struct.passwd** %12
%65 = icmp eq %struct.passwd* %64, null
br i1 %65, label %66, label %73
66: ; preds = %60
%67 = load i32, i32* @stderr
%68 = load i8**, i8*** %5
%69 = getelementptr inbounds i8*, i8** %68, i64 1
%70 = load i8*, i8** %69
%71 = call i32 (i32, i8*, ...) @fprintf(i32 %67, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i8* %70)
%72 = call i32 @exit(i32 1)
unreachable
73: ; preds = %60
%74 = load %struct.passwd*, %struct.passwd** %12
%75 = getelementptr inbounds %struct.passwd, %struct.passwd* %74, i32 0, i32 0
%76 = load i32, i32* %75
store i32 %76, i32* %7
%77 = load i8**, i8*** %5
%78 = getelementptr inbounds i8*, i8** %77, i64 2
%79 = load i8*, i8** %78
%80 = call %struct.passwd* @getpwnam(i8* %79)
store %struct.passwd* %80, %struct.passwd** %13
%81 = icmp eq %struct.passwd* %80, null
br i1 %81, label %82, label %89
82: ; preds = %73
%83 = load i32, i32* @stderr
%84 = load i8**, i8*** %5
%85 = getelementptr inbounds i8*, i8** %84, i64 2
%86 = load i8*, i8** %85
%87 = call i32 (i32, i8*, ...) @fprintf(i32 %83, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i8* %86)
%88 = call i32 @exit(i32 1)
unreachable
89: ; preds = %73
%90 = load %struct.passwd*, %struct.passwd** %13
%91 = getelementptr inbounds %struct.passwd, %struct.passwd* %90, i32 0, i32 0
%92 = load i32, i32* %91
store i32 %92, i32* %8
%93 = load %struct.passwd*, %struct.passwd** %13
%94 = getelementptr inbounds %struct.passwd, %struct.passwd* %93, i32 0, i32 1
%95 = load i32, i32* %94
store i32 %95, i32* %9
%96 = load i32, i32* %8
%97 = icmp eq i32 %96, 0
br i1 %97, label %98, label %104
98: ; preds = %89
%99 = call i64 (...) @getuid()
%100 = icmp ne i64 %99, 0
br i1 %100, label %101, label %104
101: ; preds = %98
%102 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0))
%103 = call i32 @exit(i32 1)
unreachable
104: ; preds = %98, %89
br label %105
105: ; preds = %153, %121, %104
%106 = load i32*, i32** %6
%107 = call %struct.dirent* @readdir(i32* %106)
store %struct.dirent* %107, %struct.dirent** %11
%108 = icmp ne %struct.dirent* %107, null
br i1 %108, label %109, label %154
109: ; preds = %105
%110 = getelementptr inbounds [1024 x i8], [1024 x i8]* %14, i64 0, i64 0
%111 = load i8**, i8*** %5
%112 = getelementptr inbounds i8*, i8** %111, i64 3
%113 = load i8*, i8** %112
%114 = load %struct.dirent*, %struct.dirent** %11
%115 = getelementptr inbounds %struct.dirent, %struct.dirent* %114, i32 0, i32 0
%116 = load i8*, i8** %115
%117 = call i32 @sprintf(i8* %110, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i8* %113, i8* %116)
%118 = getelementptr inbounds [1024 x i8], [1024 x i8]* %14, i64 0, i64 0
%119 = call i64 @stat(i8* %118, %struct.stat* %10)
%120 = icmp slt i64 %119, 0
br i1 %120, label %121, label %126
121: ; preds = %109
%122 = load i32, i32* @stderr
%123 = getelementptr inbounds [1024 x i8], [1024 x i8]* %14, i64 0, i64 0
%124 = call i32 (i32, i8*, ...) @fprintf(i32 %122, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0), i8* %123)
%125 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.7, i64 0, i64 0))
br label %105
126: ; preds = %109
%127 = getelementptr inbounds %struct.stat, %struct.stat* %10, i32 0, i32 0
%128 = load i32, i32* %127
%129 = load i32, i32* %7
%130 = icmp eq i32 %128, %129
%131 = zext i1 %130 to i32
%132 = getelementptr inbounds %struct.stat, %struct.stat* %10, i32 0, i32 1
%133 = load i32, i32* %132
%134 = call i32 @S_ISREG(i32 %133)
%135 = and i32 %131, %134
%136 = icmp ne i32 %135, 0
br i1 %136, label %137, label %153
137: ; preds = %126
%138 = getelementptr inbounds [1024 x i8], [1024 x i8]* %14, i64 0, i64 0
%139 = load i32, i32* %8
%140 = load i32, i32* %16
%141 = icmp ne i32 %140, 0
br i1 %141, label %142, label %144
142: ; preds = %137
%143 = load i32, i32* %9
br label %145
144: ; preds = %137
br label %145
145: ; preds = %144, %142
%146 = phi i32 [ %143, %142 ], [ -1, %144 ]
%147 = call i64 @chown(i8* %138, i32 %139, i32 %146)
%148 = icmp slt i64 %147, 0
br i1 %148, label %149, label %152
149: ; preds = %145
%150 = getelementptr inbounds [1024 x i8], [1024 x i8]* %14, i64 0, i64 0
%151 = call i32 @perror(i8* %150)
br label %152
152: ; preds = %149, %145
br label %153
153: ; preds = %152, %126
br label %105
154: ; preds = %105
%155 = load i32*, i32** %6
%156 = call i32 @closedir(i32* %155)
%157 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
%struct.stat = type { i32, i32 }
%struct.passwd = type { i32, i32 }
%struct.dirent = type { i8* }
@.str = [2 x i8] c"g\00"
@EOF = global i32 0
@stderr = global i32 0
@.str.1 = [21 x i8] c"invalid option: -%c\0A\00"
@optopt = global i32 0
@optind = global i32 0
@.str.2 = [41 x i8] c"usage: transfer old_owner new_owner dir\0A\00"
@.str.3 = [18 x i8] c"unknown user: %s\0A\00"
@.str.5 = [6 x i8] c"%s/%s\00"
@.str.6 = [5 x i8] c"%s: \00"
@.str.7 = [12 x i8] c"stat failed\00"
@str = [22 x i8] c"only root can do that\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca %struct.stat
%4 = alloca [1024 x i8]
%5 = bitcast %struct.stat* %3 to i8*
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%7 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%8 = load i32, i32* @EOF
%9 = icmp eq i32 %7, %8
br i1 %9, label %23, label %10
10: ; preds = %2, %18
%11 = phi i32 [ %20, %18 ], [ %7, %2 ]
%12 = phi i32 [ %19, %18 ], [ 0, %2 ]
switch i32 %11, label %18 [
i32 103, label %13
i32 63, label %14
]
13: ; preds = %10
br label %18
14: ; preds = %10
%15 = load i32, i32* @stderr
%16 = load i32, i32* @optopt
%17 = tail call i32 (i32, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i32 %16)
br label %18
18: ; preds = %10, %14, %13
%19 = phi i32 [ %12, %10 ], [ %12, %14 ], [ 1, %13 ]
%20 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%21 = load i32, i32* @EOF
%22 = icmp eq i32 %20, %21
br i1 %22, label %23, label %10
23: ; preds = %18, %2
%24 = phi i32 [ 0, %2 ], [ %19, %18 ]
%25 = load i32, i32* @optind
%26 = add nsw i32 %25, -1
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8*, i8** %1, i64 %27
%29 = sub nsw i32 %0, %26
%30 = icmp eq i32 %29, 4
br i1 %30, label %35, label %31
31: ; preds = %23
%32 = load i32, i32* @stderr
%33 = tail call i32 (i32, i8*, ...) @fprintf(i32 %32, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.2, i64 0, i64 0))
%34 = tail call i32 @exit(i32 1)
unreachable
35: ; preds = %23
%36 = getelementptr inbounds i8*, i8** %28, i64 3
%37 = load i8*, i8** %36
%38 = tail call i32* @opendir(i8* %37)
%39 = icmp eq i32* %38, null
br i1 %39, label %40, label %44
40: ; preds = %35
%41 = load i8*, i8** %36
%42 = tail call i32 @perror(i8* %41)
%43 = tail call i32 @exit(i32 1)
unreachable
44: ; preds = %35
%45 = getelementptr inbounds i8*, i8** %28, i64 1
%46 = load i8*, i8** %45
%47 = tail call %struct.passwd* @getpwnam(i8* %46)
%48 = icmp eq %struct.passwd* %47, null
br i1 %48, label %49, label %54
49: ; preds = %44
%50 = load i32, i32* @stderr
%51 = load i8*, i8** %45
%52 = tail call i32 (i32, i8*, ...) @fprintf(i32 %50, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i8* %51)
%53 = tail call i32 @exit(i32 1)
unreachable
54: ; preds = %44
%55 = getelementptr inbounds %struct.passwd, %struct.passwd* %47, i64 0, i32 0
%56 = load i32, i32* %55
%57 = getelementptr inbounds i8*, i8** %28, i64 2
%58 = load i8*, i8** %57
%59 = tail call %struct.passwd* @getpwnam(i8* %58)
%60 = icmp eq %struct.passwd* %59, null
br i1 %60, label %61, label %66
61: ; preds = %54
%62 = load i32, i32* @stderr
%63 = load i8*, i8** %57
%64 = tail call i32 (i32, i8*, ...) @fprintf(i32 %62, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i8* %63)
%65 = tail call i32 @exit(i32 1)
unreachable
66: ; preds = %54
%67 = getelementptr inbounds %struct.passwd, %struct.passwd* %59, i64 0, i32 0
%68 = load i32, i32* %67
%69 = getelementptr inbounds %struct.passwd, %struct.passwd* %59, i64 0, i32 1
%70 = load i32, i32* %69
%71 = icmp eq i32 %68, 0
br i1 %71, label %72, label %78
72: ; preds = %66
%73 = tail call i64 (...) @getuid()
%74 = icmp eq i64 %73, 0
br i1 %74, label %78, label %75
75: ; preds = %72
%76 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str, i64 0, i64 0))
%77 = tail call i32 @exit(i32 1)
unreachable
78: ; preds = %72, %66
%79 = call %struct.dirent* @readdir(i32* %38)
%80 = icmp eq %struct.dirent* %79, null
br i1 %80, label %114, label %81
81: ; preds = %78
%82 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%83 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 1
%84 = icmp eq i32 %24, 0
%85 = select i1 %84, i32 -1, i32 %70
br label %86
86: ; preds = %81, %98
%87 = phi %struct.dirent* [ %79, %81 ], [ %99, %98 ]
%88 = load i8*, i8** %36
%89 = getelementptr inbounds %struct.dirent, %struct.dirent* %87, i64 0, i32 0
%90 = load i8*, i8** %89
%91 = call i32 @sprintf(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i8* %88, i8* %90)
%92 = call i64 @stat(i8* %6, %struct.stat* %3)
%93 = icmp slt i64 %92, 0
br i1 %93, label %94, label %101
94: ; preds = %86
%95 = load i32, i32* @stderr
%96 = call i32 (i32, i8*, ...) @fprintf(i32 %95, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0), i8* %6)
%97 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.7, i64 0, i64 0))
br label %98
98: ; preds = %101, %112, %109, %94
%99 = call %struct.dirent* @readdir(i32* %38)
%100 = icmp eq %struct.dirent* %99, null
br i1 %100, label %114, label %86
101: ; preds = %86
%102 = load i32, i32* %82
%103 = icmp eq i32 %102, %56
%104 = zext i1 %103 to i32
%105 = load i32, i32* %83
%106 = call i32 @S_ISREG(i32 %105)
%107 = and i32 %106, %104
%108 = icmp eq i32 %107, 0
br i1 %108, label %98, label %109
109: ; preds = %101
%110 = call i64 @chown(i8* %6, i32 %68, i32 %85)
%111 = icmp slt i64 %110, 0
br i1 %111, label %112, label %98
112: ; preds = %109
%113 = call i32 @perror(i8* %6)
br label %98
114: ; preds = %98, %78
%115 = call i32 @closedir(i32* %38)
%116 = call i32 @exit(i32 0)
unreachable
}