#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 */
scalar_t__ EINVAL;
int /*<<< orphan*/ O_RDWR;
int /*<<< orphan*/ close(int);
scalar_t__ errno;
int /*<<< orphan*/ exit(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ sprintf(char *, char *, int, int);
int write(int, char *, int);
int writeload(void) {
  int loadfd;
  char rule[(23 + 23 + 5 + 2) + 1];
  int sub;
  int obj;
  int err;
  int writesize = (23 + 23 + 5 + 2);
  loadfd = open("/sys/fs/smackfs/load", O_RDWR);
  if (loadfd < 0)
    loadfd = open("/smack/load", O_RDWR);
  if (loadfd < 0) {
    perror("opening rules list");
    return -1;
  }
  for (sub = 1; sub <= 200; sub++) {
    for (obj = 1; obj <= 200; obj++) {
      if (sub == obj)
        continue;
      if (sub == obj + 1)
        sprintf(rule, "speed-%-17d speed-%-17d rwxa-\n", sub, obj);
      else
        sprintf(rule, "speed-%-17d speed-%-17d -----\n", sub, obj);
      err = write(loadfd, rule, writesize);
      if (err == writesize)
        continue;
      if (err == -1 && errno == EINVAL && writesize == (23 + 23 + 5 + 2)) {
        writesize = ((23 + 23 + 5 + 2) - 1);
        err = write(loadfd, rule, writesize);
        if (err == writesize)
          continue;
      }
      perror("writing rules list (load)");
      exit(1);
    }
  }
  close(loadfd);
  return 0;
}


x86 assembly (clang, -O0):
<writeload>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x35,-0x50(%rbp)
mov    0x2e72(%rip),%rax
mov    (%rax),%esi
lea    0xe81(%rip),%rdi
call   1050 <open@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    11a9 <writeload+0x49>
mov    0x2e50(%rip),%rax
mov    (%rax),%esi
lea    0xe74(%rip),%rdi
call   1050 <open@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    11cb <writeload+0x6b>
lea    0xe67(%rip),%rdi
call   1060 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    130c <writeload+0x1ac>
movl   $0x1,-0x44(%rbp)
cmpl   $0xc8,-0x44(%rbp)
jg     12fd <writeload+0x19d>
movl   $0x1,-0x48(%rbp)
cmpl   $0xc8,-0x48(%rbp)
jg     12ea <writeload+0x18a>
mov    -0x44(%rbp),%eax
cmp    -0x48(%rbp),%eax
jne    1204 <writeload+0xa4>
jmp    12dc <writeload+0x17c>
mov    -0x44(%rbp),%eax
mov    -0x48(%rbp),%ecx
add    $0x1,%ecx
cmp    %ecx,%eax
jne    1230 <writeload+0xd0>
lea    -0x40(%rbp),%rdi
mov    -0x44(%rbp),%edx
mov    -0x48(%rbp),%ecx
lea    0xe0e(%rip),%rsi
call   1070 <sprintf@plt>
jmp    1246 <writeload+0xe6>
lea    -0x40(%rbp),%rdi
mov    -0x44(%rbp),%edx
mov    -0x48(%rbp),%ecx
lea    0xe12(%rip),%rsi
call   1070 <sprintf@plt>
mov    -0x8(%rbp),%edi
lea    -0x40(%rbp),%rsi
mov    -0x50(%rbp),%edx
call   1030 <write@plt>
mov    %eax,-0x4c(%rbp)
mov    -0x4c(%rbp),%eax
cmp    -0x50(%rbp),%eax
jne    1269 <writeload+0x109>
jmp    12dc <writeload+0x17c>
cmpl   $0xffffffff,-0x4c(%rbp)
jne    12c6 <writeload+0x166>
mov    0x2d5e(%rip),%rax
mov    (%rax),%rax
mov    0x2d4c(%rip),%rcx
cmp    (%rcx),%rax
jne    12c6 <writeload+0x166>
cmpl   $0x35,-0x50(%rbp)
jne    12c6 <writeload+0x166>
movl   $0x34,-0x50(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x40(%rbp),%rsi
mov    -0x50(%rbp),%edx
call   1030 <write@plt>
mov    %eax,-0x4c(%rbp)
mov    -0x4c(%rbp),%eax
cmp    -0x50(%rbp),%eax
jne    12c1 <writeload+0x161>
jmp    12dc <writeload+0x17c>
jmp    12c6 <writeload+0x166>
lea    0xda5(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x48(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x48(%rbp)
jmp    11e6 <writeload+0x86>
jmp    12ef <writeload+0x18f>
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    11d2 <writeload+0x72>
mov    -0x8(%rbp),%edi
call   1040 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<writeload>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    0x2e73(%rip),%rbx
mov    (%rbx),%esi
lea    0xe82(%rip),%rdi
call   1050 <open@plt>
mov    %eax,%r15d
test   %eax,%eax
jns    11a3 <writeload+0x43>
mov    (%rbx),%esi
lea    0xe82(%rip),%rdi
call   1050 <open@plt>
mov    %eax,%r15d
test   %eax,%eax
js     1294 <writeload+0x134>
mov    $0x1,%r12d
mov    $0x35,%ebx
xor    %r13d,%r13d
mov    %rsp,%r14
jmp    11d5 <writeload+0x75>
cs nopw 0x0(%rax,%rax,1)
add    $0x1,%r12d
add    $0xffffffff,%r13d
cmp    $0xc9,%r12d
je     127b <writeload+0x11b>
mov    $0x1,%ebp
jmp    11eb <writeload+0x8b>
nopl   0x0(%rax)
add    $0x1,%ebp
cmp    $0xc9,%ebp
je     11c0 <writeload+0x60>
lea    0x0(%r13,%rbp,1),%eax
cmp    $0x1,%eax
je     11e0 <writeload+0x80>
test   %eax,%eax
lea    0xe55(%rip),%rsi
lea    0xe2f(%rip),%rax
cmove  %rax,%rsi
mov    %r14,%rdi
mov    %r12d,%edx
mov    %ebp,%ecx
call   1070 <sprintf@plt>
mov    %r15d,%edi
mov    %r14,%rsi
mov    %ebx,%edx
call   1030 <write@plt>
cmp    %ebx,%eax
je     11e0 <writeload+0x80>
cmp    $0xffffffff,%eax
jne    1265 <writeload+0x105>
mov    0x2da5(%rip),%rax
mov    (%rax),%rax
mov    0x2d93(%rip),%rcx
cmp    (%rcx),%rax
jne    1265 <writeload+0x105>
cmp    $0x35,%ebx
jne    1265 <writeload+0x105>
mov    $0x34,%ebx
mov    %r15d,%edi
mov    %r14,%rsi
mov    $0x34,%edx
call   1030 <write@plt>
cmp    $0x34,%eax
je     11e0 <writeload+0x80>
lea    0xe06(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    %r15d,%edi
call   1040 <close@plt>
xor    %eax,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd86(%rip),%rdi
call   1060 <perror@plt>
mov    $0xffffffff,%eax
jmp    1285 <writeload+0x125>

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

LLVM IR (-O2):
@.str = [21 x i8] c"/sys/fs/smackfs/load\00"
@O_RDWR = global i32 0
@.str.1 = [12 x i8] c"/smack/load\00"
@.str.2 = [19 x i8] c"opening rules list\00"
@.str.3 = [31 x i8] c"speed-%-17d speed-%-17d rwxa-\0A\00"
@.str.4 = [31 x i8] c"speed-%-17d speed-%-17d -----\0A\00"
@errno = global i64 0
@EINVAL = global i64 0
@.str.5 = [26 x i8] c"writing rules list (load)\00"
define i32 @writeload() {
%1 = alloca [54 x i8]
%2 = getelementptr inbounds [54 x i8], [54 x i8]* %1, i64 0, i64 0
%3 = load i32, i32* @O_RDWR
%4 = tail call i32 @open(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = icmp slt i32 %4, 0
br i1 %5, label %6, label %10
6: ; preds = %0
%7 = load i32, i32* @O_RDWR
%8 = tail call i32 @open(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %7)
%9 = icmp slt i32 %8, 0
br i1 %9, label %12, label %10
10: ; preds = %0, %6
%11 = phi i32 [ %8, %6 ], [ %4, %0 ]
br label %14
12: ; preds = %6
%13 = tail call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
br label %50
14: ; preds = %10, %45
%15 = phi i32 [ %43, %45 ], [ 53, %10 ]
%16 = phi i32 [ %46, %45 ], [ 1, %10 ]
br label %17
17: ; preds = %14, %42
%18 = phi i32 [ %15, %14 ], [ %43, %42 ]
%19 = phi i32 [ 1, %14 ], [ %21, %42 ]
%20 = icmp eq i32 %16, %19
%21 = add nuw nsw i32 %19, 1
br i1 %20, label %42, label %22
22: ; preds = %17
%23 = icmp eq i32 %16, %21
%24 = select i1 %23, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0)
%25 = call i32 @sprintf(i8* %2, i8* dereferenceable(1) %24, i32 %16, i32 %19)
%26 = call i32 @write(i32 %11, i8* %2, i32 %18)
%27 = icmp eq i32 %26, %18
br i1 %27, label %42, label %28
28: ; preds = %22
%29 = icmp eq i32 %26, -1
br i1 %29, label %30, label %39
30: ; preds = %28
%31 = load i64, i64* @errno
%32 = load i64, i64* @EINVAL
%33 = icmp eq i64 %31, %32
%34 = icmp eq i32 %18, 53
%35 = select i1 %33, i1 %34, i1 false
br i1 %35, label %36, label %39
36: ; preds = %30
%37 = call i32 @write(i32 %11, i8* %2, i32 52)
%38 = icmp eq i32 %37, 52
br i1 %38, label %42, label %39
39: ; preds = %36, %30, %28
%40 = tail call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.5, i64 0, i64 0))
%41 = tail call i32 @exit(i32 1)
unreachable
42: ; preds = %17, %36, %22
%43 = phi i32 [ 52, %36 ], [ %18, %22 ], [ %18, %17 ]
%44 = icmp eq i32 %21, 201
br i1 %44, label %45, label %17
45: ; preds = %42
%46 = add nuw nsw i32 %16, 1
%47 = icmp eq i32 %46, 201
br i1 %47, label %48, label %14
48: ; preds = %45
%49 = tail call i32 @close(i32 %11)
br label %50
50: ; preds = %48, %12
%51 = phi i32 [ -1, %12 ], [ 0, %48 ]
ret i32 %51
}