#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 */

/* Variables and functions */
int /*<<< orphan*/ O_RDWR;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
char *malloc(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ sprintf(char *, char *, int, int);
int strlen(char *);
int write(int, char *, int);
int writeload2(void) {
  int fd;
  int sub;
  int obj;
  int err;
  int writesize;
  char *rule;
  rule = malloc((255 + 255 + 5 + 2));
  if (rule == NULL) {
    perror("allocating buffer");
    return -1;
  }
  fd = open("/sys/fs/smackfs/load2", O_RDWR);
  if (fd < 0)
    fd = open("/smack/load2", O_RDWR);
  if (fd < 0) {
    perror("opening rules list (load2)");
    return -1;
  }
  for (sub = 1; sub <= 200; sub++) {
    for (obj = 1; obj <= 200; obj++) {
      if (sub == obj)
        continue;
      if (sub == obj + 1)
        sprintf(rule,
                "com.smack-laboritories-duty-now-for-the-future"
                "-%d "
                "com.smack-laboritories-duty-now-for-the-future"
                "-%d rwxa-\n",
                sub, obj);
      else
        sprintf(rule,
                "com.smack-laboritories-duty-now-for-the-future"
                "-%d "
                "com.smack-laboritories-duty-now-for-the-future"
                "-%d -----\n",
                sub, obj);
      writesize = strlen(rule);
      err = write(fd, rule, writesize);
      if (err != writesize) {
        perror("writing rules list (load2)");
        exit(1);
      }
    }
  }
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<writeload2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    $0x205,%edi
call   1060 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11b9 <writeload2+0x39>
lea    0xe58(%rip),%rdi
call   1080 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1305 <writeload2+0x185>
mov    0x2e28(%rip),%rax
mov    (%rax),%esi
lea    0xe49(%rip),%rdi
call   1070 <open@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    11f3 <writeload2+0x73>
mov    0x2e06(%rip),%rax
mov    (%rax),%esi
lea    0xe3d(%rip),%rdi
call   1070 <open@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    1215 <writeload2+0x95>
lea    0xe31(%rip),%rdi
call   1080 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1305 <writeload2+0x185>
movl   $0x1,-0xc(%rbp)
cmpl   $0xc8,-0xc(%rbp)
jg     12f6 <writeload2+0x176>
movl   $0x1,-0x10(%rbp)
cmpl   $0xc8,-0x10(%rbp)
jg     12e3 <writeload2+0x163>
mov    -0xc(%rbp),%eax
cmp    -0x10(%rbp),%eax
jne    124e <writeload2+0xce>
jmp    12d5 <writeload2+0x155>
mov    -0xc(%rbp),%eax
mov    -0x10(%rbp),%ecx
add    $0x1,%ecx
cmp    %ecx,%eax
jne    127a <writeload2+0xfa>
mov    -0x20(%rbp),%rdi
mov    -0xc(%rbp),%edx
mov    -0x10(%rbp),%ecx
lea    0xde0(%rip),%rsi
call   1090 <sprintf@plt>
jmp    1290 <writeload2+0x110>
mov    -0x20(%rbp),%rdi
mov    -0xc(%rbp),%edx
mov    -0x10(%rbp),%ecx
lea    0xe30(%rip),%rsi
call   1090 <sprintf@plt>
mov    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x20(%rbp),%rsi
mov    -0x18(%rbp),%edx
call   1030 <write@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
je     12d0 <writeload2+0x150>
lea    0xe65(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
jmp    12d5 <writeload2+0x155>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1230 <writeload2+0xb0>
jmp    12e8 <writeload2+0x168>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    121c <writeload2+0x9c>
mov    -0x8(%rbp),%edi
call   1050 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<writeload2>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    $0x205,%edi
call   1060 <malloc@plt>
test   %rax,%rax
je     1290 <writeload2+0x110>
mov    %rax,%r12
mov    0x2e40(%rip),%rbx
mov    (%rbx),%esi
lea    0xe61(%rip),%rdi
call   1070 <open@plt>
mov    %eax,%r14d
test   %eax,%eax
jns    11d6 <writeload2+0x56>
mov    (%rbx),%esi
lea    0xe62(%rip),%rdi
call   1070 <open@plt>
mov    %eax,%r14d
test   %eax,%eax
js     1299 <writeload2+0x119>
mov    $0x1,%r15d
xor    %r13d,%r13d
jmp    1201 <writeload2+0x81>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
add    $0x1,%r15d
add    $0xffffffff,%r13d
cmp    $0xc9,%r15d
je     1277 <writeload2+0xf7>
mov    $0x1,%ebp
jmp    121b <writeload2+0x9b>
nopl   0x0(%rax,%rax,1)
add    $0x1,%ebp
cmp    $0xc9,%ebp
je     11f0 <writeload2+0x70>
lea    0x0(%r13,%rbp,1),%eax
cmp    $0x1,%eax
je     1210 <writeload2+0x90>
test   %eax,%eax
lea    0xe8d(%rip),%rsi
lea    0xe1b(%rip),%rax
cmove  %rax,%rsi
mov    %r12,%rdi
mov    %r15d,%edx
mov    %ebp,%ecx
call   1090 <sprintf@plt>
mov    %r12,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebx
mov    %r14d,%edi
mov    %r12,%rsi
mov    %eax,%edx
call   1030 <write@plt>
cmp    %ebx,%eax
je     1210 <writeload2+0x90>
lea    0xebe(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    %r14d,%edi
call   1050 <close@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd69(%rip),%rdi
jmp    12a0 <writeload2+0x120>
lea    0xd95(%rip),%rdi
call   1080 <perror@plt>
mov    $0xffffffff,%eax
jmp    1281 <writeload2+0x101>

LLVM IR (-O0):
@.str = [18 x i8] c"allocating buffer\00"
@.str.1 = [22 x i8] c"/sys/fs/smackfs/load2\00"
@O_RDWR = global i32 0
@.str.2 = [13 x i8] c"/smack/load2\00"
@.str.3 = [27 x i8] c"opening rules list (load2)\00"
@.str.4 = [107 x i8] c"com.smack-laboritories-duty-now-for-the-future-%d com.smack-laboritories-duty-now-for-the-future-%d rwxa-\0A\00"
@.str.5 = [107 x i8] c"com.smack-laboritories-duty-now-for-the-future-%d com.smack-laboritories-duty-now-for-the-future-%d -----\0A\00"
@.str.6 = [27 x i8] c"writing rules list (load2)\00"
define i32 @writeload2() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = call i8* @malloc(i32 517)
store i8* %8, i8** %7
%9 = load i8*, i8** %7
%10 = icmp eq i8* %9, null
br i1 %10, label %11, label %13
11: ; preds = %0
%12 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %1
br label %78
13: ; preds = %0
%14 = load i32, i32* @O_RDWR
%15 = call i32 @open(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 %14)
store i32 %15, i32* %2
%16 = load i32, i32* %2
%17 = icmp slt i32 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %13
%19 = load i32, i32* @O_RDWR
%20 = call i32 @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i32 %19)
store i32 %20, i32* %2
br label %21
21: ; preds = %18, %13
%22 = load i32, i32* %2
%23 = icmp slt i32 %22, 0
br i1 %23, label %24, label %26
24: ; preds = %21
%25 = call i32 @perror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0))
store i32 -1, i32* %1
br label %78
26: ; preds = %21
store i32 1, i32* %3
br label %27
27: ; preds = %72, %26
%28 = load i32, i32* %3
%29 = icmp sle i32 %28, 200
br i1 %29, label %30, label %75
30: ; preds = %27
store i32 1, i32* %4
br label %31
31: ; preds = %68, %30
%32 = load i32, i32* %4
%33 = icmp sle i32 %32, 200
br i1 %33, label %34, label %71
34: ; preds = %31
%35 = load i32, i32* %3
%36 = load i32, i32* %4
%37 = icmp eq i32 %35, %36
br i1 %37, label %38, label %39
38: ; preds = %34
br label %68
39: ; preds = %34
%40 = load i32, i32* %3
%41 = load i32, i32* %4
%42 = add nsw i32 %41, 1
%43 = icmp eq i32 %40, %42
br i1 %43, label %44, label %49
44: ; preds = %39
%45 = load i8*, i8** %7
%46 = load i32, i32* %3
%47 = load i32, i32* %4
%48 = call i32 @sprintf(i8* %45, i8* getelementptr inbounds ([107 x i8], [107 x i8]* @.str.4, i64 0, i64 0), i32 %46, i32 %47)
br label %54
49: ; preds = %39
%50 = load i8*, i8** %7
%51 = load i32, i32* %3
%52 = load i32, i32* %4
%53 = call i32 @sprintf(i8* %50, i8* getelementptr inbounds ([107 x i8], [107 x i8]* @.str.5, i64 0, i64 0), i32 %51, i32 %52)
br label %54
54: ; preds = %49, %44
%55 = load i8*, i8** %7
%56 = call i32 @strlen(i8* %55)
store i32 %56, i32* %6
%57 = load i32, i32* %2
%58 = load i8*, i8** %7
%59 = load i32, i32* %6
%60 = call i32 @write(i32 %57, i8* %58, i32 %59)
store i32 %60, i32* %5
%61 = load i32, i32* %5
%62 = load i32, i32* %6
%63 = icmp ne i32 %61, %62
br i1 %63, label %64, label %67
64: ; preds = %54
%65 = call i32 @perror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.6, i64 0, i64 0))
%66 = call i32 @exit(i32 1)
unreachable
67: ; preds = %54
br label %68
68: ; preds = %67, %38
%69 = load i32, i32* %4
%70 = add nsw i32 %69, 1
store i32 %70, i32* %4
br label %31
71: ; preds = %31
br label %72
72: ; preds = %71
%73 = load i32, i32* %3
%74 = add nsw i32 %73, 1
store i32 %74, i32* %3
br label %27
75: ; preds = %27
%76 = load i32, i32* %2
%77 = call i32 @close(i32 %76)
store i32 0, i32* %1
br label %78
78: ; preds = %75, %24, %11
%79 = load i32, i32* %1
ret i32 %79
}

LLVM IR (-O2):
@.str = [18 x i8] c"allocating buffer\00"
@.str.1 = [22 x i8] c"/sys/fs/smackfs/load2\00"
@O_RDWR = global i32 0
@.str.2 = [13 x i8] c"/smack/load2\00"
@.str.3 = [27 x i8] c"opening rules list (load2)\00"
@.str.4 = [107 x i8] c"com.smack-laboritories-duty-now-for-the-future-%d com.smack-laboritories-duty-now-for-the-future-%d rwxa-\0A\00"
@.str.5 = [107 x i8] c"com.smack-laboritories-duty-now-for-the-future-%d com.smack-laboritories-duty-now-for-the-future-%d -----\0A\00"
@.str.6 = [27 x i8] c"writing rules list (load2)\00"
define i32 @writeload2() {
%1 = tail call dereferenceable_or_null(517) i8* @malloc(i32 517)
%2 = icmp eq i8* %1, null
br i1 %2, label %3, label %5
3: ; preds = %0
%4 = tail call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
br label %40
5: ; preds = %0
%6 = load i32, i32* @O_RDWR
%7 = tail call i32 @open(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 %6)
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %13
9: ; preds = %5
%10 = load i32, i32* @O_RDWR
%11 = tail call i32 @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i32 %10)
%12 = icmp slt i32 %11, 0
br i1 %12, label %15, label %13
13: ; preds = %5, %9
%14 = phi i32 [ %11, %9 ], [ %7, %5 ]
br label %17
15: ; preds = %9
%16 = tail call i32 @perror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0))
br label %40
17: ; preds = %13, %35
%18 = phi i32 [ %36, %35 ], [ 1, %13 ]
br label %19
19: ; preds = %17, %33
%20 = phi i32 [ 1, %17 ], [ %22, %33 ]
%21 = icmp eq i32 %18, %20
%22 = add nuw nsw i32 %20, 1
br i1 %21, label %33, label %23
23: ; preds = %19
%24 = icmp eq i32 %18, %22
%25 = select i1 %24, i8* getelementptr inbounds ([107 x i8], [107 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([107 x i8], [107 x i8]* @.str.5, i64 0, i64 0)
%26 = tail call i32 @sprintf(i8* %1, i8* dereferenceable(1) %25, i32 %18, i32 %20)
%27 = tail call i32 @strlen(i8* %1)
%28 = tail call i32 @write(i32 %14, i8* %1, i32 %27)
%29 = icmp eq i32 %28, %27
br i1 %29, label %33, label %30
30: ; preds = %23
%31 = tail call i32 @perror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.6, i64 0, i64 0))
%32 = tail call i32 @exit(i32 1)
unreachable
33: ; preds = %19, %23
%34 = icmp eq i32 %22, 201
br i1 %34, label %35, label %19
35: ; preds = %33
%36 = add nuw nsw i32 %18, 1
%37 = icmp eq i32 %36, 201
br i1 %37, label %38, label %17
38: ; preds = %35
%39 = tail call i32 @close(i32 %14)
br label %40
40: ; preds = %38, %15, %3
%41 = phi i32 [ -1, %3 ], [ -1, %15 ], [ 0, %38 ]
ret i32 %41
}