#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 uint32_t;
struct keymap {
  int dummy;
};

/* Variables and functions */
int keymap_param(struct keymap *, char *, int);
void encode_pulse_length(struct keymap *map, uint32_t scancode, int *buf,
                         int *length) {
  int len = 0, bits, i;
  buf[len++] = keymap_param(map, "header_pulse", 2125);
  buf[len++] = keymap_param(map, "header_space", 1875);
  bits = keymap_param(map, "bits", 4);
  if (keymap_param(map, "reverse", 0)) {
    for (i = 0; i < bits; i++) {
      if (scancode & (1 << i))
        buf[len++] = keymap_param(map, "bit_1_space", 1625);
      else
        buf[len++] = keymap_param(map, "bit_0_space", 375);
      buf[len++] = keymap_param(map, "bit_pulse", 625);
    }
  } else {
    for (i = bits - 1; i >= 0; i--) {
      if (scancode & (1 << i))
        buf[len++] = keymap_param(map, "bit_1_space", 1625);
      else
        buf[len++] = keymap_param(map, "bit_0_space", 375);
      buf[len++] = keymap_param(map, "bit_pulse", 625);
    }
  }
  *length = len;
}


x86 assembly (clang, -O0):
<encode_pulse_length>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xec7(%rip),%rsi
mov    $0x84d,%edx
call   1030 <keymap_param@plt>
mov    %eax,%edx
mov    -0x18(%rbp),%rax
mov    -0x24(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x24(%rbp)
movslq %ecx,%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x8(%rbp),%rdi
lea    0xea8(%rip),%rsi
mov    $0x753,%edx
call   1030 <keymap_param@plt>
mov    %eax,%edx
mov    -0x18(%rbp),%rax
mov    -0x24(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x24(%rbp)
movslq %ecx,%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x8(%rbp),%rdi
lea    0xe89(%rip),%rsi
mov    $0x4,%edx
call   1030 <keymap_param@plt>
mov    %eax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe76(%rip),%rsi
xor    %edx,%edx
call   1030 <keymap_param@plt>
cmp    $0x0,%eax
je     1282 <encode_pulse_length+0x172>
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x28(%rbp),%eax
jge    127d <encode_pulse_length+0x16d>
mov    -0xc(%rbp),%eax
mov    -0x2c(%rbp),%ecx
mov    $0x1,%edx
shl    %cl,%edx
mov    %edx,%ecx
and    %ecx,%eax
cmp    $0x0,%eax
je     1217 <encode_pulse_length+0x107>
mov    -0x8(%rbp),%rdi
lea    0xe36(%rip),%rsi
mov    $0x659,%edx
call   1030 <keymap_param@plt>
mov    %eax,%edx
mov    -0x18(%rbp),%rax
mov    -0x24(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x24(%rbp)
movslq %ecx,%rcx
mov    %edx,(%rax,%rcx,4)
jmp    1243 <encode_pulse_length+0x133>
mov    -0x8(%rbp),%rdi
lea    0xe11(%rip),%rsi
mov    $0x177,%edx
call   1030 <keymap_param@plt>
mov    %eax,%edx
mov    -0x18(%rbp),%rax
mov    -0x24(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x24(%rbp)
movslq %ecx,%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x8(%rbp),%rdi
lea    0xdf1(%rip),%rsi
mov    $0x271,%edx
call   1030 <keymap_param@plt>
mov    %eax,%edx
mov    -0x18(%rbp),%rax
mov    -0x24(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x24(%rbp)
movslq %ecx,%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11c0 <encode_pulse_length+0xb0>
jmp    134b <encode_pulse_length+0x23b>
mov    -0x28(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jl     1346 <encode_pulse_length+0x236>
mov    -0xc(%rbp),%eax
mov    -0x2c(%rbp),%ecx
mov    $0x1,%edx
shl    %cl,%edx
mov    %edx,%ecx
and    %ecx,%eax
cmp    $0x0,%eax
je     12e0 <encode_pulse_length+0x1d0>
mov    -0x8(%rbp),%rdi
lea    0xd6d(%rip),%rsi
mov    $0x659,%edx
call   1030 <keymap_param@plt>
mov    %eax,%edx
mov    -0x18(%rbp),%rax
mov    -0x24(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x24(%rbp)
movslq %ecx,%rcx
mov    %edx,(%rax,%rcx,4)
jmp    130c <encode_pulse_length+0x1fc>
mov    -0x8(%rbp),%rdi
lea    0xd48(%rip),%rsi
mov    $0x177,%edx
call   1030 <keymap_param@plt>
mov    %eax,%edx
mov    -0x18(%rbp),%rax
mov    -0x24(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x24(%rbp)
movslq %ecx,%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x8(%rbp),%rdi
lea    0xd28(%rip),%rsi
mov    $0x271,%edx
call   1030 <keymap_param@plt>
mov    %eax,%edx
mov    -0x18(%rbp),%rax
mov    -0x24(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x24(%rbp)
movslq %ecx,%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x2c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x2c(%rbp)
jmp    128b <encode_pulse_length+0x17b>
jmp    134b <encode_pulse_length+0x23b>
mov    -0x24(%rbp),%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<encode_pulse_length>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rcx,(%rsp)
mov    %rdx,%r12
mov    %esi,%r15d
mov    %rdi,%rbp
lea    0xed1(%rip),%rsi
mov    $0x84d,%edx
call   1030 <keymap_param@plt>
mov    %eax,(%r12)
lea    0xec9(%rip),%rsi
mov    %rbp,%rdi
mov    $0x753,%edx
call   1030 <keymap_param@plt>
mov    %eax,0x4(%r12)
lea    0xebd(%rip),%rsi
mov    %rbp,%rdi
mov    $0x4,%edx
call   1030 <keymap_param@plt>
mov    %eax,%ebx
lea    0xeac(%rip),%rsi
mov    %rbp,%rdi
xor    %edx,%edx
call   1030 <keymap_param@plt>
test   %eax,%eax
je     11f7 <encode_pulse_length+0xe7>
test   %ebx,%ebx
jle    1263 <encode_pulse_length+0x153>
mov    %ebx,%r13d
mov    $0x2,%r14d
xor    %ebx,%ebx
jmp    11e0 <encode_pulse_length+0xd0>
cs nopw 0x0(%rax,%rax,1)
lea    0xe8c(%rip),%rsi
mov    $0x177,%edx
call   1030 <keymap_param@plt>
mov    %eax,0x8(%r12,%rbx,8)
mov    %rbp,%rdi
lea    0xe7f(%rip),%rsi
mov    $0x271,%edx
call   1030 <keymap_param@plt>
mov    %eax,0xc(%r12,%rbx,8)
add    $0x1,%rbx
add    $0x2,%r14d
cmp    %ebx,%r13d
je     1269 <encode_pulse_length+0x159>
mov    %rbp,%rdi
bt     %ebx,%r15d
jae    11a0 <encode_pulse_length+0x90>
lea    0xe37(%rip),%rsi
mov    $0x659,%edx
jmp    11ac <encode_pulse_length+0x9c>
test   %ebx,%ebx
jle    1263 <encode_pulse_length+0x153>
add    $0x1,%ebx
mov    $0x2,%r14d
lea    0xe34(%rip),%r13
jmp    1246 <encode_pulse_length+0x136>
nopl   (%rax)
lea    0xe1c(%rip),%rsi
mov    $0x177,%edx
call   1030 <keymap_param@plt>
mov    %eax,(%r12,%r14,4)
mov    %rbp,%rdi
mov    %r13,%rsi
mov    $0x271,%edx
call   1030 <keymap_param@plt>
mov    %eax,0x4(%r12,%r14,4)
add    $0x2,%r14
add    $0xffffffff,%ebx
cmp    $0x1,%ebx
jbe    1269 <encode_pulse_length+0x159>
lea    -0x2(%rbx),%eax
movzbl %al,%eax
mov    %rbp,%rdi
bt     %eax,%r15d
jae    1210 <encode_pulse_length+0x100>
lea    0xdcb(%rip),%rsi
mov    $0x659,%edx
jmp    121c <encode_pulse_length+0x10c>
mov    $0x2,%r14d
mov    (%rsp),%rax
mov    %r14d,(%rax)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.keymap = type { i32 }
@.str = [13 x i8] c"header_pulse\00"
@.str.1 = [13 x i8] c"header_space\00"
@.str.2 = [5 x i8] c"bits\00"
@.str.3 = [8 x i8] c"reverse\00"
@.str.4 = [12 x i8] c"bit_1_space\00"
@.str.5 = [12 x i8] c"bit_0_space\00"
@.str.6 = [10 x i8] c"bit_pulse\00"
define void @encode_pulse_length(%struct.keymap* %0, i32 %1, i32* %2, i32* %3) {
%5 = alloca %struct.keymap*
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store %struct.keymap* %0, %struct.keymap** %5
store i32 %1, i32* %6
store i32* %2, i32** %7
store i32* %3, i32** %8
store i32 0, i32* %9
%12 = load %struct.keymap*, %struct.keymap** %5
%13 = call i32 @keymap_param(%struct.keymap* %12, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 2125)
%14 = load i32*, i32** %7
%15 = load i32, i32* %9
%16 = add nsw i32 %15, 1
store i32 %16, i32* %9
%17 = sext i32 %15 to i64
%18 = getelementptr inbounds i32, i32* %14, i64 %17
store i32 %13, i32* %18
%19 = load %struct.keymap*, %struct.keymap** %5
%20 = call i32 @keymap_param(%struct.keymap* %19, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 1875)
%21 = load i32*, i32** %7
%22 = load i32, i32* %9
%23 = add nsw i32 %22, 1
store i32 %23, i32* %9
%24 = sext i32 %22 to i64
%25 = getelementptr inbounds i32, i32* %21, i64 %24
store i32 %20, i32* %25
%26 = load %struct.keymap*, %struct.keymap** %5
%27 = call i32 @keymap_param(%struct.keymap* %26, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 4)
store i32 %27, i32* %10
%28 = load %struct.keymap*, %struct.keymap** %5
%29 = call i32 @keymap_param(%struct.keymap* %28, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i32 0)
%30 = icmp ne i32 %29, 0
br i1 %30, label %31, label %70
31: ; preds = %4
store i32 0, i32* %11
br label %32
32: ; preds = %66, %31
%33 = load i32, i32* %11
%34 = load i32, i32* %10
%35 = icmp slt i32 %33, %34
br i1 %35, label %36, label %69
36: ; preds = %32
%37 = load i32, i32* %6
%38 = load i32, i32* %11
%39 = shl i32 1, %38
%40 = and i32 %37, %39
%41 = icmp ne i32 %40, 0
br i1 %41, label %42, label %50
42: ; preds = %36
%43 = load %struct.keymap*, %struct.keymap** %5
%44 = call i32 @keymap_param(%struct.keymap* %43, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i32 1625)
%45 = load i32*, i32** %7
%46 = load i32, i32* %9
%47 = add nsw i32 %46, 1
store i32 %47, i32* %9
%48 = sext i32 %46 to i64
%49 = getelementptr inbounds i32, i32* %45, i64 %48
store i32 %44, i32* %49
br label %58
50: ; preds = %36
%51 = load %struct.keymap*, %struct.keymap** %5
%52 = call i32 @keymap_param(%struct.keymap* %51, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0), i32 375)
%53 = load i32*, i32** %7
%54 = load i32, i32* %9
%55 = add nsw i32 %54, 1
store i32 %55, i32* %9
%56 = sext i32 %54 to i64
%57 = getelementptr inbounds i32, i32* %53, i64 %56
store i32 %52, i32* %57
br label %58
58: ; preds = %50, %42
%59 = load %struct.keymap*, %struct.keymap** %5
%60 = call i32 @keymap_param(%struct.keymap* %59, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0), i32 625)
%61 = load i32*, i32** %7
%62 = load i32, i32* %9
%63 = add nsw i32 %62, 1
store i32 %63, i32* %9
%64 = sext i32 %62 to i64
%65 = getelementptr inbounds i32, i32* %61, i64 %64
store i32 %60, i32* %65
br label %66
66: ; preds = %58
%67 = load i32, i32* %11
%68 = add nsw i32 %67, 1
store i32 %68, i32* %11
br label %32
69: ; preds = %32
br label %110
70: ; preds = %4
%71 = load i32, i32* %10
%72 = sub nsw i32 %71, 1
store i32 %72, i32* %11
br label %73
73: ; preds = %106, %70
%74 = load i32, i32* %11
%75 = icmp sge i32 %74, 0
br i1 %75, label %76, label %109
76: ; preds = %73
%77 = load i32, i32* %6
%78 = load i32, i32* %11
%79 = shl i32 1, %78
%80 = and i32 %77, %79
%81 = icmp ne i32 %80, 0
br i1 %81, label %82, label %90
82: ; preds = %76
%83 = load %struct.keymap*, %struct.keymap** %5
%84 = call i32 @keymap_param(%struct.keymap* %83, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i32 1625)
%85 = load i32*, i32** %7
%86 = load i32, i32* %9
%87 = add nsw i32 %86, 1
store i32 %87, i32* %9
%88 = sext i32 %86 to i64
%89 = getelementptr inbounds i32, i32* %85, i64 %88
store i32 %84, i32* %89
br label %98
90: ; preds = %76
%91 = load %struct.keymap*, %struct.keymap** %5
%92 = call i32 @keymap_param(%struct.keymap* %91, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0), i32 375)
%93 = load i32*, i32** %7
%94 = load i32, i32* %9
%95 = add nsw i32 %94, 1
store i32 %95, i32* %9
%96 = sext i32 %94 to i64
%97 = getelementptr inbounds i32, i32* %93, i64 %96
store i32 %92, i32* %97
br label %98
98: ; preds = %90, %82
%99 = load %struct.keymap*, %struct.keymap** %5
%100 = call i32 @keymap_param(%struct.keymap* %99, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0), i32 625)
%101 = load i32*, i32** %7
%102 = load i32, i32* %9
%103 = add nsw i32 %102, 1
store i32 %103, i32* %9
%104 = sext i32 %102 to i64
%105 = getelementptr inbounds i32, i32* %101, i64 %104
store i32 %100, i32* %105
br label %106
106: ; preds = %98
%107 = load i32, i32* %11
%108 = add nsw i32 %107, -1
store i32 %108, i32* %11
br label %73
109: ; preds = %73
br label %110
110: ; preds = %109, %69
%111 = load i32, i32* %9
%112 = load i32*, i32** %8
store i32 %111, i32* %112
ret void
}

LLVM IR (-O2):
%struct.keymap = type { i32 }
@.str = [13 x i8] c"header_pulse\00"
@.str.1 = [13 x i8] c"header_space\00"
@.str.2 = [5 x i8] c"bits\00"
@.str.3 = [8 x i8] c"reverse\00"
@.str.4 = [12 x i8] c"bit_1_space\00"
@.str.5 = [12 x i8] c"bit_0_space\00"
@.str.6 = [10 x i8] c"bit_pulse\00"
define void @encode_pulse_length(%struct.keymap* %0, i32 %1, i32* nocapture writeonly %2, i32* nocapture writeonly %3) {
%5 = tail call i32 @keymap_param(%struct.keymap* %0, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 2125)
store i32 %5, i32* %2
%6 = tail call i32 @keymap_param(%struct.keymap* %0, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 1875)
%7 = getelementptr inbounds i32, i32* %2, i64 1
store i32 %6, i32* %7
%8 = tail call i32 @keymap_param(%struct.keymap* %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 4)
%9 = tail call i32 @keymap_param(%struct.keymap* %0, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i32 0)
%10 = icmp eq i32 %9, 0
%11 = icmp sgt i32 %8, 0
br i1 %10, label %13, label %12
12: ; preds = %4
br i1 %11, label %14, label %56
13: ; preds = %4
br i1 %11, label %33, label %56
14: ; preds = %12, %24
%15 = phi i64 [ %29, %24 ], [ 2, %12 ]
%16 = phi i32 [ %31, %24 ], [ 0, %12 ]
%17 = shl nuw i32 1, %16
%18 = and i32 %17, %1
%19 = icmp eq i32 %18, 0
br i1 %19, label %22, label %20
20: ; preds = %14
%21 = tail call i32 @keymap_param(%struct.keymap* %0, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i32 1625)
br label %24
22: ; preds = %14
%23 = tail call i32 @keymap_param(%struct.keymap* %0, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0), i32 375)
br label %24
24: ; preds = %22, %20
%25 = phi i32 [ %23, %22 ], [ %21, %20 ]
%26 = getelementptr inbounds i32, i32* %2, i64 %15
store i32 %25, i32* %26
%27 = or i64 %15, 1
%28 = tail call i32 @keymap_param(%struct.keymap* %0, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0), i32 625)
%29 = add nuw nsw i64 %15, 2
%30 = getelementptr inbounds i32, i32* %2, i64 %27
store i32 %28, i32* %30
%31 = add nuw nsw i32 %16, 1
%32 = icmp eq i32 %31, %8
br i1 %32, label %54, label %14
33: ; preds = %13, %44
%34 = phi i64 [ %49, %44 ], [ 2, %13 ]
%35 = phi i32 [ %36, %44 ], [ %8, %13 ]
%36 = add nsw i32 %35, -1
%37 = shl nuw i32 1, %36
%38 = and i32 %37, %1
%39 = icmp eq i32 %38, 0
br i1 %39, label %42, label %40
40: ; preds = %33
%41 = tail call i32 @keymap_param(%struct.keymap* %0, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i32 1625)
br label %44
42: ; preds = %33
%43 = tail call i32 @keymap_param(%struct.keymap* %0, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0), i32 375)
br label %44
44: ; preds = %42, %40
%45 = phi i32 [ %43, %42 ], [ %41, %40 ]
%46 = getelementptr inbounds i32, i32* %2, i64 %34
store i32 %45, i32* %46
%47 = or i64 %34, 1
%48 = tail call i32 @keymap_param(%struct.keymap* %0, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0), i32 625)
%49 = add nuw nsw i64 %34, 2
%50 = getelementptr inbounds i32, i32* %2, i64 %47
store i32 %48, i32* %50
%51 = icmp ugt i32 %35, 1
br i1 %51, label %33, label %52
52: ; preds = %44
%53 = trunc i64 %49 to i32
br label %56
54: ; preds = %24
%55 = trunc i64 %29 to i32
br label %56
56: ; preds = %54, %52, %12, %13
%57 = phi i32 [ 2, %13 ], [ 2, %12 ], [ %53, %52 ], [ %55, %54 ]
store i32 %57, i32* %3
ret void
}