#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 */
struct triple {
  int dummy;
};
struct compile_state {
  int dummy;
};

/* Variables and functions */
struct triple **triple_iter(struct compile_state *state, size_t count,
                            struct triple **vector, struct triple *ins,
                            struct triple **last) {
  struct triple **ret;
  ret = 0;
  if (count) {
    if (!last) {
      ret = vector;
    } else if ((last >= vector) && (last < (vector + count - 1))) {
      ret = last + 1;
    }
  }
  return ret;
}


x86 assembly (clang, -O0):
<triple_iter>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1187 <triple_iter+0x87>
cmpq   $0x0,-0x28(%rbp)
jne    1143 <triple_iter+0x43>
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
jmp    1182 <triple_iter+0x82>
mov    -0x28(%rbp),%rax
cmp    -0x18(%rbp),%rax
jb     117d <triple_iter+0x7d>
mov    -0x28(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    -0x10(%rbp),%rdx
shl    $0x3,%rdx
add    %rdx,%rcx
add    $0xfffffffffffffff8,%rcx
cmp    %rcx,%rax
jae    117d <triple_iter+0x7d>
mov    -0x28(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x30(%rbp)
jmp    1182 <triple_iter+0x82>
jmp    1187 <triple_iter+0x87>
mov    -0x30(%rbp),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<triple_iter>:
test   %rsi,%rsi
je     112d <triple_iter+0x2d>
mov    %rdx,%rax
test   %r8,%r8
je     112c <triple_iter+0x2c>
lea    (%rax,%rsi,8),%rcx
add    $0xfffffffffffffff8,%rcx
lea    0x8(%r8),%rdx
xor    %esi,%esi
cmp    %r8,%rcx
cmovbe %rsi,%rdx
cmp    %rax,%r8
cmovb  %rsi,%rdx
mov    %rdx,%rax
ret
xor    %eax,%eax
ret

LLVM IR (-O0):
%struct.compile_state = type { i32 }
%struct.triple = type { i32 }
define %struct.triple** @triple_iter(%struct.compile_state* %0, i64 %1, %struct.triple** %2, %struct.triple* %3, %struct.triple** %4) {
%6 = alloca %struct.compile_state*
%7 = alloca i64
%8 = alloca %struct.triple**
%9 = alloca %struct.triple*
%10 = alloca %struct.triple**
%11 = alloca %struct.triple**
store %struct.compile_state* %0, %struct.compile_state** %6
store i64 %1, i64* %7
store %struct.triple** %2, %struct.triple*** %8
store %struct.triple* %3, %struct.triple** %9
store %struct.triple** %4, %struct.triple*** %10
store %struct.triple** null, %struct.triple*** %11
%12 = load i64, i64* %7
%13 = icmp ne i64 %12, 0
br i1 %13, label %14, label %35
14: ; preds = %5
%15 = load %struct.triple**, %struct.triple*** %10
%16 = icmp ne %struct.triple** %15, null
br i1 %16, label %19, label %17
17: ; preds = %14
%18 = load %struct.triple**, %struct.triple*** %8
store %struct.triple** %18, %struct.triple*** %11
br label %34
19: ; preds = %14
%20 = load %struct.triple**, %struct.triple*** %10
%21 = load %struct.triple**, %struct.triple*** %8
%22 = icmp uge %struct.triple** %20, %21
br i1 %22, label %23, label %33
23: ; preds = %19
%24 = load %struct.triple**, %struct.triple*** %10
%25 = load %struct.triple**, %struct.triple*** %8
%26 = load i64, i64* %7
%27 = getelementptr inbounds %struct.triple*, %struct.triple** %25, i64 %26
%28 = getelementptr inbounds %struct.triple*, %struct.triple** %27, i64 -1
%29 = icmp ult %struct.triple** %24, %28
br i1 %29, label %30, label %33
30: ; preds = %23
%31 = load %struct.triple**, %struct.triple*** %10
%32 = getelementptr inbounds %struct.triple*, %struct.triple** %31, i64 1
store %struct.triple** %32, %struct.triple*** %11
br label %33
33: ; preds = %30, %23, %19
br label %34
34: ; preds = %33, %17
br label %35
35: ; preds = %34, %5
%36 = load %struct.triple**, %struct.triple*** %11
ret %struct.triple** %36
}

LLVM IR (-O2):
%struct.compile_state = type { i32 }
%struct.triple = type { i32 }
define %struct.triple** @triple_iter(%struct.compile_state* nocapture readnone %0, i64 %1, %struct.triple** readnone %2, %struct.triple* nocapture readnone %3, %struct.triple** readnone %4) {
%6 = icmp eq i64 %1, 0
br i1 %6, label %17, label %7
7: ; preds = %5
%8 = icmp eq %struct.triple** %4, null
br i1 %8, label %17, label %9
9: ; preds = %7
%10 = icmp uge %struct.triple** %4, %2
%11 = getelementptr inbounds %struct.triple*, %struct.triple** %2, i64 %1
%12 = getelementptr inbounds %struct.triple*, %struct.triple** %11, i64 -1
%13 = icmp ugt %struct.triple** %12, %4
%14 = select i1 %10, i1 %13, i1 false
%15 = getelementptr inbounds %struct.triple*, %struct.triple** %4, i64 1
%16 = select i1 %14, %struct.triple** %15, %struct.triple** null
br label %17
17: ; preds = %9, %7, %5
%18 = phi %struct.triple** [ null, %5 ], [ %2, %7 ], [ %16, %9 ]
ret %struct.triple** %18
}