#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 lcm(int, int);
int lcm_for_array(int *numbers) {
  int current_lcm = 0;
  static int firstFound = 0;
  for (int i = 0; i < 10; i++) {
    if (numbers[i] == 0)
      continue;
    if (firstFound == 0) {
      firstFound = numbers[i];
      continue;
    }
    if (current_lcm == 0) {
      current_lcm = lcm(firstFound, numbers[i]);
      continue;
    }
    current_lcm = lcm(current_lcm, numbers[i]);
  }
  return current_lcm;
}


x86 assembly (clang, -O0):
<lcm_for_array>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
cmpl   $0xa,-0x10(%rbp)
jge    11ba <lcm_for_array+0xaa>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
cmpl   $0x0,(%rax,%rcx,4)
jne    114b <lcm_for_array+0x3b>
jmp    11ac <lcm_for_array+0x9c>
cmpl   $0x0,0x2eda(%rip)
jne    116e <lcm_for_array+0x5e>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,0x2ec3(%rip)
jmp    11ac <lcm_for_array+0x9c>
cmpl   $0x0,-0xc(%rbp)
jne    1196 <lcm_for_array+0x86>
mov    0x2eae(%rip),%edi
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
call   1030 <lcm@plt>
mov    %eax,-0xc(%rbp)
jmp    11ac <lcm_for_array+0x9c>
mov    -0xc(%rbp),%edi
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
call   1030 <lcm@plt>
mov    %eax,-0xc(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    112a <lcm_for_array+0x1a>
mov    -0xc(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lcm_for_array>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
xor    %ebx,%ebx
xor    %eax,%eax
jmp    1130 <lcm_for_array+0x20>
nopl   (%rax)
mov    %esi,0x2f06(%rip)
add    $0x1,%rbx
cmp    $0xa,%rbx
je     114f <lcm_for_array+0x3f>
mov    (%r14,%rbx,4),%esi
test   %esi,%esi
je     1126 <lcm_for_array+0x16>
mov    0x2eee(%rip),%edi
test   %edi,%edi
je     1120 <lcm_for_array+0x10>
test   %eax,%eax
je     1148 <lcm_for_array+0x38>
mov    %eax,%edi
call   1030 <lcm@plt>
jmp    1126 <lcm_for_array+0x16>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
@lcm_for_array.firstFound = internal unnamed_addr global i32 0
define i32 @lcm_for_array(i32* nocapture %0) {
br label %3
2: ; preds = %19
ret i32 %20
3: ; preds = %1, %19
%4 = phi i64 [ 0, %1 ], [ %21, %19 ]
%5 = phi i32 [ 0, %1 ], [ %20, %19 ]
%6 = getelementptr inbounds i32, i32* %0, i64 %4
%7 = load i32, i32* %6
%8 = icmp eq i32 %7, 0
br i1 %8, label %19, label %9
9: ; preds = %3
%10 = load i32, i32* @lcm_for_array.firstFound
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %13
12: ; preds = %9
store i32 %7, i32* @lcm_for_array.firstFound
br label %19
13: ; preds = %9
%14 = icmp eq i32 %5, 0
br i1 %14, label %15, label %17
15: ; preds = %13
%16 = tail call i32 @lcm(i32 %10, i32 %7)
br label %19
17: ; preds = %13
%18 = tail call i32 @lcm(i32 %5, i32 %7)
br label %19
19: ; preds = %3, %17, %15, %12
%20 = phi i32 [ %5, %3 ], [ %5, %12 ], [ %16, %15 ], [ %18, %17 ]
%21 = add nuw nsw i64 %4, 1
%22 = icmp eq i64 %21, 10
br i1 %22, label %2, label %3
}