#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 /*<<< orphan*/ line;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ fwrite(char *, int, int /*<<< orphan*/,
                          int /*<<< orphan*/ *);
scalar_t__ malloc(int);
int /*<<< orphan*/ memcpy(char *, char *, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ strcat(char *, char *);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ strlen(char *);
void add_all() {
  FILE *raspchar = fopen("/dev/raspchar", "w");
  if (!raspchar) {
    printf("Failed to open raspchar\n");
    exit(1);
  }
  FILE *users = fopen("/etc/frusers", "r");
  if (!users) {
    printf("Failed to open frusers\n");
    fclose(raspchar);
    exit(1);
  }
  char line[256];
  while (fgets(line, sizeof(line), users)) {
    if (strcmp(line, "\n") != 0 && strcmp(line, "") != 0) {
      char *command = (char *)malloc(sizeof(char) * (5 + strlen(line)));
      line[strlen(line) - 1] = '\0';
      memcpy(command, "ADD \0", 5);
      strcat(command, line);
      fwrite(command, sizeof(char), strlen(command), raspchar);
      free(command);
    }
  }
  fclose(raspchar);
  fclose(users);
}


x86 assembly (clang, -O0):
<add_all>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
lea    0xe2e(%rip),%rdi
lea    0xe35(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    1203 <add_all+0x43>
lea    0xe1c(%rip),%rdi
call   1060 <printf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
lea    0xe1f(%rip),%rdi
lea    0xdfb(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1244 <add_all+0x84>
lea    0xe0a(%rip),%rdi
call   1060 <printf@plt>
mov    -0x8(%rbp),%rdi
call   1040 <fclose@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
jmp    1249 <add_all+0x89>
lea    -0x110(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x100,%esi
call   1070 <fgets@plt>
cmp    $0x0,%rax
je     134b <add_all+0x18b>
lea    -0x110(%rbp),%rdi
lea    0xdb1(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
je     1346 <add_all+0x186>
lea    -0x110(%rbp),%rdi
lea    0xd95(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
je     1346 <add_all+0x186>
lea    -0x110(%rbp),%rdi
call   1050 <strlen@plt>
add    $0x5,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   10a0 <malloc@plt>
mov    %rax,-0x118(%rbp)
lea    -0x110(%rbp),%rdi
call   1050 <strlen@plt>
sub    $0x1,%eax
cltq
movb   $0x0,-0x110(%rbp,%rax,1)
mov    -0x118(%rbp),%rdi
lea    0xd62(%rip),%rsi
mov    $0x5,%edx
call   1090 <memcpy@plt>
mov    -0x118(%rbp),%rdi
lea    -0x110(%rbp),%rsi
call   10c0 <strcat@plt>
mov    -0x118(%rbp),%rax
mov    %rax,-0x120(%rbp)
mov    -0x118(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x120(%rbp),%rdi
mov    %eax,%edx
mov    -0x8(%rbp),%rcx
mov    $0x1,%esi
call   10e0 <fwrite@plt>
mov    -0x118(%rbp),%rdi
call   1030 <free@plt>
jmp    1249 <add_all+0x89>
mov    -0x8(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<add_all>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x108,%rsp
lea    0xe28(%rip),%rdi
lea    0xe2f(%rip),%rsi
call   10b0 <fopen@plt>
test   %rax,%rax
je     1303 <add_all+0x143>
mov    %rax,%r14
lea    0xe19(%rip),%rdi
lea    0xe37(%rip),%rsi
call   10b0 <fopen@plt>
test   %rax,%rax
je     1319 <add_all+0x159>
mov    %rax,%r15
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x100,%esi
mov    %rax,%rdx
call   1070 <fgets@plt>
test   %rax,%rax
je     12e1 <add_all+0x121>
lea    0xdeb(%rip),%r12
lea    0xde5(%rip),%r13
jmp    1259 <add_all+0x99>
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    $0x100,%esi
mov    %r15,%rdx
call   1070 <fgets@plt>
test   %rax,%rax
je     12e1 <add_all+0x121>
mov    %rbx,%rdi
mov    %r12,%rsi
call   1080 <strcmp@plt>
test   %rax,%rax
je     1240 <add_all+0x80>
mov    %rbx,%rdi
mov    %r13,%rsi
call   1080 <strcmp@plt>
test   %rax,%rax
je     1240 <add_all+0x80>
mov    %rbx,%rdi
call   1060 <strlen@plt>
lea    0x5(%rax),%edi
call   10a0 <malloc@plt>
mov    %rax,%rbp
mov    %rbx,%rdi
call   1060 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%rbx,1)
mov    %rbp,%rdi
lea    0xda9(%rip),%rsi
mov    $0x5,%edx
call   1090 <memcpy@plt>
mov    %rbp,%rdi
mov    %rbx,%rsi
call   10c0 <strcat@plt>
mov    %rbp,%rdi
call   1060 <strlen@plt>
mov    %rbp,%rdi
mov    $0x1,%esi
mov    %eax,%edx
mov    %r14,%rcx
call   10e0 <fwrite@plt>
mov    %rbp,%rdi
call   1030 <free@plt>
jmp    1240 <add_all+0x80>
mov    %r14,%rdi
call   1050 <fclose@plt>
mov    %r15,%rdi
call   1050 <fclose@plt>
add    $0x108,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd15(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
lea    0xd17(%rip),%rdi
call   1040 <puts@plt>
mov    %r14,%rdi
call   1050 <fclose@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>

LLVM IR (-O0):
@.str = [14 x i8] c"/dev/raspchar\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [25 x i8] c"Failed to open raspchar\0A\00"
@.str.3 = [13 x i8] c"/etc/frusers\00"
@.str.4 = [2 x i8] c"r\00"
@.str.5 = [24 x i8] c"Failed to open frusers\0A\00"
@.str.6 = [2 x i8] c"\0A\00"
@.str.7 = [1 x i8] zeroinitializer
@.str.8 = [6 x i8] c"ADD \00\00"
define void @add_all() {
%1 = alloca i32*
%2 = alloca i32*
%3 = alloca [256 x i8]
%4 = alloca i8*
%5 = call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %5, i32** %1
%6 = load i32*, i32** %1
%7 = icmp ne i32* %6, null
br i1 %7, label %11, label %8
8: ; preds = %0
%9 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
%10 = call i32 @exit(i32 1)
unreachable
11: ; preds = %0
%12 = call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32* %12, i32** %2
%13 = load i32*, i32** %2
%14 = icmp ne i32* %13, null
br i1 %14, label %20, label %15
15: ; preds = %11
%16 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0))
%17 = load i32*, i32** %1
%18 = call i32 @fclose(i32* %17)
%19 = call i32 @exit(i32 1)
unreachable
20: ; preds = %11
br label %21
21: ; preds = %60, %20
%22 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%23 = load i32*, i32** %2
%24 = call i64 @fgets(i8* %22, i32 256, i32* %23)
%25 = icmp ne i64 %24, 0
br i1 %25, label %26, label %61
26: ; preds = %21
%27 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%28 = call i64 @strcmp(i8* %27, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%29 = icmp ne i64 %28, 0
br i1 %29, label %30, label %60
30: ; preds = %26
%31 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%32 = call i64 @strcmp(i8* %31, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.7, i64 0, i64 0))
%33 = icmp ne i64 %32, 0
br i1 %33, label %34, label %60
34: ; preds = %30
%35 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%36 = call i32 @strlen(i8* %35)
%37 = add nsw i32 5, %36
%38 = sext i32 %37 to i64
%39 = mul i64 1, %38
%40 = trunc i64 %39 to i32
%41 = call i64 @malloc(i32 %40)
%42 = inttoptr i64 %41 to i8*
store i8* %42, i8** %4
%43 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%44 = call i32 @strlen(i8* %43)
%45 = sub nsw i32 %44, 1
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 %46
store i8 0, i8* %47
%48 = load i8*, i8** %4
%49 = call i32 @memcpy(i8* %48, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.8, i64 0, i64 0), i32 5)
%50 = load i8*, i8** %4
%51 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%52 = call i32 @strcat(i8* %50, i8* %51)
%53 = load i8*, i8** %4
%54 = load i8*, i8** %4
%55 = call i32 @strlen(i8* %54)
%56 = load i32*, i32** %1
%57 = call i32 @fwrite(i8* %53, i32 1, i32 %55, i32* %56)
%58 = load i8*, i8** %4
%59 = call i32 @free(i8* %58)
br label %60
60: ; preds = %34, %30, %26
br label %21
61: ; preds = %21
%62 = load i32*, i32** %1
%63 = call i32 @fclose(i32* %62)
%64 = load i32*, i32** %2
%65 = call i32 @fclose(i32* %64)
ret void
}

LLVM IR (-O2):
@.str = [14 x i8] c"/dev/raspchar\00"
@.str.1 = [2 x i8] c"w\00"
@.str.3 = [13 x i8] c"/etc/frusers\00"
@.str.4 = [2 x i8] c"r\00"
@.str.6 = [2 x i8] c"\0A\00"
@.str.7 = [1 x i8] zeroinitializer
@.str.8 = [6 x i8] c"ADD \00\00"
@str = [24 x i8] c"Failed to open raspchar\00"
@str.9 = [23 x i8] c"Failed to open frusers\00"
define void @add_all() {
%1 = alloca [256 x i8]
%2 = tail call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%3 = icmp eq i32* %2, null
br i1 %3, label %4, label %7
4: ; preds = %0
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str, i64 0, i64 0))
%6 = tail call i32 @exit(i32 1)
unreachable
7: ; preds = %0
%8 = tail call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %14
10: ; preds = %7
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str.9, i64 0, i64 0))
%12 = tail call i32 @fclose(i32* %2)
%13 = tail call i32 @exit(i32 1)
unreachable
14: ; preds = %7
%15 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 0
%16 = call i64 @fgets(i8* %15, i32 256, i32* %8)
%17 = icmp eq i64 %16, 0
br i1 %17, label %41, label %18
18: ; preds = %14, %38
%19 = call i64 @strcmp(i8* %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%20 = icmp eq i64 %19, 0
br i1 %20, label %38, label %21
21: ; preds = %18
%22 = call i64 @strcmp(i8* %15, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.7, i64 0, i64 0))
%23 = icmp eq i64 %22, 0
br i1 %23, label %38, label %24
24: ; preds = %21
%25 = call i32 @strlen(i8* %15)
%26 = add nsw i32 %25, 5
%27 = call i64 @malloc(i32 %26)
%28 = inttoptr i64 %27 to i8*
%29 = call i32 @strlen(i8* %15)
%30 = add nsw i32 %29, -1
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 %31
store i8 0, i8* %32
%33 = call i32 @memcpy(i8* %28, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.8, i64 0, i64 0), i32 5)
%34 = call i32 @strcat(i8* %28, i8* %15)
%35 = call i32 @strlen(i8* %28)
%36 = call i32 @fwrite(i8* %28, i32 1, i32 %35, i32* %2)
%37 = call i32 @free(i8* %28)
br label %38
38: ; preds = %24, %21, %18
%39 = call i64 @fgets(i8* %15, i32 256, i32* %8)
%40 = icmp eq i64 %39, 0
br i1 %40, label %41, label %18
41: ; preds = %38, %14
%42 = call i32 @fclose(i32* %2)
%43 = call i32 @fclose(i32* %8)
ret void
}