#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 */
scalar_t__ bar(int *, int);
int foo(int n, int b[], int size) {
  int a[n], i;
  for (i = 0; i < size; i++) {
    a[i] = b[i];
  }
  if (bar(a, size)) {
    return size;
  }
  return i;
}


x86 assembly (clang, -O0):
<foo>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
lea    0xf(,%rax,4),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x38(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1180 <foo+0x70>
mov    -0x38(%rbp),%rax
mov    -0x10(%rbp),%rcx
movslq -0x2c(%rbp),%rdx
mov    (%rcx,%rdx,4),%edx
movslq -0x2c(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1150 <foo+0x40>
mov    -0x38(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1030 <bar@plt>
cmp    $0x0,%rax
je     11a8 <foo+0x98>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x30(%rbp)
jmp    11b5 <foo+0xa5>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x30(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<foo>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%r14d
mov    %edi,%eax
mov    %rsp,%rbx
lea    0xf(,%rax,4),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
test   %edx,%edx
jle    115c <foo+0x3c>
mov    %r14d,%edx
shl    $0x2,%rdx
mov    %rbx,%rdi
call   1040 <memcpy@plt>
mov    %r14d,%r15d
jmp    115f <foo+0x3f>
xor    %r15d,%r15d
mov    %rbx,%rdi
mov    %r14d,%esi
call   1030 <bar@plt>
test   %rax,%rax
cmovne %r14d,%r15d
mov    %r15d,%eax
lea    -0x18(%rbp),%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @foo(i32 %0, i32* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i32
%11 = alloca i32
store i32 %0, i32* %5
store i32* %1, i32** %6
store i32 %2, i32* %7
%12 = load i32, i32* %5
%13 = zext i32 %12 to i64
%14 = call i8* @llvm.stacksave()
store i8* %14, i8** %8
%15 = alloca i32, i64 %13
store i64 %13, i64* %9
store i32 0, i32* %10
br label %16
16: ; preds = %29, %3
%17 = load i32, i32* %10
%18 = load i32, i32* %7
%19 = icmp slt i32 %17, %18
br i1 %19, label %20, label %32
20: ; preds = %16
%21 = load i32*, i32** %6
%22 = load i32, i32* %10
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i32, i32* %21, i64 %23
%25 = load i32, i32* %24
%26 = load i32, i32* %10
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i32, i32* %15, i64 %27
store i32 %25, i32* %28
br label %29
29: ; preds = %20
%30 = load i32, i32* %10
%31 = add nsw i32 %30, 1
store i32 %31, i32* %10
br label %16
32: ; preds = %16
%33 = load i32, i32* %7
%34 = call i64 @bar(i32* %15, i32 %33)
%35 = icmp ne i64 %34, 0
br i1 %35, label %36, label %38
36: ; preds = %32
%37 = load i32, i32* %7
store i32 %37, i32* %4
store i32 1, i32* %11
br label %40
38: ; preds = %32
%39 = load i32, i32* %10
store i32 %39, i32* %4
store i32 1, i32* %11
br label %40
40: ; preds = %38, %36
%41 = load i8*, i8** %8
%42 = load i32, i32* %4
ret i32 %42
}

LLVM IR (-O2):
define i32 @foo(i32 %0, i32* nocapture %1, i32 %2) {
%4 = zext i32 %0 to i64
%5 = alloca i32, i64 %4
%6 = icmp sgt i32 %2, 0
br i1 %6, label %7, label %12
7: ; preds = %3
%8 = bitcast i32* %5 to i8*
%9 = bitcast i32* %1 to i8*
%10 = zext i32 %2 to i64
%11 = shl nuw nsw i64 %10, 2
br label %12
12: ; preds = %7, %3
%13 = phi i32 [ 0, %3 ], [ %2, %7 ]
%14 = call i64 @bar(i32* %5, i32 %2)
%15 = icmp eq i64 %14, 0
%16 = select i1 %15, i32 %13, i32 %2
ret i32 %16
}