#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 filesystem {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ compresspath(char *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ fsclose(struct filesystem *);
struct filesystem *fsopen(char *);
char *getsetting(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sprintf(char *, char *, char *, ...);
int /*<<< orphan*/ sscanf(char *, char *, int *);
int /*<<< orphan*/ uchgrp(struct filesystem *, char *, int);
int main(int argc, char *argv[]) {
  struct filesystem *f;
  int i;
  int mode;
  char temp[1024];
  char *cwd;
  char *fsname = getsetting("imagefile");
  ;
  if (!fsname) {
    printf("Have you run ulogin?\n");
    return 10;
  }
  if (argc < 3) {
    printf("Usage: %s <gid> <file> ...\n", argv[0]);
    return 10;
  }
  sscanf(argv[1], "%o", &mode);
  f = fsopen(fsname);
  if (!f) {
    printf("Unable to open %s\n", fsname);
    return 10;
  }
  cwd = getsetting("cwd");
  for (i = 2; i < argc; i++) {
    if (argv[i][0] == '/') {
      uchgrp(f, argv[i], mode);
    } else {
      if (!cwd) {
        sprintf(temp, "/%s", argv[i]);
      } else {
        sprintf(temp, "%s/%s", cwd, argv[i]);
      }
      compresspath(temp);
      uchgrp(f, temp, mode);
    }
  }
  fsclose(f);
  if (cwd)
    free(cwd);
  free(fsname);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe50(%rip),%rdi
call   1090 <getsetting@plt>
mov    %rax,-0x430(%rbp)
cmpq   $0x0,-0x430(%rbp)
jne    11e4 <main+0x54>
lea    0xe39(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0xa,-0x4(%rbp)
jmp    1382 <main+0x1f2>
cmpl   $0x3,-0x8(%rbp)
jge    120f <main+0x7f>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe24(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0xa,-0x4(%rbp)
jmp    1382 <main+0x1f2>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe1e(%rip),%rsi
lea    -0x20(%rbp),%rdx
call   1080 <sscanf@plt>
mov    -0x430(%rbp),%rdi
call   1050 <fsopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1263 <main+0xd3>
mov    -0x430(%rbp),%rsi
lea    0xdef(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0xa,-0x4(%rbp)
jmp    1382 <main+0x1f2>
lea    0xde8(%rip),%rdi
call   1090 <getsetting@plt>
mov    %rax,-0x428(%rbp)
movl   $0x2,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    134c <main+0x1bc>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
jne    12be <main+0x12e>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
mov    -0x20(%rbp),%edx
call   1040 <uchgrp@plt>
jmp    1339 <main+0x1a9>
cmpq   $0x0,-0x428(%rbp)
jne    12f2 <main+0x162>
lea    -0x420(%rbp),%rdi
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xd72(%rip),%rsi
mov    $0x0,%al
call   10a0 <sprintf@plt>
jmp    131a <main+0x18a>
lea    -0x420(%rbp),%rdi
mov    -0x428(%rbp),%rdx
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rcx
lea    0xd43(%rip),%rsi
mov    $0x0,%al
call   10a0 <sprintf@plt>
lea    -0x420(%rbp),%rdi
call   10b0 <compresspath@plt>
mov    -0x18(%rbp),%rdi
lea    -0x420(%rbp),%rsi
mov    -0x20(%rbp),%edx
call   1040 <uchgrp@plt>
jmp    133e <main+0x1ae>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    127d <main+0xed>
mov    -0x18(%rbp),%rdi
call   1070 <fsclose@plt>
cmpq   $0x0,-0x428(%rbp)
je     136f <main+0x1df>
mov    -0x428(%rbp),%rdi
call   1030 <free@plt>
mov    -0x430(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x418,%rsp
mov    %rsi,%r15
mov    %edi,%r14d
lea    0xe42(%rip),%rdi
call   10a0 <getsetting@plt>
test   %rax,%rax
je     11dd <main+0x3d>
cmp    $0x2,%r14d
jg     11ee <main+0x4e>
mov    (%r15),%rsi
lea    0xe32(%rip),%rdi
jmp    12ce <main+0x12e>
lea    0xe62(%rip),%rdi
call   1040 <puts@plt>
jmp    12d5 <main+0x135>
mov    %rax,%rbp
mov    0x8(%r15),%rdi
lea    0xe2a(%rip),%rsi
lea    0x4(%rsp),%rdx
call   1090 <sscanf@plt>
mov    %rbp,%rdi
call   1060 <fsopen@plt>
test   %rax,%rax
je     12c4 <main+0x124>
mov    %rax,%rbx
mov    %rbp,0x8(%rsp)
lea    0xe16(%rip),%rdi
call   10a0 <getsetting@plt>
mov    %rax,%r12
mov    %r14d,%r13d
mov    $0x2,%r14d
lea    0x10(%rsp),%rbp
jmp    1258 <main+0xb8>
xchg   %ax,%ax
mov    0x4(%rsp),%edx
mov    %rbx,%rdi
mov    %rcx,%rsi
call   1050 <uchgrp@plt>
add    $0x1,%r14
cmp    %r14,%r13
je     12a1 <main+0x101>
mov    (%r15,%r14,8),%rcx
cmpb   $0x2f,(%rcx)
je     1240 <main+0xa0>
mov    %rbp,%rdi
test   %r12,%r12
je     127c <main+0xdc>
lea    0xdd0(%rip),%rsi
mov    %r12,%rdx
xor    %eax,%eax
call   10b0 <sprintf@plt>
jmp    128d <main+0xed>
lea    0xdbf(%rip),%rsi
mov    %rcx,%rdx
xor    %eax,%eax
call   10b0 <sprintf@plt>
mov    %rbp,%rdi
call   10c0 <compresspath@plt>
mov    0x4(%rsp),%edx
mov    %rbx,%rdi
mov    %rbp,%rsi
jmp    124a <main+0xaa>
mov    %rbx,%rdi
call   1080 <fsclose@plt>
test   %r12,%r12
je     12b6 <main+0x116>
mov    %r12,%rdi
call   1030 <free@plt>
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
jmp    12da <main+0x13a>
lea    0xd5e(%rip),%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
mov    $0xa,%eax
add    $0x418,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.filesystem = type { i32 }
@.str = [10 x i8] c"imagefile\00"
@.str.1 = [22 x i8] c"Have you run ulogin?\0A\00"
@.str.2 = [28 x i8] c"Usage: %s <gid> <file> ...\0A\00"
@.str.3 = [3 x i8] c"%o\00"
@.str.4 = [19 x i8] c"Unable to open %s\0A\00"
@.str.5 = [4 x i8] c"cwd\00"
@.str.6 = [4 x i8] c"/%s\00"
@.str.7 = [6 x i8] c"%s/%s\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.filesystem*
%7 = alloca i32
%8 = alloca i32
%9 = alloca [1024 x i8]
%10 = alloca i8*
%11 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = call i8* @getsetting(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
store i8* %12, i8** %11
%13 = load i8*, i8** %11
%14 = icmp ne i8* %13, null
br i1 %14, label %17, label %15
15: ; preds = %2
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
store i32 10, i32* %3
br label %104
17: ; preds = %2
%18 = load i32, i32* %4
%19 = icmp slt i32 %18, 3
br i1 %19, label %20, label %25
20: ; preds = %17
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 0
%23 = load i8*, i8** %22
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i8* %23)
store i32 10, i32* %3
br label %104
25: ; preds = %17
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 1
%28 = load i8*, i8** %27
%29 = call i32 @sscanf(i8* %28, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %8)
%30 = load i8*, i8** %11
%31 = call %struct.filesystem* @fsopen(i8* %30)
store %struct.filesystem* %31, %struct.filesystem** %6
%32 = load %struct.filesystem*, %struct.filesystem** %6
%33 = icmp ne %struct.filesystem* %32, null
br i1 %33, label %37, label %34
34: ; preds = %25
%35 = load i8*, i8** %11
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i8* %35)
store i32 10, i32* %3
br label %104
37: ; preds = %25
%38 = call i8* @getsetting(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0))
store i8* %38, i8** %10
store i32 2, i32* %7
br label %39
39: ; preds = %90, %37
%40 = load i32, i32* %7
%41 = load i32, i32* %4
%42 = icmp slt i32 %40, %41
br i1 %42, label %43, label %93
43: ; preds = %39
%44 = load i8**, i8*** %5
%45 = load i32, i32* %7
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds i8*, i8** %44, i64 %46
%48 = load i8*, i8** %47
%49 = getelementptr inbounds i8, i8* %48, i64 0
%50 = load i8, i8* %49
%51 = sext i8 %50 to i32
%52 = icmp eq i32 %51, 47
br i1 %52, label %53, label %62
53: ; preds = %43
%54 = load %struct.filesystem*, %struct.filesystem** %6
%55 = load i8**, i8*** %5
%56 = load i32, i32* %7
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds i8*, i8** %55, i64 %57
%59 = load i8*, i8** %58
%60 = load i32, i32* %8
%61 = call i32 @uchgrp(%struct.filesystem* %54, i8* %59, i32 %60)
br label %89
62: ; preds = %43
%63 = load i8*, i8** %10
%64 = icmp ne i8* %63, null
br i1 %64, label %73, label %65
65: ; preds = %62
%66 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%67 = load i8**, i8*** %5
%68 = load i32, i32* %7
%69 = sext i32 %68 to i64
%70 = getelementptr inbounds i8*, i8** %67, i64 %69
%71 = load i8*, i8** %70
%72 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %66, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i8* %71)
br label %82
73: ; preds = %62
%74 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%75 = load i8*, i8** %10
%76 = load i8**, i8*** %5
%77 = load i32, i32* %7
%78 = sext i32 %77 to i64
%79 = getelementptr inbounds i8*, i8** %76, i64 %78
%80 = load i8*, i8** %79
%81 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %74, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0), i8* %75, i8* %80)
br label %82
82: ; preds = %73, %65
%83 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%84 = call i32 @compresspath(i8* %83)
%85 = load %struct.filesystem*, %struct.filesystem** %6
%86 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%87 = load i32, i32* %8
%88 = call i32 @uchgrp(%struct.filesystem* %85, i8* %86, i32 %87)
br label %89
89: ; preds = %82, %53
br label %90
90: ; preds = %89
%91 = load i32, i32* %7
%92 = add nsw i32 %91, 1
store i32 %92, i32* %7
br label %39
93: ; preds = %39
%94 = load %struct.filesystem*, %struct.filesystem** %6
%95 = call i32 @fsclose(%struct.filesystem* %94)
%96 = load i8*, i8** %10
%97 = icmp ne i8* %96, null
br i1 %97, label %98, label %101
98: ; preds = %93
%99 = load i8*, i8** %10
%100 = call i32 @free(i8* %99)
br label %101
101: ; preds = %98, %93
%102 = load i8*, i8** %11
%103 = call i32 @free(i8* %102)
store i32 0, i32* %3
br label %104
104: ; preds = %101, %34, %20, %15
%105 = load i32, i32* %3
ret i32 %105
}

LLVM IR (-O2):
%struct.filesystem = type { i32 }
@.str = [10 x i8] c"imagefile\00"
@.str.2 = [28 x i8] c"Usage: %s <gid> <file> ...\0A\00"
@.str.3 = [3 x i8] c"%o\00"
@.str.4 = [19 x i8] c"Unable to open %s\0A\00"
@.str.5 = [4 x i8] c"cwd\00"
@.str.6 = [4 x i8] c"/%s\00"
@.str.7 = [6 x i8] c"%s/%s\00"
@str = [21 x i8] c"Have you run ulogin?\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca [1024 x i8]
%5 = bitcast i32* %3 to i8*
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%7 = tail call i8* @getsetting(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i8* %7, null
br i1 %8, label %9, label %11
9: ; preds = %2
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str, i64 0, i64 0))
br label %56
11: ; preds = %2
%12 = icmp slt i32 %0, 3
br i1 %12, label %13, label %16
13: ; preds = %11
%14 = load i8*, i8** %1
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i8* %14)
br label %56
16: ; preds = %11
%17 = getelementptr inbounds i8*, i8** %1, i64 1
%18 = load i8*, i8** %17
%19 = call i32 @sscanf(i8* %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %3)
%20 = call %struct.filesystem* @fsopen(i8* %7)
%21 = icmp eq %struct.filesystem* %20, null
br i1 %21, label %22, label %24
22: ; preds = %16
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i8* %7)
br label %56
24: ; preds = %16
%25 = call i8* @getsetting(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0))
%26 = icmp eq i8* %25, null
%27 = zext i32 %0 to i64
br label %28
28: ; preds = %24, %46
%29 = phi i64 [ 2, %24 ], [ %47, %46 ]
%30 = getelementptr inbounds i8*, i8** %1, i64 %29
%31 = load i8*, i8** %30
%32 = load i8, i8* %31
%33 = icmp eq i8 %32, 47
br i1 %33, label %34, label %37
34: ; preds = %28
%35 = load i32, i32* %3
%36 = call i32 @uchgrp(%struct.filesystem* %20, i8* %31, i32 %35)
br label %46
37: ; preds = %28
br i1 %26, label %38, label %40
38: ; preds = %37
%39 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i8* %31)
br label %42
40: ; preds = %37
%41 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0), i8* %25, i8* %31)
br label %42
42: ; preds = %40, %38
%43 = call i32 @compresspath(i8* %6)
%44 = load i32, i32* %3
%45 = call i32 @uchgrp(%struct.filesystem* %20, i8* %6, i32 %44)
br label %46
46: ; preds = %34, %42
%47 = add nuw nsw i64 %29, 1
%48 = icmp eq i64 %47, %27
br i1 %48, label %49, label %28
49: ; preds = %46
%50 = call i32 @fsclose(%struct.filesystem* %20)
%51 = icmp eq i8* %25, null
br i1 %51, label %54, label %52
52: ; preds = %49
%53 = call i32 @free(i8* %25)
br label %54
54: ; preds = %52, %49
%55 = call i32 @free(i8* %7)
br label %56
56: ; preds = %54, %22, %13, %9
%57 = phi i32 [ 10, %13 ], [ 0, %54 ], [ 10, %22 ], [ 10, %9 ]
ret i32 %57
}