#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 open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int strlen(char *);
int write(int, char *, int);
int __name(char *data) {
  int fd, ret;
  if (strlen(data) > 11) {
    printf("(__name) Error: max nr of allowed characters are 12!\n");
    return 1;
  }
  fd = open("/dev/resch", O_RDWR);
  if (fd < 0) {
    printf("(__name) Error: failed to access the module!\n");
    return 1;
  }
  ret = write(fd, data, sizeof(char) * strlen(data));
  close(fd);
  return ret;
}


x86 assembly (clang, -O0):
<__name>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0xb,%eax
jle    1186 <__name+0x36>
lea    0xe8b(%rip),%rdi
call   1050 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    11fc <__name+0xac>
mov    0x2e5b(%rip),%rax
mov    (%rax),%esi
lea    0xea0(%rip),%rdi
call   1070 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    11c0 <__name+0x70>
lea    0xe92(%rip),%rdi
call   1050 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    11fc <__name+0xac>
mov    -0x14(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x24(%rbp),%edi
mov    -0x20(%rbp),%rsi
cltq
shl    $0x0,%rax
mov    %eax,%edx
call   1030 <write@plt>
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%edi
call   1060 <close@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<__name>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
call   1050 <strlen@plt>
cmp    $0xc,%eax
jl     1169 <__name+0x19>
lea    0xed1(%rip),%rdi
jmp    11ac <__name+0x5c>
mov    0x2e78(%rip),%rax
mov    (%rax),%esi
lea    0xe87(%rip),%rdi
call   1070 <open@plt>
test   %eax,%eax
js     11a5 <__name+0x55>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1040 <write@plt>
mov    %eax,%ebx
mov    %ebp,%edi
call   1060 <close@plt>
mov    %ebx,%eax
jmp    11b6 <__name+0x66>
lea    0xe5f(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [54 x i8] c"(__name) Error: max nr of allowed characters are 12!\0A\00"
@.str.1 = [11 x i8] c"/dev/resch\00"
@O_RDWR = global i32 0
@.str.2 = [46 x i8] c"(__name) Error: failed to access the module!\0A\00"
define i32 @__name(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = call i32 @strlen(i8* %6)
%8 = icmp sgt i32 %7, 11
br i1 %8, label %9, label %11
9: ; preds = %1
%10 = call i32 @printf(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %2
br label %30
11: ; preds = %1
%12 = load i32, i32* @O_RDWR
%13 = call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 %12)
store i32 %13, i32* %4
%14 = load i32, i32* %4
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %11
%17 = call i32 @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %2
br label %30
18: ; preds = %11
%19 = load i32, i32* %4
%20 = load i8*, i8** %3
%21 = load i8*, i8** %3
%22 = call i32 @strlen(i8* %21)
%23 = sext i32 %22 to i64
%24 = mul i64 1, %23
%25 = trunc i64 %24 to i32
%26 = call i32 @write(i32 %19, i8* %20, i32 %25)
store i32 %26, i32* %5
%27 = load i32, i32* %4
%28 = call i32 @close(i32 %27)
%29 = load i32, i32* %5
store i32 %29, i32* %2
br label %30
30: ; preds = %18, %16, %9
%31 = load i32, i32* %2
ret i32 %31
}

LLVM IR (-O2):
@.str.1 = [11 x i8] c"/dev/resch\00"
@O_RDWR = global i32 0
@str = [45 x i8] c"(__name) Error: failed to access the module!\00"
@str.3 = [53 x i8] c"(__name) Error: max nr of allowed characters are 12!\00"
define i32 @__name(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = icmp sgt i32 %2, 11
br i1 %3, label %4, label %6
4: ; preds = %1
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([53 x i8], [53 x i8]* @str.3, i64 0, i64 0))
br label %16
6: ; preds = %1
%7 = load i32, i32* @O_RDWR
%8 = tail call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 %7)
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %6
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @str, i64 0, i64 0))
br label %16
12: ; preds = %6
%13 = tail call i32 @strlen(i8* %0)
%14 = tail call i32 @write(i32 %8, i8* %0, i32 %13)
%15 = tail call i32 @close(i32 %8)
br label %16
16: ; preds = %12, %10, %4
%17 = phi i32 [ 1, %4 ], [ 1, %10 ], [ %14, %12 ]
ret i32 %17
}