#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;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
void generate_line(uint32_t len) {
  FILE *f;
  f = fopen("out", "w+");
  uint32_t i;
  for (i = 1; i <= len; i++) {
    if (i == 1) {
      fprintf(f, "1 --> 2\n");
    } else if (i == len) {
      fprintf(f, "%d --> %d\n", len, len - 1);
    } else {
      fprintf(f, "%d --> %d %d\n", i, i - 1, i + 1);
    }
    if (i != len)
      fprintf(f, "\n");
  }
  fclose(f);
}


x86 assembly (clang, -O0):
<generate_line>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
lea    0xebe(%rip),%rdi
lea    0xebb(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x10(%rbp)
movl   $0x1,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x4(%rbp),%eax
jg     120b <generate_line+0xdb>
cmpl   $0x1,-0x14(%rbp)
jne    1186 <generate_line+0x56>
mov    -0x10(%rbp),%rdi
lea    0xe8d(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
jmp    11da <generate_line+0xaa>
mov    -0x14(%rbp),%eax
cmp    -0x4(%rbp),%eax
jne    11b2 <generate_line+0x82>
mov    -0x10(%rbp),%rdi
mov    -0x4(%rbp),%edx
mov    -0x4(%rbp),%ecx
sub    $0x1,%ecx
lea    0xe6a(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
jmp    11d5 <generate_line+0xa5>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%edx
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
mov    -0x14(%rbp),%r8d
add    $0x1,%r8d
lea    0xe4d(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
jmp    11da <generate_line+0xaa>
mov    -0x14(%rbp),%eax
cmp    -0x4(%rbp),%eax
je     11f8 <generate_line+0xc8>
mov    -0x10(%rbp),%rdi
lea    0xe1d(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
jmp    11fd <generate_line+0xcd>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1159 <generate_line+0x29>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<generate_line>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edi,%r15d
lea    0xe9b(%rip),%rdi
lea    0xe98(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%rbx
test   %r15d,%r15d
jle    1198 <generate_line+0x48>
lea    0xe87(%rip),%rdi
mov    $0x8,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1070 <fwrite@plt>
cmp    $0x1,%r15d
jne    11ae <generate_line+0x5e>
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <fclose@plt>
lea    -0x1(%r15),%r12d
mov    $0xa,%edi
mov    %rbx,%rsi
call   1040 <fputc@plt>
mov    %r15d,%r14d
neg    %r14d
mov    $0x3,%ebp
jmp    11e3 <generate_line+0x93>
nopl   0x0(%rax)
lea    (%r14,%rbp,1),%eax
add    $0x1,%eax
mov    %ebp,%ecx
add    $0x1,%ecx
mov    %ecx,%ebp
cmp    $0x2,%eax
je     1198 <generate_line+0x48>
lea    (%r14,%rbp,1),%r13d
cmp    $0x1,%r13d
jne    1210 <generate_line+0xc0>
mov    %rbx,%rdi
lea    0xe19(%rip),%rsi
mov    %r15d,%edx
mov    %r12d,%ecx
xor    %eax,%eax
call   1050 <fprintf@plt>
cmp    $0x1,%r13d
je     11d0 <generate_line+0x80>
jmp    1230 <generate_line+0xe0>
nopl   0x0(%rax)
lea    -0x1(%rbp),%edx
lea    -0x2(%rbp),%ecx
mov    %rbx,%rdi
lea    0xdfb(%rip),%rsi
mov    %ebp,%r8d
xor    %eax,%eax
call   1050 <fprintf@plt>
cmp    $0x1,%r13d
je     11d0 <generate_line+0x80>
mov    $0xa,%edi
mov    %rbx,%rsi
call   1040 <fputc@plt>
jmp    11d0 <generate_line+0x80>

LLVM IR (-O0):
@.str = [4 x i8] c"out\00"
@.str.1 = [3 x i8] c"w+\00"
@.str.2 = [9 x i8] c"1 --> 2\0A\00"
@.str.3 = [11 x i8] c"%d --> %d\0A\00"
@.str.4 = [14 x i8] c"%d --> %d %d\0A\00"
@.str.5 = [2 x i8] c"\0A\00"
define void @generate_line(i32 %0) {
%2 = alloca i32
%3 = alloca i32*
%4 = alloca i32
store i32 %0, i32* %2
%5 = call i32* @fopen(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %5, i32** %3
store i32 1, i32* %4
br label %6
6: ; preds = %43, %1
%7 = load i32, i32* %4
%8 = load i32, i32* %2
%9 = icmp sle i32 %7, %8
br i1 %9, label %10, label %46
10: ; preds = %6
%11 = load i32, i32* %4
%12 = icmp eq i32 %11, 1
br i1 %12, label %13, label %16
13: ; preds = %10
%14 = load i32*, i32** %3
%15 = call i32 (i32*, i8*, ...) @fprintf(i32* %14, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
br label %35
16: ; preds = %10
%17 = load i32, i32* %4
%18 = load i32, i32* %2
%19 = icmp eq i32 %17, %18
br i1 %19, label %20, label %26
20: ; preds = %16
%21 = load i32*, i32** %3
%22 = load i32, i32* %2
%23 = load i32, i32* %2
%24 = sub nsw i32 %23, 1
%25 = call i32 (i32*, i8*, ...) @fprintf(i32* %21, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i32 %22, i32 %24)
br label %34
26: ; preds = %16
%27 = load i32*, i32** %3
%28 = load i32, i32* %4
%29 = load i32, i32* %4
%30 = sub nsw i32 %29, 1
%31 = load i32, i32* %4
%32 = add nsw i32 %31, 1
%33 = call i32 (i32*, i8*, ...) @fprintf(i32* %27, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0), i32 %28, i32 %30, i32 %32)
br label %34
34: ; preds = %26, %20
br label %35
35: ; preds = %34, %13
%36 = load i32, i32* %4
%37 = load i32, i32* %2
%38 = icmp ne i32 %36, %37
br i1 %38, label %39, label %42
39: ; preds = %35
%40 = load i32*, i32** %3
%41 = call i32 (i32*, i8*, ...) @fprintf(i32* %40, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
br label %42
42: ; preds = %39, %35
br label %43
43: ; preds = %42
%44 = load i32, i32* %4
%45 = add nsw i32 %44, 1
store i32 %45, i32* %4
br label %6
46: ; preds = %6
%47 = load i32*, i32** %3
%48 = call i32 @fclose(i32* %47)
ret void
}

LLVM IR (-O2):
@.str = [4 x i8] c"out\00"
@.str.1 = [3 x i8] c"w+\00"
@.str.2 = [9 x i8] c"1 --> 2\0A\00"
@.str.3 = [11 x i8] c"%d --> %d\0A\00"
@.str.4 = [14 x i8] c"%d --> %d %d\0A\00"
define void @generate_line(i32 %0) {
%2 = tail call i32* @fopen(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%3 = icmp slt i32 %0, 1
br i1 %3, label %26, label %4
4: ; preds = %1
%5 = add nsw i32 %0, -1
%6 = tail call i64 @fwrite(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i64 8, i64 1, i32* %2)
%7 = icmp eq i32 %0, 1
br i1 %7, label %26, label %8
8: ; preds = %4
%9 = tail call i32 @fputc(i32 10, i32* %2)
br label %10
10: ; preds = %23, %8
%11 = phi i32 [ 2, %8 ], [ %24, %23 ]
%12 = icmp eq i32 %11, %0
br i1 %12, label %13, label %15
13: ; preds = %10
%14 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %2, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i32 %0, i32 %5)
br label %19
15: ; preds = %10
%16 = add nsw i32 %11, -1
%17 = add nuw nsw i32 %11, 1
%18 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %2, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0), i32 %11, i32 %16, i32 %17)
br label %19
19: ; preds = %13, %15
%20 = icmp eq i32 %11, %0
br i1 %20, label %23, label %21
21: ; preds = %19
%22 = tail call i32 @fputc(i32 10, i32* %2)
br label %23
23: ; preds = %19, %21
%24 = add nuw i32 %11, 1
%25 = icmp eq i32 %11, %0
br i1 %25, label %26, label %10
26: ; preds = %23, %4, %1
%27 = tail call i32 @fclose(i32* %2)
ret void
}