#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 */
typedef int /*<<< orphan*/ swirr;
struct gpiohandle_data {
  int *values;
};

/* Variables and functions */
int /*<<< orphan*/ GPIOHANDLE_REQUEST_OUTPUT;
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int gpiotools_get_values(int, struct gpiohandle_data *);
int /*<<< orphan*/ gpiotools_release_linehandle(int);
int gpiotools_request_linehandle(char const *, unsigned int *, int,
                                 int /*<<< orphan*/, struct gpiohandle_data *,
                                 char *);
int gpiotools_set_values(int, struct gpiohandle_data *);
int /*<<< orphan*/ memset(int **, int /*<<< orphan*/, int);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ stdout;
int hammer_device(const char *device_name, unsigned int *lines, int nlines,
                  unsigned int loops) {
  struct gpiohandle_data data;
  char swirr[] = "-\\|/";
  int fd;
  int ret;
  int i, j;
  unsigned int iteration = 0;
  memset(&data.values, 0, sizeof(data.values));
  ret = gpiotools_request_linehandle(device_name, lines, nlines,
                                     GPIOHANDLE_REQUEST_OUTPUT, &data,
                                     "gpio-hammer");
  if (ret < 0)
    goto exit_error;
  else
    fd = ret;
  ret = gpiotools_get_values(fd, &data);
  if (ret < 0)
    goto exit_close_error;
  fprintf(stdout, "Hammer lines [");
  for (i = 0; i < nlines; i++) {
    fprintf(stdout, "%d", lines[i]);
    if (i != (nlines - 1))
      fprintf(stdout, ", ");
  }
  fprintf(stdout, "] on %s, initial states: [", device_name);
  for (i = 0; i < nlines; i++) {
    fprintf(stdout, "%d", data.values[i]);
    if (i != (nlines - 1))
      fprintf(stdout, ", ");
  }
  fprintf(stdout, "]\n");
  j = 0;
  while (1) {
    for (i = 0; i < nlines; i++)
      data.values[i] = !data.values[i];
    ret = gpiotools_set_values(fd, &data);
    if (ret < 0)
      goto exit_close_error;
    ret = gpiotools_get_values(fd, &data);
    if (ret < 0)
      goto exit_close_error;
    fprintf(stdout, "[%c] ", swirr[j]);
    j++;
    if (j == sizeof(swirr) - 1)
      j = 0;
    fprintf(stdout, "[");
    for (i = 0; i < nlines; i++) {
      fprintf(stdout, "%d: %d", lines[i], data.values[i]);
      if (i != (nlines - 1))
        fprintf(stdout, ", ");
    }
    fprintf(stdout, "]\r");
    fflush(stdout);
    sleep(1);
    iteration++;
    if (loops && iteration == loops)
      break;
  }
  fprintf(stdout, "\n");
  ret = 0;
exit_close_error:
  gpiotools_release_linehandle(fd);
exit_error:
  return ret;
}


x86 assembly (clang, -O0):
<hammer_device>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    0xe64(%rip),%eax
mov    %eax,-0x25(%rbp)
mov    0xe5f(%rip),%al
mov    %al,-0x21(%rbp)
movl   $0x0,-0x3c(%rbp)
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1030 <memset@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
mov    0x2e17(%rip),%rax
mov    (%rax),%ecx
lea    -0x20(%rbp),%r8
lea    0xe27(%rip),%r9
call   1090 <gpiotools_request_linehandle@plt>
mov    %eax,-0x30(%rbp)
cmpl   $0x0,-0x30(%rbp)
jge    11f5 <hammer_device+0x75>
jmp    1515 <hammer_device+0x395>
mov    -0x30(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%edi
lea    -0x20(%rbp),%rsi
call   1080 <gpiotools_get_values@plt>
mov    %eax,-0x30(%rbp)
cmpl   $0x0,-0x30(%rbp)
jge    1219 <hammer_device+0x99>
jmp    150d <hammer_device+0x38d>
mov    0x2db8(%rip),%rax
mov    (%rax),%edi
lea    0xde8(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    12a0 <hammer_device+0x120>
mov    0x2d8e(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
movslq -0x34(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
lea    0xded(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x34(%rbp),%eax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
je     128d <hammer_device+0x10d>
mov    0x2d5b(%rip),%rax
mov    (%rax),%edi
lea    0xd9a(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
jmp    1292 <hammer_device+0x112>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1237 <hammer_device+0xb7>
mov    0x2d31(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xd6f(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    132b <hammer_device+0x1ab>
mov    0x2d03(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rax
movslq -0x34(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
lea    0xd62(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x34(%rbp),%eax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
je     1318 <hammer_device+0x198>
mov    0x2cd0(%rip),%rax
mov    (%rax),%edi
lea    0xd0f(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
jmp    131d <hammer_device+0x19d>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    12c2 <hammer_device+0x142>
mov    0x2ca6(%rip),%rax
mov    (%rax),%edi
lea    0xd03(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0x0,-0x38(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    138b <hammer_device+0x20b>
mov    -0x20(%rbp),%rax
movslq -0x34(%rbp),%rcx
cmpl   $0x0,(%rax,%rcx,4)
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%edx
mov    -0x20(%rbp),%rax
movslq -0x34(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1350 <hammer_device+0x1d0>
mov    -0x2c(%rbp),%edi
lea    -0x20(%rbp),%rsi
call   1070 <gpiotools_set_values@plt>
mov    %eax,-0x30(%rbp)
cmpl   $0x0,-0x30(%rbp)
jge    13a9 <hammer_device+0x229>
jmp    150d <hammer_device+0x38d>
mov    -0x2c(%rbp),%edi
lea    -0x20(%rbp),%rsi
call   1080 <gpiotools_get_values@plt>
mov    %eax,-0x30(%rbp)
cmpl   $0x0,-0x30(%rbp)
jge    13c7 <hammer_device+0x247>
jmp    150d <hammer_device+0x38d>
mov    0x2c0a(%rip),%rax
mov    (%rax),%edi
movslq -0x38(%rbp),%rax
movsbl -0x25(%rbp,%rax,1),%edx
lea    0xc61(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
movslq -0x38(%rbp),%rax
cmp    $0x4,%rax
jne    1405 <hammer_device+0x285>
movl   $0x0,-0x38(%rbp)
mov    0x2bcc(%rip),%rax
mov    (%rax),%edi
lea    0xc27(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1497 <hammer_device+0x317>
mov    0x2ba2(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
movslq -0x34(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
mov    -0x20(%rbp),%rax
movslq -0x34(%rbp),%rcx
mov    (%rax,%rcx,4),%ecx
lea    0xbf2(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x34(%rbp),%eax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
je     1484 <hammer_device+0x304>
mov    0x2b64(%rip),%rax
mov    (%rax),%edi
lea    0xba3(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
jmp    1489 <hammer_device+0x309>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1423 <hammer_device+0x2a3>
mov    0x2b3a(%rip),%rax
mov    (%rax),%edi
lea    0xba7(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    0x2b23(%rip),%rax
mov    (%rax),%edi
call   1060 <fflush@plt>
mov    $0x1,%edi
call   10a0 <sleep@plt>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
cmpl   $0x0,-0x18(%rbp)
je     14ea <hammer_device+0x36a>
mov    -0x3c(%rbp),%eax
cmp    -0x18(%rbp),%eax
jne    14ea <hammer_device+0x36a>
jmp    14ef <hammer_device+0x36f>
jmp    1349 <hammer_device+0x1c9>
mov    0x2ae2(%rip),%rax
mov    (%rax),%edi
lea    0xb40(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0x0,-0x30(%rbp)
mov    -0x2c(%rbp),%edi
call   1050 <gpiotools_release_linehandle@plt>
mov    -0x30(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hammer_device>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x58,%rsp
mov    %ecx,0x1c(%rsp)
mov    %edx,%ebp
mov    %rsi,%r12
mov    %rdi,%rbx
lea    0x8(%rsp),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1030 <memset@plt>
mov    0x2e33(%rip),%rax
mov    (%rax),%ecx
lea    0xe47(%rip),%r9
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %ebp,%edx
mov    %r14,%r8
call   1090 <gpiotools_request_linehandle@plt>
test   %eax,%eax
js     15dd <hammer_device+0x45d>
mov    %rbp,0x20(%rsp)
lea    0x8(%rsp),%rsi
mov    %eax,%ebp
mov    %eax,%edi
call   1080 <gpiotools_get_values@plt>
test   %eax,%eax
js     12e4 <hammer_device+0x164>
mov    %rbx,0x10(%rsp)
mov    %r12,0x30(%rsp)
mov    0x2dd6(%rip),%r12
mov    (%r12),%edi
lea    0xe04(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    0x20(%rsp),%r15
mov    %r15d,%r13d
test   %r15d,%r15d
mov    %ebp,0x4(%rsp)
jle    12ee <hammer_device+0x16e>
lea    -0x1(%r15),%r14d
lea    0xe17(%rip),%rbx
lea    0xde5(%rip),%rbp
xor    %r15d,%r15d
jmp    1249 <hammer_device+0xc9>
add    $0x1,%r15
cmp    %r15,%r13
je     1275 <hammer_device+0xf5>
mov    (%r12),%edi
mov    0x30(%rsp),%rax
mov    (%rax,%r15,4),%edx
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
cmp    %r15,%r14
je     1240 <hammer_device+0xc0>
mov    (%r12),%edi
mov    %rbp,%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
jmp    1240 <hammer_device+0xc0>
mov    (%r12),%edi
lea    0xda3(%rip),%rsi
mov    0x10(%rsp),%rdx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    0x20(%rsp),%r15
test   %r15d,%r15d
jle    1305 <hammer_device+0x185>
lea    0xdae(%rip),%r15
lea    0xd7c(%rip),%rbp
xor    %ebx,%ebx
jmp    12b9 <hammer_device+0x139>
nopl   0x0(%rax,%rax,1)
add    $0x1,%rbx
cmp    %rbx,%r13
je     1310 <hammer_device+0x190>
mov    (%r12),%edi
mov    0x8(%rsp),%rax
mov    (%rax,%rbx,4),%edx
mov    %r15,%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
cmp    %rbx,%r14
je     12b0 <hammer_device+0x130>
mov    (%r12),%edi
mov    %rbp,%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
jmp    12b0 <hammer_device+0x130>
mov    %eax,%r15d
mov    %ebp,%edi
jmp    15d5 <hammer_device+0x455>
mov    (%r12),%edi
lea    0xd2a(%rip),%rsi
mov    0x10(%rsp),%rdx
xor    %eax,%eax
call   1040 <fprintf@plt>
lea    -0x1(%r15),%r14d
mov    0x4(%rsp),%r12d
jmp    131a <hammer_device+0x19a>
mov    0x4(%rsp),%r12d
mov    0x20(%rsp),%r15
mov    0x2cb7(%rip),%rax
mov    (%rax),%edi
lea    0xd14(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    %r13d,%eax
and    $0xfffffff8,%eax
mov    %rax,0x50(%rsp)
add    $0xfffffffffffffff8,%rax
mov    %rax,0x48(%rsp)
mov    %rax,%rcx
shr    $0x3,%rcx
add    $0x1,%rcx
mov    %rcx,%rax
mov    %rcx,0x40(%rsp)
and    $0xfffffffffffffffe,%rcx
mov    %rcx,0x38(%rsp)
pxor   %xmm4,%xmm4
lea    0x8(%rsp),%rbx
xor    %eax,%eax
mov    %rax,0x10(%rsp)
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
test   %r15d,%r15d
jle    1475 <hammer_device+0x2f5>
mov    0x8(%rsp),%rax
cmp    $0x8,%r15d
jae    13a0 <hammer_device+0x220>
xor    %ecx,%ecx
jmp    1460 <hammer_device+0x2e0>
nopl   0x0(%rax,%rax,1)
cmpq   $0x0,0x48(%rsp)
je     15a1 <hammer_device+0x421>
mov    0x38(%rsp),%rdx
xor    %ecx,%ecx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movdqu (%rax,%rcx,4),%xmm0
movdqu 0x10(%rax,%rcx,4),%xmm1
movdqu 0x20(%rax,%rcx,4),%xmm2
movdqu 0x30(%rax,%rcx,4),%xmm3
pcmpeqd %xmm4,%xmm0
psrld  $0x1f,%xmm0
pcmpeqd %xmm4,%xmm1
psrld  $0x1f,%xmm1
movdqu %xmm0,(%rax,%rcx,4)
movdqu %xmm1,0x10(%rax,%rcx,4)
pcmpeqd %xmm4,%xmm2
psrld  $0x1f,%xmm2
pcmpeqd %xmm4,%xmm3
psrld  $0x1f,%xmm3
movdqu %xmm2,0x20(%rax,%rcx,4)
movdqu %xmm3,0x30(%rax,%rcx,4)
add    $0x10,%rcx
add    $0xfffffffffffffffe,%rdx
jne    13c0 <hammer_device+0x240>
testb  $0x1,0x40(%rsp)
je     144b <hammer_device+0x2cb>
movdqu (%rax,%rcx,4),%xmm0
movdqu 0x10(%rax,%rcx,4),%xmm1
pcmpeqd %xmm4,%xmm0
psrld  $0x1f,%xmm0
pcmpeqd %xmm4,%xmm1
psrld  $0x1f,%xmm1
movdqu %xmm0,(%rax,%rcx,4)
movdqu %xmm1,0x10(%rax,%rcx,4)
mov    0x50(%rsp),%rdx
mov    %rdx,%rcx
cmp    %r13,%rdx
je     1475 <hammer_device+0x2f5>
nopl   0x0(%rax,%rax,1)
xor    %edx,%edx
cmpl   $0x0,(%rax,%rcx,4)
sete   %dl
mov    %edx,(%rax,%rcx,4)
add    $0x1,%rcx
cmp    %rcx,%r13
jne    1460 <hammer_device+0x2e0>
mov    %r12d,%edi
mov    %rbx,%rsi
call   1070 <gpiotools_set_values@plt>
test   %eax,%eax
js     15b3 <hammer_device+0x433>
mov    %r12d,%edi
mov    %rbx,%rsi
call   1080 <gpiotools_get_values@plt>
test   %eax,%eax
js     15b3 <hammer_device+0x433>
mov    %ebp,0x2c(%rsp)
mov    0x2b32(%rip),%r12
mov    (%r12),%edi
mov    0x10(%rsp),%rbx
movslq %ebx,%rbx
lea    0xb47(%rip),%rax
movsbl (%rbx,%rax,1),%edx
lea    0xb7d(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
add    $0x1,%ebx
cmp    $0x4,%ebx
mov    $0x0,%eax
cmove  %eax,%ebx
mov    %rbx,0x10(%rsp)
mov    (%r12),%edi
lea    0xb53(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    0x20(%rsp),%r15
test   %r15d,%r15d
mov    0x30(%rsp),%rbp
jle    1550 <hammer_device+0x3d0>
xor    %ebx,%ebx
jmp    1519 <hammer_device+0x399>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    $0x1,%rbx
cmp    %rbx,%r13
je     1550 <hammer_device+0x3d0>
mov    (%r12),%edi
mov    0x0(%rbp,%rbx,4),%edx
mov    0x8(%rsp),%rax
mov    (%rax,%rbx,4),%ecx
lea    0xb17(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
cmp    %rbx,%r14
je     1510 <hammer_device+0x390>
mov    (%r12),%edi
lea    0xad9(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
jmp    1510 <hammer_device+0x390>
mov    (%r12),%edi
lea    0xaf3(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    (%r12),%edi
call   1060 <fflush@plt>
mov    $0x1,%edi
call   10a0 <sleep@plt>
mov    0x2c(%rsp),%ebp
add    $0x1,%ebp
cmpl   $0x0,0x1c(%rsp)
mov    0x4(%rsp),%r12d
pxor   %xmm4,%xmm4
lea    0x8(%rsp),%rbx
je     1380 <hammer_device+0x200>
cmp    0x1c(%rsp),%ebp
jne    1380 <hammer_device+0x200>
jmp    15b8 <hammer_device+0x438>
xor    %ecx,%ecx
testb  $0x1,0x40(%rsp)
jne    1423 <hammer_device+0x2a3>
jmp    144b <hammer_device+0x2cb>
mov    %eax,%r15d
jmp    15d2 <hammer_device+0x452>
mov    0x2a19(%rip),%rax
mov    (%rax),%edi
lea    0xa77(%rip),%rsi
xor    %r15d,%r15d
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    %r12d,%edi
call   1050 <gpiotools_release_linehandle@plt>
mov    %r15d,%eax
add    $0x58,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.gpiohandle_data = type { i32* }
@__const.hammer_device.swirr = [5 x i8] c"-\\|/\00"
@GPIOHANDLE_REQUEST_OUTPUT = global i32 0
@.str = [12 x i8] c"gpio-hammer\00"
@stdout = global i32 0
@.str.1 = [15 x i8] c"Hammer lines [\00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [3 x i8] c", \00"
@.str.4 = [27 x i8] c"] on %s, initial states: [\00"
@.str.5 = [3 x i8] c"]\0A\00"
@.str.6 = [6 x i8] c"[%c] \00"
@.str.7 = [2 x i8] c"[\00"
@.str.8 = [7 x i8] c"%d: %d\00"
@.str.9 = [3 x i8] c"]\0D\00"
@.str.10 = [2 x i8] c"\0A\00"
define i32 @hammer_device(i8* %0, i32* %1, i32 %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
%9 = alloca %struct.gpiohandle_data
%10 = alloca [5 x i8]
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
store i8* %0, i8** %5
store i32* %1, i32** %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%16 = bitcast [5 x i8]* %10 to i8*
store i32 0, i32* %15
%17 = getelementptr inbounds %struct.gpiohandle_data, %struct.gpiohandle_data* %9, i32 0, i32 0
%18 = call i32 @memset(i32** %17, i32 0, i32 8)
%19 = load i8*, i8** %5
%20 = load i32*, i32** %6
%21 = load i32, i32* %7
%22 = load i32, i32* @GPIOHANDLE_REQUEST_OUTPUT
%23 = call i32 @gpiotools_request_linehandle(i8* %19, i32* %20, i32 %21, i32 %22, %struct.gpiohandle_data* %9, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
store i32 %23, i32* %12
%24 = load i32, i32* %12
%25 = icmp slt i32 %24, 0
br i1 %25, label %26, label %27
26: ; preds = %4
br label %195
27: ; preds = %4
%28 = load i32, i32* %12
store i32 %28, i32* %11
br label %29
29: ; preds = %27
%30 = load i32, i32* %11
%31 = call i32 @gpiotools_get_values(i32 %30, %struct.gpiohandle_data* %9)
store i32 %31, i32* %12
%32 = load i32, i32* %12
%33 = icmp slt i32 %32, 0
br i1 %33, label %34, label %35
34: ; preds = %29
br label %192
35: ; preds = %29
%36 = load i32, i32* @stdout
%37 = call i32 (i32, i8*, ...) @fprintf(i32 %36, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %13
br label %38
38: ; preds = %58, %35
%39 = load i32, i32* %13
%40 = load i32, i32* %7
%41 = icmp slt i32 %39, %40
br i1 %41, label %42, label %61
42: ; preds = %38
%43 = load i32, i32* @stdout
%44 = load i32*, i32** %6
%45 = load i32, i32* %13
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds i32, i32* %44, i64 %46
%48 = load i32, i32* %47
%49 = call i32 (i32, i8*, ...) @fprintf(i32 %43, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %48)
%50 = load i32, i32* %13
%51 = load i32, i32* %7
%52 = sub nsw i32 %51, 1
%53 = icmp ne i32 %50, %52
br i1 %53, label %54, label %57
54: ; preds = %42
%55 = load i32, i32* @stdout
%56 = call i32 (i32, i8*, ...) @fprintf(i32 %55, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
br label %57
57: ; preds = %54, %42
br label %58
58: ; preds = %57
%59 = load i32, i32* %13
%60 = add nsw i32 %59, 1
store i32 %60, i32* %13
br label %38
61: ; preds = %38
%62 = load i32, i32* @stdout
%63 = load i8*, i8** %5
%64 = call i32 (i32, i8*, ...) @fprintf(i32 %62, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0), i8* %63)
store i32 0, i32* %13
br label %65
65: ; preds = %86, %61
%66 = load i32, i32* %13
%67 = load i32, i32* %7
%68 = icmp slt i32 %66, %67
br i1 %68, label %69, label %89
69: ; preds = %65
%70 = load i32, i32* @stdout
%71 = getelementptr inbounds %struct.gpiohandle_data, %struct.gpiohandle_data* %9, i32 0, i32 0
%72 = load i32*, i32** %71
%73 = load i32, i32* %13
%74 = sext i32 %73 to i64
%75 = getelementptr inbounds i32, i32* %72, i64 %74
%76 = load i32, i32* %75
%77 = call i32 (i32, i8*, ...) @fprintf(i32 %70, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %76)
%78 = load i32, i32* %13
%79 = load i32, i32* %7
%80 = sub nsw i32 %79, 1
%81 = icmp ne i32 %78, %80
br i1 %81, label %82, label %85
82: ; preds = %69
%83 = load i32, i32* @stdout
%84 = call i32 (i32, i8*, ...) @fprintf(i32 %83, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
br label %85
85: ; preds = %82, %69
br label %86
86: ; preds = %85
%87 = load i32, i32* %13
%88 = add nsw i32 %87, 1
store i32 %88, i32* %13
br label %65
89: ; preds = %65
%90 = load i32, i32* @stdout
%91 = call i32 (i32, i8*, ...) @fprintf(i32 %90, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
store i32 0, i32* %14
br label %92
92: ; preds = %89, %188
store i32 0, i32* %13
br label %93
93: ; preds = %112, %92
%94 = load i32, i32* %13
%95 = load i32, i32* %7
%96 = icmp slt i32 %94, %95
br i1 %96, label %97, label %115
97: ; preds = %93
%98 = getelementptr inbounds %struct.gpiohandle_data, %struct.gpiohandle_data* %9, i32 0, i32 0
%99 = load i32*, i32** %98
%100 = load i32, i32* %13
%101 = sext i32 %100 to i64
%102 = getelementptr inbounds i32, i32* %99, i64 %101
%103 = load i32, i32* %102
%104 = icmp ne i32 %103, 0
%105 = xor i1 %104, true
%106 = zext i1 %105 to i32
%107 = getelementptr inbounds %struct.gpiohandle_data, %struct.gpiohandle_data* %9, i32 0, i32 0
%108 = load i32*, i32** %107
%109 = load i32, i32* %13
%110 = sext i32 %109 to i64
%111 = getelementptr inbounds i32, i32* %108, i64 %110
store i32 %106, i32* %111
br label %112
112: ; preds = %97
%113 = load i32, i32* %13
%114 = add nsw i32 %113, 1
store i32 %114, i32* %13
br label %93
115: ; preds = %93
%116 = load i32, i32* %11
%117 = call i32 @gpiotools_set_values(i32 %116, %struct.gpiohandle_data* %9)
store i32 %117, i32* %12
%118 = load i32, i32* %12
%119 = icmp slt i32 %118, 0
br i1 %119, label %120, label %121
120: ; preds = %115
br label %192
121: ; preds = %115
%122 = load i32, i32* %11
%123 = call i32 @gpiotools_get_values(i32 %122, %struct.gpiohandle_data* %9)
store i32 %123, i32* %12
%124 = load i32, i32* %12
%125 = icmp slt i32 %124, 0
br i1 %125, label %126, label %127
126: ; preds = %121
br label %192
127: ; preds = %121
%128 = load i32, i32* @stdout
%129 = load i32, i32* %14
%130 = sext i32 %129 to i64
%131 = getelementptr inbounds [5 x i8], [5 x i8]* %10, i64 0, i64 %130
%132 = load i8, i8* %131
%133 = sext i8 %132 to i32
%134 = call i32 (i32, i8*, ...) @fprintf(i32 %128, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0), i32 %133)
%135 = load i32, i32* %14
%136 = add nsw i32 %135, 1
store i32 %136, i32* %14
%137 = load i32, i32* %14
%138 = sext i32 %137 to i64
%139 = icmp eq i64 %138, 4
br i1 %139, label %140, label %141
140: ; preds = %127
store i32 0, i32* %14
br label %141
141: ; preds = %140, %127
%142 = load i32, i32* @stdout
%143 = call i32 (i32, i8*, ...) @fprintf(i32 %142, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
store i32 0, i32* %13
br label %144
144: ; preds = %170, %141
%145 = load i32, i32* %13
%146 = load i32, i32* %7
%147 = icmp slt i32 %145, %146
br i1 %147, label %148, label %173
148: ; preds = %144
%149 = load i32, i32* @stdout
%150 = load i32*, i32** %6
%151 = load i32, i32* %13
%152 = sext i32 %151 to i64
%153 = getelementptr inbounds i32, i32* %150, i64 %152
%154 = load i32, i32* %153
%155 = getelementptr inbounds %struct.gpiohandle_data, %struct.gpiohandle_data* %9, i32 0, i32 0
%156 = load i32*, i32** %155
%157 = load i32, i32* %13
%158 = sext i32 %157 to i64
%159 = getelementptr inbounds i32, i32* %156, i64 %158
%160 = load i32, i32* %159
%161 = call i32 (i32, i8*, ...) @fprintf(i32 %149, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.8, i64 0, i64 0), i32 %154, i32 %160)
%162 = load i32, i32* %13
%163 = load i32, i32* %7
%164 = sub nsw i32 %163, 1
%165 = icmp ne i32 %162, %164
br i1 %165, label %166, label %169
166: ; preds = %148
%167 = load i32, i32* @stdout
%168 = call i32 (i32, i8*, ...) @fprintf(i32 %167, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
br label %169
169: ; preds = %166, %148
br label %170
170: ; preds = %169
%171 = load i32, i32* %13
%172 = add nsw i32 %171, 1
store i32 %172, i32* %13
br label %144
173: ; preds = %144
%174 = load i32, i32* @stdout
%175 = call i32 (i32, i8*, ...) @fprintf(i32 %174, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.9, i64 0, i64 0))
%176 = load i32, i32* @stdout
%177 = call i32 @fflush(i32 %176)
%178 = call i32 @sleep(i32 1)
%179 = load i32, i32* %15
%180 = add i32 %179, 1
store i32 %180, i32* %15
%181 = load i32, i32* %8
%182 = icmp ne i32 %181, 0
br i1 %182, label %183, label %188
183: ; preds = %173
%184 = load i32, i32* %15
%185 = load i32, i32* %8
%186 = icmp eq i32 %184, %185
br i1 %186, label %187, label %188
187: ; preds = %183
br label %189
188: ; preds = %183, %173
br label %92
189: ; preds = %187
%190 = load i32, i32* @stdout
%191 = call i32 (i32, i8*, ...) @fprintf(i32 %190, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.10, i64 0, i64 0))
store i32 0, i32* %12
br label %192
192: ; preds = %189, %126, %120, %34
%193 = load i32, i32* %11
%194 = call i32 @gpiotools_release_linehandle(i32 %193)
br label %195
195: ; preds = %192, %26
%196 = load i32, i32* %12
ret i32 %196
}

LLVM IR (-O2):
%struct.gpiohandle_data = type { i32* }
@__const.hammer_device.swirr = [5 x i8] c"-\\|/\00"
@GPIOHANDLE_REQUEST_OUTPUT = global i32 0
@.str = [12 x i8] c"gpio-hammer\00"
@stdout = global i32 0
@.str.1 = [15 x i8] c"Hammer lines [\00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [3 x i8] c", \00"
@.str.4 = [27 x i8] c"] on %s, initial states: [\00"
@.str.5 = [3 x i8] c"]\0A\00"
@.str.6 = [6 x i8] c"[%c] \00"
@.str.7 = [2 x i8] c"[\00"
@.str.8 = [7 x i8] c"%d: %d\00"
@.str.9 = [3 x i8] c"]\0D\00"
@.str.10 = [2 x i8] c"\0A\00"
define i32 @hammer_device(i8* %0, i32* %1, i32 %2, i32 %3) {
%5 = alloca %struct.gpiohandle_data
%6 = bitcast %struct.gpiohandle_data* %5 to i8*
%7 = getelementptr inbounds %struct.gpiohandle_data, %struct.gpiohandle_data* %5, i64 0, i32 0
%8 = call i32 @memset(i32** %7, i32 0, i32 8)
%9 = load i32, i32* @GPIOHANDLE_REQUEST_OUTPUT
%10 = call i32 @gpiotools_request_linehandle(i8* %0, i32* %1, i32 %2, i32 %9, %struct.gpiohandle_data* %5, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%11 = icmp slt i32 %10, 0
br i1 %11, label %193, label %12
12: ; preds = %4
%13 = call i32 @gpiotools_get_values(i32 %10, %struct.gpiohandle_data* %5)
%14 = icmp slt i32 %13, 0
br i1 %14, label %190, label %15
15: ; preds = %12
%16 = load i32, i32* @stdout
%17 = call i32 (i32, i8*, ...) @fprintf(i32 %16, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
%18 = icmp sgt i32 %2, 0
br i1 %18, label %22, label %19
19: ; preds = %15
%20 = load i32, i32* @stdout
%21 = call i32 (i32, i8*, ...) @fprintf(i32 %20, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0), i8* %0)
br label %42
22: ; preds = %15
%23 = add nsw i32 %2, -1
%24 = zext i32 %23 to i64
%25 = zext i32 %2 to i64
br label %26
26: ; preds = %22, %36
%27 = phi i64 [ 0, %22 ], [ %37, %36 ]
%28 = load i32, i32* @stdout
%29 = getelementptr inbounds i32, i32* %1, i64 %27
%30 = load i32, i32* %29
%31 = call i32 (i32, i8*, ...) @fprintf(i32 %28, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %30)
%32 = icmp eq i64 %27, %24
br i1 %32, label %36, label %33
33: ; preds = %26
%34 = load i32, i32* @stdout
%35 = call i32 (i32, i8*, ...) @fprintf(i32 %34, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
br label %36
36: ; preds = %26, %33
%37 = add nuw nsw i64 %27, 1
%38 = icmp eq i64 %37, %25
br i1 %38, label %39, label %26
39: ; preds = %36
%40 = load i32, i32* @stdout
%41 = call i32 (i32, i8*, ...) @fprintf(i32 %40, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0), i8* %0)
br i1 %18, label %45, label %42
42: ; preds = %19, %39
%43 = add nsw i32 %2, -1
%44 = zext i32 %43 to i64
br label %63
45: ; preds = %39
%46 = add nsw i32 %2, -1
%47 = zext i32 %46 to i64
%48 = zext i32 %2 to i64
br label %49
49: ; preds = %45, %60
%50 = phi i64 [ 0, %45 ], [ %61, %60 ]
%51 = load i32, i32* @stdout
%52 = load i32*, i32** %7
%53 = getelementptr inbounds i32, i32* %52, i64 %50
%54 = load i32, i32* %53
%55 = call i32 (i32, i8*, ...) @fprintf(i32 %51, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %54)
%56 = icmp eq i64 %50, %47
br i1 %56, label %60, label %57
57: ; preds = %49
%58 = load i32, i32* @stdout
%59 = call i32 (i32, i8*, ...) @fprintf(i32 %58, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
br label %60
60: ; preds = %49, %57
%61 = add nuw nsw i64 %50, 1
%62 = icmp eq i64 %61, %48
br i1 %62, label %63, label %49
63: ; preds = %60, %42
%64 = phi i64 [ %44, %42 ], [ %47, %60 ]
%65 = load i32, i32* @stdout
%66 = call i32 (i32, i8*, ...) @fprintf(i32 %65, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
%67 = icmp ne i32 %3, 0
%68 = zext i32 %2 to i64
%69 = zext i32 %2 to i64
%70 = and i64 %68, 4294967288
%71 = add nsw i64 %70, -8
%72 = lshr exact i64 %71, 3
%73 = add nuw nsw i64 %72, 1
%74 = icmp ult i32 %2, 8
%75 = and i64 %68, 4294967288
%76 = and i64 %73, 1
%77 = icmp eq i64 %71, 0
%78 = and i64 %73, 4611686018427387902
%79 = icmp eq i64 %76, 0
%80 = icmp eq i64 %75, %68
br label %81
81: ; preds = %178, %63
%82 = phi i32 [ 0, %63 ], [ %159, %178 ]
%83 = phi i32 [ 0, %63 ], [ %184, %178 ]
br i1 %18, label %84, label %144
84: ; preds = %81
%85 = load i32*, i32** %7
br i1 %74, label %134, label %86
86: ; preds = %84
br i1 %77, label %118, label %87
87: ; preds = %86, %87
%88 = phi i64 [ %115, %87 ], [ 0, %86 ]
%89 = phi i64 [ %116, %87 ], [ 0, %86 ]
%90 = getelementptr inbounds i32, i32* %85, i64 %88
%91 = bitcast i32* %90 to <4 x i32>*
%92 = load <4 x i32>, <4 x i32>* %91
%93 = getelementptr inbounds i32, i32* %90, i64 4
%94 = bitcast i32* %93 to <4 x i32>*
%95 = load <4 x i32>, <4 x i32>* %94
%96 = icmp eq <4 x i32> %92, zeroinitializer
%97 = icmp eq <4 x i32> %95, zeroinitializer
%98 = zext <4 x i1> %96 to <4 x i32>
%99 = zext <4 x i1> %97 to <4 x i32>
%100 = bitcast i32* %90 to <4 x i32>*
store <4 x i32> %98, <4 x i32>* %100
%101 = bitcast i32* %93 to <4 x i32>*
store <4 x i32> %99, <4 x i32>* %101
%102 = or i64 %88, 8
%103 = getelementptr inbounds i32, i32* %85, i64 %102
%104 = bitcast i32* %103 to <4 x i32>*
%105 = load <4 x i32>, <4 x i32>* %104
%106 = getelementptr inbounds i32, i32* %103, i64 4
%107 = bitcast i32* %106 to <4 x i32>*
%108 = load <4 x i32>, <4 x i32>* %107
%109 = icmp eq <4 x i32> %105, zeroinitializer
%110 = icmp eq <4 x i32> %108, zeroinitializer
%111 = zext <4 x i1> %109 to <4 x i32>
%112 = zext <4 x i1> %110 to <4 x i32>
%113 = bitcast i32* %103 to <4 x i32>*
store <4 x i32> %111, <4 x i32>* %113
%114 = bitcast i32* %106 to <4 x i32>*
store <4 x i32> %112, <4 x i32>* %114
%115 = add nuw i64 %88, 16
%116 = add i64 %89, 2
%117 = icmp eq i64 %116, %78
br i1 %117, label %118, label %87
118: ; preds = %87, %86
%119 = phi i64 [ 0, %86 ], [ %115, %87 ]
br i1 %79, label %133, label %120
120: ; preds = %118
%121 = getelementptr inbounds i32, i32* %85, i64 %119
%122 = bitcast i32* %121 to <4 x i32>*
%123 = load <4 x i32>, <4 x i32>* %122
%124 = getelementptr inbounds i32, i32* %121, i64 4
%125 = bitcast i32* %124 to <4 x i32>*
%126 = load <4 x i32>, <4 x i32>* %125
%127 = icmp eq <4 x i32> %123, zeroinitializer
%128 = icmp eq <4 x i32> %126, zeroinitializer
%129 = zext <4 x i1> %127 to <4 x i32>
%130 = zext <4 x i1> %128 to <4 x i32>
%131 = bitcast i32* %121 to <4 x i32>*
store <4 x i32> %129, <4 x i32>* %131
%132 = bitcast i32* %124 to <4 x i32>*
store <4 x i32> %130, <4 x i32>* %132
br label %133
133: ; preds = %118, %120
br i1 %80, label %144, label %134
134: ; preds = %84, %133
%135 = phi i64 [ 0, %84 ], [ %75, %133 ]
br label %136
136: ; preds = %134, %136
%137 = phi i64 [ %142, %136 ], [ %135, %134 ]
%138 = getelementptr inbounds i32, i32* %85, i64 %137
%139 = load i32, i32* %138
%140 = icmp eq i32 %139, 0
%141 = zext i1 %140 to i32
store i32 %141, i32* %138
%142 = add nuw nsw i64 %137, 1
%143 = icmp eq i64 %142, %68
br i1 %143, label %144, label %136
144: ; preds = %136, %133, %81
%145 = call i32 @gpiotools_set_values(i32 %10, %struct.gpiohandle_data* %5)
%146 = icmp slt i32 %145, 0
br i1 %146, label %190, label %147
147: ; preds = %144
%148 = call i32 @gpiotools_get_values(i32 %10, %struct.gpiohandle_data* %5)
%149 = icmp slt i32 %148, 0
br i1 %149, label %190, label %150
150: ; preds = %147
%151 = load i32, i32* @stdout
%152 = sext i32 %82 to i64
%153 = getelementptr inbounds [5 x i8], [5 x i8]* @__const.hammer_device.swirr, i64 0, i64 %152
%154 = load i8, i8* %153
%155 = sext i8 %154 to i32
%156 = call i32 (i32, i8*, ...) @fprintf(i32 %151, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0), i32 %155)
%157 = add nsw i32 %82, 1
%158 = icmp eq i32 %157, 4
%159 = select i1 %158, i32 0, i32 %157
%160 = load i32, i32* @stdout
%161 = call i32 (i32, i8*, ...) @fprintf(i32 %160, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
br i1 %18, label %162, label %178
162: ; preds = %150, %175
%163 = phi i64 [ %176, %175 ], [ 0, %150 ]
%164 = load i32, i32* @stdout
%165 = getelementptr inbounds i32, i32* %1, i64 %163
%166 = load i32, i32* %165
%167 = load i32*, i32** %7
%168 = getelementptr inbounds i32, i32* %167, i64 %163
%169 = load i32, i32* %168
%170 = call i32 (i32, i8*, ...) @fprintf(i32 %164, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.8, i64 0, i64 0), i32 %166, i32 %169)
%171 = icmp eq i64 %163, %64
br i1 %171, label %175, label %172
172: ; preds = %162
%173 = load i32, i32* @stdout
%174 = call i32 (i32, i8*, ...) @fprintf(i32 %173, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
br label %175
175: ; preds = %162, %172
%176 = add nuw nsw i64 %163, 1
%177 = icmp eq i64 %176, %69
br i1 %177, label %178, label %162
178: ; preds = %175, %150
%179 = load i32, i32* @stdout
%180 = call i32 (i32, i8*, ...) @fprintf(i32 %179, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.9, i64 0, i64 0))
%181 = load i32, i32* @stdout
%182 = call i32 @fflush(i32 %181)
%183 = call i32 @sleep(i32 1)
%184 = add i32 %83, 1
%185 = icmp eq i32 %184, %3
%186 = select i1 %67, i1 %185, i1 false
br i1 %186, label %187, label %81
187: ; preds = %178
%188 = load i32, i32* @stdout
%189 = call i32 (i32, i8*, ...) @fprintf(i32 %188, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.10, i64 0, i64 0))
br label %190
190: ; preds = %147, %144, %12, %187
%191 = phi i32 [ %13, %12 ], [ 0, %187 ], [ %148, %147 ], [ %145, %144 ]
%192 = call i32 @gpiotools_release_linehandle(i32 %10)
br label %193
193: ; preds = %4, %190
%194 = phi i32 [ %10, %4 ], [ %191, %190 ]
ret i32 %194
}