#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 can_chain(char **, int);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, int);
int main(int argc, char const *argv[]) {
  char **words = (char **)malloc(sizeof(char *) * 4);
  words[0] = "dg";
  words[1] = "gd";
  words[2] = "dn";
  words[3] = "nd";
  printf("%d\n", can_chain(words, 4));
  char **words2 = (char **)malloc(sizeof(char *) * 2);
  words2[0] = "ab";
  words2[1] = "cd";
  printf("%d\n", can_chain(words2, 2));
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x20,%edi
call   1040 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
lea    0xea1(%rip),%rcx
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rax
lea    0xe96(%rip),%rcx
mov    %rcx,0x8(%rax)
mov    -0x18(%rbp),%rax
lea    0xe8a(%rip),%rcx
mov    %rcx,0x10(%rax)
mov    -0x18(%rbp),%rax
lea    0xe7e(%rip),%rcx
mov    %rcx,0x18(%rax)
mov    -0x18(%rbp),%rdi
mov    $0x4,%esi
call   1050 <can_chain@plt>
mov    %eax,%esi
lea    0xe66(%rip),%rdi
call   1030 <printf@plt>
mov    $0x10,%edi
call   1040 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
lea    0xe4c(%rip),%rcx
mov    %rcx,(%rax)
mov    -0x20(%rbp),%rax
lea    0xe41(%rip),%rcx
mov    %rcx,0x8(%rax)
mov    -0x20(%rbp),%rdi
mov    $0x2,%esi
call   1050 <can_chain@plt>
mov    %eax,%esi
lea    0xe1f(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    $0x20,%edi
call   1040 <malloc@plt>
lea    0xebe(%rip),%rcx
mov    %rcx,(%rax)
lea    0xeb7(%rip),%rcx
mov    %rcx,0x8(%rax)
lea    0xeaf(%rip),%rcx
mov    %rcx,0x10(%rax)
lea    0xea7(%rip),%rcx
mov    %rcx,0x18(%rax)
mov    %rax,%rdi
mov    $0x4,%esi
call   1050 <can_chain@plt>
lea    0xe92(%rip),%rbx
mov    %rbx,%rdi
mov    %eax,%esi
call   1030 <printf@plt>
mov    $0x10,%edi
call   1040 <malloc@plt>
lea    0xe7b(%rip),%rcx
mov    %rcx,(%rax)
lea    0xe74(%rip),%rcx
mov    %rcx,0x8(%rax)
mov    %rax,%rdi
mov    $0x2,%esi
call   1050 <can_chain@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1030 <printf@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [3 x i8] c"dg\00"
@.str.1 = [3 x i8] c"gd\00"
@.str.2 = [3 x i8] c"dn\00"
@.str.3 = [3 x i8] c"nd\00"
@.str.4 = [4 x i8] c"%d\0A\00"
@.str.5 = [3 x i8] c"ab\00"
@.str.6 = [3 x i8] c"cd\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8**
%7 = alloca i8**
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = call i64 @malloc(i32 32)
%9 = inttoptr i64 %8 to i8**
store i8** %9, i8*** %6
%10 = load i8**, i8*** %6
%11 = getelementptr inbounds i8*, i8** %10, i64 0
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8** %11
%12 = load i8**, i8*** %6
%13 = getelementptr inbounds i8*, i8** %12, i64 1
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8** %13
%14 = load i8**, i8*** %6
%15 = getelementptr inbounds i8*, i8** %14, i64 2
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8** %15
%16 = load i8**, i8*** %6
%17 = getelementptr inbounds i8*, i8** %16, i64 3
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8** %17
%18 = load i8**, i8*** %6
%19 = call i32 @can_chain(i8** %18, i32 4)
%20 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %19)
%21 = call i64 @malloc(i32 16)
%22 = inttoptr i64 %21 to i8**
store i8** %22, i8*** %7
%23 = load i8**, i8*** %7
%24 = getelementptr inbounds i8*, i8** %23, i64 0
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i8** %24
%25 = load i8**, i8*** %7
%26 = getelementptr inbounds i8*, i8** %25, i64 1
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i8** %26
%27 = load i8**, i8*** %7
%28 = call i32 @can_chain(i8** %27, i32 2)
%29 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %28)
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"dg\00"
@.str.1 = [3 x i8] c"gd\00"
@.str.2 = [3 x i8] c"dn\00"
@.str.3 = [3 x i8] c"nd\00"
@.str.4 = [4 x i8] c"%d\0A\00"
@.str.5 = [3 x i8] c"ab\00"
@.str.6 = [3 x i8] c"cd\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i64 @malloc(i32 32)
%4 = inttoptr i64 %3 to i8**
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8** %4
%5 = getelementptr inbounds i8*, i8** %4, i64 1
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8** %5
%6 = getelementptr inbounds i8*, i8** %4, i64 2
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8** %6
%7 = getelementptr inbounds i8*, i8** %4, i64 3
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8** %7
%8 = tail call i32 @can_chain(i8** %4, i32 4)
%9 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %8)
%10 = tail call i64 @malloc(i32 16)
%11 = inttoptr i64 %10 to i8**
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i8** %11
%12 = getelementptr inbounds i8*, i8** %11, i64 1
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i8** %12
%13 = tail call i32 @can_chain(i8** %11, i32 2)
%14 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %13)
ret i32 0
}