#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
typedef int uid_t;
struct passwd {
  int pw_uid;
};

/* Variables and functions */
int EXIT_FAILURE;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
struct passwd *getpwnam(char *);
int lchown(char *, int, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int strtol(char *, char **, int);
int main(int argc, char **argv) {
  int ix;
  uid_t uid;
  struct passwd *pwd;
  char *endptr;
  if (argc < 3) {
    fprintf(stderr, "\nERROR (%s): Invalid number of arguments.\n", argv[0]);
    fprintf(stderr, "        Usage:  &% %s <user id>  <file list>\n", argv[0]);
    fprintf(stderr, "           or:  &% %s <username> <file list>\n\n",
            argv[0]);
    fprintf(stderr, "      Example:  &% %s builduser  file1 file2 file3\n",
            argv[0]);
    fprintf(stderr, "                will perform the equivalent of \% chown "
                    "builduser:<unchanged> file1 file2 file3\n\n");
    exit(1);
  }
  uid = strtol(argv[1], &endptr, 10);
  if (*endptr != '\0') {
    pwd = getpwnam(argv[1]);
    if (pwd == NULL) {
      perror("getpwnam");
      exit(EXIT_FAILURE);
    }
    uid = pwd->pw_uid;
  }
  for (ix = 2; argv[ix]; ix++) {
    (void)lchown(argv[ix], uid, -1);
    if (lchown(argv[ix], uid, -1) == -1) {
      fprintf(stderr, "\nERROR (%s): lchown %s %i failed. \n", argv[0],
              argv[ix], uid);
      fprintf(stderr, "errno=%s\n", strerror(errno));
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    1229 <main+0xb9>
mov    0x2e49(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe59(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    0x2e2b(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe66(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    0x2e0d(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe76(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    0x2def(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe87(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    0x2dd1(%rip),%rax
mov    (%rax),%edi
lea    0xea4(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x28(%rbp),%rsi
mov    $0xa,%edx
call   1050 <strtol@plt>
mov    %eax,-0x18(%rbp)
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1291 <main+0x121>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1030 <getpwnam@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1288 <main+0x118>
lea    0xea8(%rip),%rdi
call   1070 <perror@plt>
mov    0x2d4f(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    -0x20(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
movl   $0x2,-0x14(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
je     1355 <main+0x1e5>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x18(%rbp),%esi
mov    $0xffffffff,%edx
call   1060 <lchown@plt>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x18(%rbp),%esi
mov    $0xffffffff,%edx
call   1060 <lchown@plt>
cmp    $0xffffffff,%eax
jne    1342 <main+0x1d2>
mov    0x2cf3(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rcx
mov    -0x18(%rbp),%r8d
lea    0xe19(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    0x2cc5(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    0x2cb1(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x2c(%rbp),%edi
mov    %rax,%rdx
lea    0xe0f(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
jmp    1347 <main+0x1d7>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1298 <main+0x128>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r12
cmp    $0x2,%edi
jle    125c <main+0xec>
mov    0x8(%r12),%rdi
mov    %rsp,%rsi
mov    $0xa,%edx
call   1050 <strtol@plt>
mov    %eax,%ebp
mov    (%rsp),%rax
cmpb   $0x0,(%rax)
je     11b9 <main+0x49>
mov    0x8(%r12),%rdi
call   1030 <getpwnam@plt>
test   %rax,%rax
je     12cd <main+0x15d>
mov    (%rax),%ebp
mov    0x10(%r12),%rdi
test   %rdi,%rdi
je     124b <main+0xdb>
lea    0x10(%r12),%rbx
mov    0x2e0d(%rip),%r14
lea    0xf70(%rip),%r15
jmp    11ed <main+0x7d>
nopl   0x0(%rax)
mov    0x8(%rbx),%rdi
add    $0x8,%rbx
test   %rdi,%rdi
je     124b <main+0xdb>
mov    %ebp,%esi
mov    $0xffffffff,%edx
call   1060 <lchown@plt>
mov    (%rbx),%rdi
mov    %ebp,%esi
mov    $0xffffffff,%edx
call   1060 <lchown@plt>
cmp    $0xffffffff,%eax
jne    11e0 <main+0x70>
mov    (%r14),%edi
mov    (%r12),%rdx
mov    (%rbx),%rcx
lea    0xf08(%rip),%rsi
mov    %ebp,%r8d
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    (%r14),%r13d
mov    0x2da6(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    %r13d,%edi
mov    %r15,%rsi
mov    %rax,%rdx
xor    %eax,%eax
call   1040 <fprintf@plt>
jmp    11e0 <main+0x70>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d7d(%rip),%rbx
mov    (%rbx),%edi
mov    (%r12),%rdx
lea    0xd90(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    (%rbx),%edi
mov    (%r12),%rdx
lea    0xda7(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    (%rbx),%edi
mov    (%r12),%rdx
lea    0xdc1(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    (%rbx),%edi
mov    (%r12),%rdx
lea    0xddc(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    (%rbx),%edi
lea    0xe00(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
lea    0xe49(%rip),%rdi
call   1070 <perror@plt>
mov    0x2cf0(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

LLVM IR (-O0):
%struct.passwd = type { i32 }
@stderr = global i32 0
@.str = [43 x i8] c"\0AERROR (%s): Invalid number of arguments.\0A\00"
@.str.1 = [46 x i8] c" Usage: &% %s <user id> <file list>\0A\00"
@.str.2 = [47 x i8] c" or: &% %s <username> <file list>\0A\0A\00"
@.str.3 = [52 x i8] c" Example: &% %s builduser file1 file2 file3\0A\00"
@.str.4 = [97 x i8] c" will perform the equivalent of % chown builduser:<unchanged> file1 file2 file3\0A\0A\00"
@.str.5 = [9 x i8] c"getpwnam\00"
@EXIT_FAILURE = global i32 0
@.str.6 = [36 x i8] c"\0AERROR (%s): lchown %s %i failed. \0A\00"
@.str.7 = [10 x i8] c"errno=%s\0A\00"
@errno = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca %struct.passwd*
%9 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp slt i32 %10, 3
br i1 %11, label %12, label %36
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 0
%16 = load i8*, i8** %15
%17 = call i32 (i32, i8*, ...) @fprintf(i32 %13, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), i8* %16)
%18 = load i32, i32* @stderr
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 0
%21 = load i8*, i8** %20
%22 = call i32 (i32, i8*, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.1, i64 0, i64 0), i8* %21)
%23 = load i32, i32* @stderr
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 0
%26 = load i8*, i8** %25
%27 = call i32 (i32, i8*, ...) @fprintf(i32 %23, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.2, i64 0, i64 0), i8* %26)
%28 = load i32, i32* @stderr
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 0
%31 = load i8*, i8** %30
%32 = call i32 (i32, i8*, ...) @fprintf(i32 %28, i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.3, i64 0, i64 0), i8* %31)
%33 = load i32, i32* @stderr
%34 = call i32 (i32, i8*, ...) @fprintf(i32 %33, i8* getelementptr inbounds ([97 x i8], [97 x i8]* @.str.4, i64 0, i64 0))
%35 = call i32 @exit(i32 1)
unreachable
36: ; preds = %2
%37 = load i8**, i8*** %5
%38 = getelementptr inbounds i8*, i8** %37, i64 1
%39 = load i8*, i8** %38
%40 = call i32 @strtol(i8* %39, i8** %9, i32 10)
store i32 %40, i32* %7
%41 = load i8*, i8** %9
%42 = load i8, i8* %41
%43 = sext i8 %42 to i32
%44 = icmp ne i32 %43, 0
br i1 %44, label %45, label %60
45: ; preds = %36
%46 = load i8**, i8*** %5
%47 = getelementptr inbounds i8*, i8** %46, i64 1
%48 = load i8*, i8** %47
%49 = call %struct.passwd* @getpwnam(i8* %48)
store %struct.passwd* %49, %struct.passwd** %8
%50 = load %struct.passwd*, %struct.passwd** %8
%51 = icmp eq %struct.passwd* %50, null
br i1 %51, label %52, label %56
52: ; preds = %45
%53 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0))
%54 = load i32, i32* @EXIT_FAILURE
%55 = call i32 @exit(i32 %54)
unreachable
56: ; preds = %45
%57 = load %struct.passwd*, %struct.passwd** %8
%58 = getelementptr inbounds %struct.passwd, %struct.passwd* %57, i32 0, i32 0
%59 = load i32, i32* %58
store i32 %59, i32* %7
br label %60
60: ; preds = %56, %36
store i32 2, i32* %6
br label %61
61: ; preds = %101, %60
%62 = load i8**, i8*** %5
%63 = load i32, i32* %6
%64 = sext i32 %63 to i64
%65 = getelementptr inbounds i8*, i8** %62, i64 %64
%66 = load i8*, i8** %65
%67 = icmp ne i8* %66, null
br i1 %67, label %68, label %104
68: ; preds = %61
%69 = load i8**, i8*** %5
%70 = load i32, i32* %6
%71 = sext i32 %70 to i64
%72 = getelementptr inbounds i8*, i8** %69, i64 %71
%73 = load i8*, i8** %72
%74 = load i32, i32* %7
%75 = call i32 @lchown(i8* %73, i32 %74, i32 -1)
%76 = load i8**, i8*** %5
%77 = load i32, i32* %6
%78 = sext i32 %77 to i64
%79 = getelementptr inbounds i8*, i8** %76, i64 %78
%80 = load i8*, i8** %79
%81 = load i32, i32* %7
%82 = call i32 @lchown(i8* %80, i32 %81, i32 -1)
%83 = icmp eq i32 %82, -1
br i1 %83, label %84, label %100
84: ; preds = %68
%85 = load i32, i32* @stderr
%86 = load i8**, i8*** %5
%87 = getelementptr inbounds i8*, i8** %86, i64 0
%88 = load i8*, i8** %87
%89 = load i8**, i8*** %5
%90 = load i32, i32* %6
%91 = sext i32 %90 to i64
%92 = getelementptr inbounds i8*, i8** %89, i64 %91
%93 = load i8*, i8** %92
%94 = load i32, i32* %7
%95 = call i32 (i32, i8*, ...) @fprintf(i32 %85, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.6, i64 0, i64 0), i8* %88, i8* %93, i32 %94)
%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 ([10 x i8], [10 x i8]* @.str.7, i64 0, i64 0), i8* %98)
br label %100
100: ; preds = %84, %68
br label %101
101: ; preds = %100
%102 = load i32, i32* %6
%103 = add nsw i32 %102, 1
store i32 %103, i32* %6
br label %61
104: ; preds = %61
ret i32 0
}

LLVM IR (-O2):
%struct.passwd = type { i32 }
@stderr = global i32 0
@.str = [43 x i8] c"\0AERROR (%s): Invalid number of arguments.\0A\00"
@.str.1 = [46 x i8] c" Usage: &% %s <user id> <file list>\0A\00"
@.str.2 = [47 x i8] c" or: &% %s <username> <file list>\0A\0A\00"
@.str.3 = [52 x i8] c" Example: &% %s builduser file1 file2 file3\0A\00"
@.str.4 = [97 x i8] c" will perform the equivalent of % chown builduser:<unchanged> file1 file2 file3\0A\0A\00"
@.str.5 = [9 x i8] c"getpwnam\00"
@EXIT_FAILURE = global i32 0
@.str.6 = [36 x i8] c"\0AERROR (%s): lchown %s %i failed. \0A\00"
@.str.7 = [10 x i8] c"errno=%s\0A\00"
@errno = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i8*
%4 = bitcast i8** %3 to i8*
%5 = icmp slt i32 %0, 3
br i1 %5, label %6, label %22
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = load i8*, i8** %1
%9 = tail call i32 (i32, i8*, ...) @fprintf(i32 %7, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), i8* %8)
%10 = load i32, i32* @stderr
%11 = load i8*, i8** %1
%12 = tail call i32 (i32, i8*, ...) @fprintf(i32 %10, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.1, i64 0, i64 0), i8* %11)
%13 = load i32, i32* @stderr
%14 = load i8*, i8** %1
%15 = tail call i32 (i32, i8*, ...) @fprintf(i32 %13, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.2, i64 0, i64 0), i8* %14)
%16 = load i32, i32* @stderr
%17 = load i8*, i8** %1
%18 = tail call i32 (i32, i8*, ...) @fprintf(i32 %16, i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.3, i64 0, i64 0), i8* %17)
%19 = load i32, i32* @stderr
%20 = tail call i32 (i32, i8*, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([97 x i8], [97 x i8]* @.str.4, i64 0, i64 0))
%21 = tail call i32 @exit(i32 1)
unreachable
22: ; preds = %2
%23 = getelementptr inbounds i8*, i8** %1, i64 1
%24 = load i8*, i8** %23
%25 = call i32 @strtol(i8* %24, i8** %3, i32 10)
%26 = load i8*, i8** %3
%27 = load i8, i8* %26
%28 = icmp eq i8 %27, 0
br i1 %28, label %40, label %29
29: ; preds = %22
%30 = load i8*, i8** %23
%31 = tail call %struct.passwd* @getpwnam(i8* %30)
%32 = icmp eq %struct.passwd* %31, null
br i1 %32, label %33, label %37
33: ; preds = %29
%34 = tail call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0))
%35 = load i32, i32* @EXIT_FAILURE
%36 = tail call i32 @exit(i32 %35)
unreachable
37: ; preds = %29
%38 = getelementptr inbounds %struct.passwd, %struct.passwd* %31, i64 0, i32 0
%39 = load i32, i32* %38
br label %40
40: ; preds = %37, %22
%41 = phi i32 [ %39, %37 ], [ %25, %22 ]
%42 = getelementptr inbounds i8*, i8** %1, i64 2
%43 = load i8*, i8** %42
%44 = icmp eq i8* %43, null
br i1 %44, label %67, label %45
45: ; preds = %40, %62
%46 = phi i64 [ %63, %62 ], [ 2, %40 ]
%47 = phi i8* [ %65, %62 ], [ %43, %40 ]
%48 = phi i8** [ %64, %62 ], [ %42, %40 ]
%49 = tail call i32 @lchown(i8* %47, i32 %41, i32 -1)
%50 = load i8*, i8** %48
%51 = tail call i32 @lchown(i8* %50, i32 %41, i32 -1)
%52 = icmp eq i32 %51, -1
br i1 %52, label %53, label %62
53: ; preds = %45
%54 = load i32, i32* @stderr
%55 = load i8*, i8** %1
%56 = load i8*, i8** %48
%57 = tail call i32 (i32, i8*, ...) @fprintf(i32 %54, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.6, i64 0, i64 0), i8* %55, i8* %56, i32 %41)
%58 = load i32, i32* @stderr
%59 = load i32, i32* @errno
%60 = tail call i8* @strerror(i32 %59)
%61 = tail call i32 (i32, i8*, ...) @fprintf(i32 %58, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.7, i64 0, i64 0), i8* %60)
br label %62
62: ; preds = %45, %53
%63 = add nuw i64 %46, 1
%64 = getelementptr inbounds i8*, i8** %1, i64 %63
%65 = load i8*, i8** %64
%66 = icmp eq i8* %65, null
br i1 %66, label %67, label %45
67: ; preds = %62, %40
ret i32 0
}