#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*/ bar(char *);
int foo(unsigned short l) {
  char c[10000] = {};
  unsigned short nchar = 9999;
  if (nchar <= l)
    return -1;
  while (nchar-- != l) {
    c[nchar] = 'A';
  }
  bar(c);
  return 0;
}


x86 assembly (clang, -O0):
<foo>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2730,%rsp
mov    %di,%ax
mov    %ax,-0x6(%rbp)
lea    -0x2720(%rbp),%rdi
xor    %esi,%esi
mov    $0x2710,%edx
call   1040 <memset@plt>
movw   $0x270f,-0x2722(%rbp)
0f 27
movzwl -0x2722(%rbp),%eax
movzwl -0x6(%rbp),%ecx
cmp    %ecx,%eax
jg     116d <foo+0x4d>
movl   $0xffffffff,-0x4(%rbp)
jmp    11bd <foo+0x9d>
jmp    1172 <foo+0x52>
mov    -0x2722(%rbp),%ax
mov    %ax,%cx
add    $0xffff,%cx
mov    %cx,-0x2722(%rbp)
movzwl %ax,%eax
movzwl -0x6(%rbp),%ecx
cmp    %ecx,%eax
je     11aa <foo+0x8a>
movzwl -0x2722(%rbp),%eax
movb   $0x41,-0x2720(%rbp,%rax,1)
41
jmp    1172 <foo+0x52>
lea    -0x2720(%rbp),%rdi
call   1030 <bar@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x2730,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<foo>:
push   %rbp
push   %rbx
sub    $0x2718,%rsp
mov    %edi,%ebp
mov    %rsp,%rbx
mov    $0x2710,%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1040 <memset@plt>
mov    $0xffffffff,%eax
cmp    $0x270e,%ebp
ja     1179 <foo+0x59>
mov    $0x270e,%eax
sub    %ebp,%eax
movzwl %ax,%edx
mov    %rbx,%rdi
sub    %rdx,%rdi
add    $0x270e,%rdi
add    $0x1,%rdx
mov    $0x41,%esi
call   1040 <memset@plt>
mov    %rbx,%rdi
call   1030 <bar@plt>
xor    %eax,%eax
add    $0x2718,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @foo(i16 zeroext %0) {
%2 = alloca i32
%3 = alloca i16
%4 = alloca [10000 x i8]
%5 = alloca i16
store i16 %0, i16* %3
%6 = bitcast [10000 x i8]* %4 to i8*
store i16 9999, i16* %5
%7 = load i16, i16* %5
%8 = zext i16 %7 to i32
%9 = load i16, i16* %3
%10 = zext i16 %9 to i32
%11 = icmp sle i32 %8, %10
br i1 %11, label %12, label %13
12: ; preds = %1
store i32 -1, i32* %2
br label %28
13: ; preds = %1
br label %14
14: ; preds = %21, %13
%15 = load i16, i16* %5
%16 = add i16 %15, -1
store i16 %16, i16* %5
%17 = zext i16 %15 to i32
%18 = load i16, i16* %3
%19 = zext i16 %18 to i32
%20 = icmp ne i32 %17, %19
br i1 %20, label %21, label %25
21: ; preds = %14
%22 = load i16, i16* %5
%23 = zext i16 %22 to i64
%24 = getelementptr inbounds [10000 x i8], [10000 x i8]* %4, i64 0, i64 %23
store i8 65, i8* %24
br label %14
25: ; preds = %14
%26 = getelementptr inbounds [10000 x i8], [10000 x i8]* %4, i64 0, i64 0
%27 = call i32 @bar(i8* %26)
store i32 0, i32* %2
br label %28
28: ; preds = %25, %12
%29 = load i32, i32* %2
ret i32 %29
}

LLVM IR (-O2):
define i32 @foo(i16 zeroext %0) {
%2 = alloca [10000 x i8]
%3 = getelementptr inbounds [10000 x i8], [10000 x i8]* %2, i64 0, i64 0
%4 = icmp ugt i16 %0, 9998
br i1 %4, label %12, label %5
5: ; preds = %1
%6 = sub nuw nsw i16 9998, %0
%7 = zext i16 %6 to i64
%8 = sub nuw nsw i64 9998, %7
%9 = getelementptr [10000 x i8], [10000 x i8]* %2, i64 0, i64 %8
%10 = add nuw nsw i64 %7, 1
%11 = call i32 @bar(i8* %3)
br label %12
12: ; preds = %1, %5
%13 = phi i32 [ 0, %5 ], [ -1, %1 ]
ret i32 %13
}