#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*/ ft_putendl(char *);
int init_protect(void **ptr, size_t size, int flag) {
  int i;
  i = 0;
  if (flag == 1) {
    while (i < (int)size)
      if (!ptr[i++])
        return (0);
  } else
    ft_putendl("error");
  return (1);
}


x86 assembly (clang, -O0):
<init_protect>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
cmpl   $0x1,-0x1c(%rbp)
jne    117b <init_protect+0x6b>
jmp    1139 <init_protect+0x29>
mov    -0x20(%rbp),%eax
mov    -0x18(%rbp),%rcx
cmp    %ecx,%eax
jge    1176 <init_protect+0x66>
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x20(%rbp)
movslq %ecx,%rcx
cmpq   $0x0,(%rax,%rcx,8)
jne    1171 <init_protect+0x61>
movl   $0x0,-0x4(%rbp)
jmp    118e <init_protect+0x7e>
jmp    1139 <init_protect+0x29>
jmp    1187 <init_protect+0x77>
lea    0xe7e(%rip),%rdi
call   1030 <ft_putendl@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<init_protect>:
push   %rax
cmp    $0x1,%edx
jne    1134 <init_protect+0x24>
xor    %eax,%eax
test   %esi,%esi
cmovle %eax,%esi
nopl   (%rax)
cmp    %rax,%rsi
je     1140 <init_protect+0x30>
cmpq   $0x0,(%rdi,%rax,8)
lea    0x1(%rax),%rax
jne    1120 <init_protect+0x10>
xor    %eax,%eax
pop    %rcx
ret
lea    0xec5(%rip),%rdi
call   1030 <ft_putendl@plt>
mov    $0x1,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [6 x i8] c"error\00"
define i32 @init_protect(i8** %0, i64 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
%7 = alloca i32
%8 = alloca i32
store i8** %0, i8*** %5
store i64 %1, i64* %6
store i32 %2, i32* %7
store i32 0, i32* %8
%9 = load i32, i32* %7
%10 = icmp eq i32 %9, 1
br i1 %10, label %11, label %28
11: ; preds = %3
br label %12
12: ; preds = %26, %11
%13 = load i32, i32* %8
%14 = load i64, i64* %6
%15 = trunc i64 %14 to i32
%16 = icmp slt i32 %13, %15
br i1 %16, label %17, label %27
17: ; preds = %12
%18 = load i8**, i8*** %5
%19 = load i32, i32* %8
%20 = add nsw i32 %19, 1
store i32 %20, i32* %8
%21 = sext i32 %19 to i64
%22 = getelementptr inbounds i8*, i8** %18, i64 %21
%23 = load i8*, i8** %22
%24 = icmp ne i8* %23, null
br i1 %24, label %26, label %25
25: ; preds = %17
store i32 0, i32* %4
br label %31
26: ; preds = %17
br label %12
27: ; preds = %12
br label %30
28: ; preds = %3
%29 = call i32 @ft_putendl(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
br label %30
30: ; preds = %28, %27
store i32 1, i32* %4
br label %31
31: ; preds = %30, %25
%32 = load i32, i32* %4
ret i32 %32
}

LLVM IR (-O2):
@.str = [6 x i8] c"error\00"
define i32 @init_protect(i8** nocapture %0, i64 %1, i32 %2) {
%4 = icmp eq i32 %2, 1
br i1 %4, label %5, label %17
5: ; preds = %3
%6 = trunc i64 %1 to i32
%7 = call i32 @llvm.smax.i32(i32 %6, i32 0)
%8 = zext i32 %7 to i64
br label %9
9: ; preds = %5, %12
%10 = phi i64 [ 0, %5 ], [ %13, %12 ]
%11 = icmp eq i64 %10, %8
br i1 %11, label %19, label %12
12: ; preds = %9
%13 = add nuw nsw i64 %10, 1
%14 = getelementptr inbounds i8*, i8** %0, i64 %10
%15 = load i8*, i8** %14
%16 = icmp eq i8* %15, null
br i1 %16, label %19, label %9
17: ; preds = %3
%18 = tail call i32 @ft_putendl(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
br label %19
19: ; preds = %9, %12, %17
%20 = phi i32 [ 1, %17 ], [ 1, %9 ], [ 0, %12 ]
ret i32 %20
}