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

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fwrite(char *, int, int /*<<< orphan*/,
                          int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ sprintf(char *, char *, int);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int /*<<< orphan*/ strlen(char *);
int pru_bridge_init(int channel_sizes[10]) {
  int i = 0;
  char input[100], char_sizes[11];
  strcpy(input, "");
  int size_check = 0;
  for (i = 0; i < 10; i++) {
    size_check += channel_sizes[i];
  }
  if (size_check > 11500) {
    printf("Buffer size insufficient\n");
    return 1;
  }
  for (i = 0; i < 10; i++) {
    sprintf(char_sizes, "%d", channel_sizes[i]);
    strcat(input, char_sizes);
    strcat(input, " ");
    if (channel_sizes[i] < 0) {
      printf("Invalid Size\n");
      return 1;
    }
  }
  strcat(input, "\n\0");
  FILE *fp = fopen("/sys/devices/virtual/misc/pru_bridge/init", "w");
  printf("Init opened\n");
  if (fp != NULL) {
    fwrite(input, sizeof(char), strlen(input), fp);
    fclose(fp);
  } else
    printf("Unable to open init\n");
  return 0;
}


x86 assembly (clang, -O0):
<pru_bridge_init>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
lea    -0x80(%rbp),%rdi
lea    0xec4(%rip),%rsi
call   1030 <strcpy@plt>
movl   $0x0,-0x90(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0xa,-0x14(%rbp)
jge    11e6 <pru_bridge_init+0x66>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
add    -0x90(%rbp),%eax
mov    %eax,-0x90(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11b7 <pru_bridge_init+0x37>
cmpl   $0x2cec,-0x90(%rbp)
jle    120e <pru_bridge_init+0x8e>
lea    0xe03(%rip),%rdi
call   1060 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1330 <pru_bridge_init+0x1b0>
movl   $0x0,-0x14(%rbp)
cmpl   $0xa,-0x14(%rbp)
jge    129a <pru_bridge_init+0x11a>
lea    -0x8b(%rbp),%rdi
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
lea    0xde2(%rip),%rsi
call   1090 <sprintf@plt>
lea    -0x80(%rbp),%rdi
lea    -0x8b(%rbp),%rsi
call   1080 <strcat@plt>
lea    -0x80(%rbp),%rdi
lea    0xdc5(%rip),%rsi
call   1080 <strcat@plt>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
cmpl   $0x0,(%rax,%rcx,4)
jge    1287 <pru_bridge_init+0x107>
lea    0xda9(%rip),%rdi
call   1060 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1330 <pru_bridge_init+0x1b0>
jmp    128c <pru_bridge_init+0x10c>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1215 <pru_bridge_init+0x95>
lea    -0x80(%rbp),%rdi
lea    0xdd6(%rip),%rsi
call   1080 <strcat@plt>
lea    0xd7c(%rip),%rdi
lea    0xd9f(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x98(%rbp)
lea    0xd8e(%rip),%rdi
call   1060 <printf@plt>
cmpq   $0x0,-0x98(%rbp)
je     131d <pru_bridge_init+0x19d>
lea    -0x80(%rbp),%rax
mov    %rax,-0xa0(%rbp)
lea    -0x80(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0xa0(%rbp),%rdi
mov    %eax,%edx
mov    -0x98(%rbp),%rcx
mov    $0x1,%esi
call   10a0 <fwrite@plt>
mov    -0x98(%rbp),%rdi
call   1040 <fclose@plt>
jmp    1329 <pru_bridge_init+0x1a9>
lea    0xd42(%rip),%rdi
call   1060 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pru_bridge_init>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x78,%rsp
mov    %rdi,%rbx
lea    0xe6c(%rip),%rsi
lea    0x10(%rsp),%rdi
call   1030 <strcpy@plt>
mov    (%rbx),%edx
movdqu 0x18(%rbx),%xmm0
movdqu 0x8(%rbx),%xmm1
paddd  %xmm0,%xmm1
pshufd $0xee,%xmm1,%xmm0
paddd  %xmm1,%xmm0
pshufd $0x55,%xmm0,%xmm1
paddd  %xmm0,%xmm1
movd   %xmm1,%eax
add    0x4(%rbx),%eax
add    %edx,%eax
cmp    $0x2cec,%eax
jle    11e0 <pru_bridge_init+0x60>
lea    0xe83(%rip),%rdi
jmp    127b <pru_bridge_init+0xfb>
lea    0xe19(%rip),%rsi
lea    0x5(%rsp),%r14
mov    %r14,%rdi
call   1090 <sprintf@plt>
lea    0x10(%rsp),%r15
mov    %r15,%rdi
mov    %r14,%rsi
call   1080 <strcat@plt>
lea    0xdf8(%rip),%rsi
mov    %r15,%rdi
call   1080 <strcat@plt>
cmpl   $0x0,(%rbx)
js     1274 <pru_bridge_init+0xf4>
mov    $0x1,%ebp
lea    0xddc(%rip),%r14
lea    0x5(%rsp),%r15
lea    0x10(%rsp),%r12
lea    0xdce(%rip),%r13
cs nopw 0x0(%rax,%rax,1)
nop
cmp    $0xa,%rbp
je     1294 <pru_bridge_init+0x114>
mov    (%rbx,%rbp,4),%edx
mov    %r15,%rdi
mov    %r14,%rsi
call   1090 <sprintf@plt>
mov    %r12,%rdi
mov    %r15,%rsi
call   1080 <strcat@plt>
mov    %r12,%rdi
mov    %r13,%rsi
call   1080 <strcat@plt>
cmpl   $0x0,(%rbx,%rbp,4)
lea    0x1(%rbp),%rbp
jns    1240 <pru_bridge_init+0xc0>
lea    0xdd6(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%eax
add    $0x78,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xddc(%rip),%rsi
lea    0x10(%rsp),%rdi
call   1080 <strcat@plt>
lea    0xd59(%rip),%rdi
lea    0xd7c(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%rbx
lea    0xd6f(%rip),%rdi
call   1040 <puts@plt>
test   %rbx,%rbx
je     12f5 <pru_bridge_init+0x175>
lea    0x10(%rsp),%r14
mov    %r14,%rdi
call   1060 <strlen@plt>
mov    %r14,%rdi
mov    $0x1,%esi
mov    %eax,%edx
mov    %rbx,%rcx
call   10a0 <fwrite@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
jmp    1301 <pru_bridge_init+0x181>
lea    0xd41(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
jmp    1285 <pru_bridge_init+0x105>

LLVM IR (-O0):
@.str = [1 x i8] zeroinitializer
@.str.1 = [26 x i8] c"Buffer size insufficient\0A\00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [2 x i8] c" \00"
@.str.4 = [14 x i8] c"Invalid Size\0A\00"
@.str.5 = [3 x i8] c"\0A\00\00"
@.str.6 = [42 x i8] c"/sys/devices/virtual/misc/pru_bridge/init\00"
@.str.7 = [2 x i8] c"w\00"
@.str.8 = [13 x i8] c"Init opened\0A\00"
@.str.9 = [21 x i8] c"Unable to open init\0A\00"
define i32 @pru_bridge_init(i32* %0) {
%2 = alloca i32
%3 = alloca i32*
%4 = alloca i32
%5 = alloca [100 x i8]
%6 = alloca [11 x i8]
%7 = alloca i32
%8 = alloca i32*
store i32* %0, i32** %3
store i32 0, i32* %4
%9 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%10 = call i32 @strcpy(i8* %9, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %7
store i32 0, i32* %4
br label %11
11: ; preds = %22, %1
%12 = load i32, i32* %4
%13 = icmp slt i32 %12, 10
br i1 %13, label %14, label %25
14: ; preds = %11
%15 = load i32*, i32** %3
%16 = load i32, i32* %4
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i32, i32* %15, i64 %17
%19 = load i32, i32* %18
%20 = load i32, i32* %7
%21 = add nsw i32 %20, %19
store i32 %21, i32* %7
br label %22
22: ; preds = %14
%23 = load i32, i32* %4
%24 = add nsw i32 %23, 1
store i32 %24, i32* %4
br label %11
25: ; preds = %11
%26 = load i32, i32* %7
%27 = icmp sgt i32 %26, 11500
br i1 %27, label %28, label %30
28: ; preds = %25
%29 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %2
br label %77
30: ; preds = %25
store i32 0, i32* %4
br label %31
31: ; preds = %56, %30
%32 = load i32, i32* %4
%33 = icmp slt i32 %32, 10
br i1 %33, label %34, label %59
34: ; preds = %31
%35 = getelementptr inbounds [11 x i8], [11 x i8]* %6, i64 0, i64 0
%36 = load i32*, i32** %3
%37 = load i32, i32* %4
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i32, i32* %36, i64 %38
%40 = load i32, i32* %39
%41 = call i32 @sprintf(i8* %35, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %40)
%42 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%43 = getelementptr inbounds [11 x i8], [11 x i8]* %6, i64 0, i64 0
%44 = call i32 @strcat(i8* %42, i8* %43)
%45 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%46 = call i32 @strcat(i8* %45, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%47 = load i32*, i32** %3
%48 = load i32, i32* %4
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds i32, i32* %47, i64 %49
%51 = load i32, i32* %50
%52 = icmp slt i32 %51, 0
br i1 %52, label %53, label %55
53: ; preds = %34
%54 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0))
store i32 1, i32* %2
br label %77
55: ; preds = %34
br label %56
56: ; preds = %55
%57 = load i32, i32* %4
%58 = add nsw i32 %57, 1
store i32 %58, i32* %4
br label %31
59: ; preds = %31
%60 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%61 = call i32 @strcat(i8* %60, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
%62 = call i32* @fopen(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
store i32* %62, i32** %8
%63 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.8, i64 0, i64 0))
%64 = load i32*, i32** %8
%65 = icmp ne i32* %64, null
br i1 %65, label %66, label %74
66: ; preds = %59
%67 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%68 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%69 = call i32 @strlen(i8* %68)
%70 = load i32*, i32** %8
%71 = call i32 @fwrite(i8* %67, i32 1, i32 %69, i32* %70)
%72 = load i32*, i32** %8
%73 = call i32 @fclose(i32* %72)
br label %76
74: ; preds = %59
%75 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.9, i64 0, i64 0))
br label %76
76: ; preds = %74, %66
store i32 0, i32* %2
br label %77
77: ; preds = %76, %53, %28
%78 = load i32, i32* %2
ret i32 %78
}

LLVM IR (-O2):
@.str = [1 x i8] zeroinitializer
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [2 x i8] c" \00"
@.str.5 = [3 x i8] c"\0A\00\00"
@.str.6 = [42 x i8] c"/sys/devices/virtual/misc/pru_bridge/init\00"
@.str.7 = [2 x i8] c"w\00"
@str = [12 x i8] c"Init opened\00"
@str.10 = [20 x i8] c"Unable to open init\00"
@str.11 = [13 x i8] c"Invalid Size\00"
@str.12 = [25 x i8] c"Buffer size insufficient\00"
define i32 @pru_bridge_init(i32* nocapture %0) {
%2 = alloca [100 x i8]
%3 = alloca [11 x i8]
%4 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%5 = getelementptr inbounds [11 x i8], [11 x i8]* %3, i64 0, i64 0
%6 = call i32 @strcpy(i8* %4, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%7 = load i32, i32* %0
%8 = getelementptr inbounds i32, i32* %0, i64 1
%9 = load i32, i32* %8
%10 = getelementptr inbounds i32, i32* %0, i64 2
%11 = bitcast i32* %10 to <8 x i32>*
%12 = load <8 x i32>, <8 x i32>* %11
%13 = call i32 @llvm.vector.reduce.add.v8i32(<8 x i32> %12)
%14 = add nsw i32 %13, %9
%15 = add nsw i32 %14, %7
%16 = icmp sgt i32 %15, 11500
br i1 %16, label %23, label %17
17: ; preds = %1
%18 = call i32 @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %7)
%19 = call i32 @strcat(i8* %4, i8* %5)
%20 = call i32 @strcat(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%21 = load i32, i32* %0
%22 = icmp slt i32 %21, 0
br i1 %22, label %38, label %25
23: ; preds = %1
%24 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str.12, i64 0, i64 0))
br label %51
25: ; preds = %17, %29
%26 = phi i64 [ %27, %29 ], [ 0, %17 ]
%27 = add nuw nsw i64 %26, 1
%28 = icmp eq i64 %27, 10
br i1 %28, label %40, label %29
29: ; preds = %25
%30 = getelementptr inbounds i32, i32* %0, i64 %27
%31 = load i32, i32* %30
%32 = getelementptr inbounds i32, i32* %0, i64 %27
%33 = call i32 @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %31)
%34 = call i32 @strcat(i8* %4, i8* %5)
%35 = call i32 @strcat(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%36 = load i32, i32* %32
%37 = icmp slt i32 %36, 0
br i1 %37, label %38, label %25
38: ; preds = %29, %17
%39 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str.11, i64 0, i64 0))
br label %51
40: ; preds = %25
%41 = call i32 @strcat(i8* %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
%42 = call i32* @fopen(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
%43 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str, i64 0, i64 0))
%44 = icmp eq i32* %42, null
br i1 %44, label %49, label %45
45: ; preds = %40
%46 = call i32 @strlen(i8* %4)
%47 = call i32 @fwrite(i8* %4, i32 1, i32 %46, i32* %42)
%48 = call i32 @fclose(i32* %42)
br label %51
49: ; preds = %40
%50 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str.10, i64 0, i64 0))
br label %51
51: ; preds = %45, %49, %38, %23
%52 = phi i32 [ 1, %23 ], [ 1, %38 ], [ 0, %49 ], [ 0, %45 ]
ret i32 %52
}