#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_circle(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 %d\n", len);
    } else if (i == len) {
      fprintf(f, "%d --> %d 1\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_circle>:
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     120e <generate_circle+0xde>
cmpl   $0x1,-0x14(%rbp)
jne    1189 <generate_circle+0x59>
mov    -0x10(%rbp),%rdi
mov    -0x4(%rbp),%edx
lea    0xe8a(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
jmp    11dd <generate_circle+0xad>
mov    -0x14(%rbp),%eax
cmp    -0x4(%rbp),%eax
jne    11b5 <generate_circle+0x85>
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    11d8 <generate_circle+0xa8>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%edx
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
mov    -0x14(%rbp),%r8d
add    $0x1,%r8d
lea    0xe4f(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
jmp    11dd <generate_circle+0xad>
mov    -0x14(%rbp),%eax
cmp    -0x4(%rbp),%eax
je     11fb <generate_circle+0xcb>
mov    -0x10(%rbp),%rdi
lea    0xe2a(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
jmp    1200 <generate_circle+0xd0>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1159 <generate_circle+0x29>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<generate_circle>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edi,%r15d
lea    0xeab(%rip),%rdi
lea    0xea8(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%rbx
test   %r15d,%r15d
jle    1183 <generate_circle+0x43>
lea    0xe97(%rip),%rsi
mov    %rbx,%rdi
mov    %r15d,%edx
xor    %eax,%eax
call   1050 <fprintf@plt>
cmp    $0x1,%r15d
jne    1199 <generate_circle+0x59>
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    11d3 <generate_circle+0x93>
nopw   0x0(%rax,%rax,1)
lea    (%r14,%rbp,1),%eax
add    $0x1,%eax
mov    %ebp,%ecx
add    $0x1,%ecx
mov    %ecx,%ebp
cmp    $0x2,%eax
je     1183 <generate_circle+0x43>
lea    (%r14,%rbp,1),%r13d
cmp    $0x1,%r13d
jne    1200 <generate_circle+0xc0>
mov    %rbx,%rdi
lea    0xe2c(%rip),%rsi
mov    %r15d,%edx
mov    %r12d,%ecx
xor    %eax,%eax
call   1050 <fprintf@plt>
cmp    $0x1,%r13d
je     11c0 <generate_circle+0x80>
jmp    1220 <generate_circle+0xe0>
nopl   0x0(%rax)
lea    -0x1(%rbp),%edx
lea    -0x2(%rbp),%ecx
mov    %rbx,%rdi
lea    0xe10(%rip),%rsi
mov    %ebp,%r8d
xor    %eax,%eax
call   1050 <fprintf@plt>
cmp    $0x1,%r13d
je     11c0 <generate_circle+0x80>
mov    $0xa,%edi
mov    %rbx,%rsi
call   1040 <fputc@plt>
jmp    11c0 <generate_circle+0x80>

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

LLVM IR (-O2):
@.str = [4 x i8] c"out\00"
@.str.1 = [3 x i8] c"w+\00"
@.str.2 = [12 x i8] c"1 --> 2 %d\0A\00"
@.str.3 = [13 x i8] c"%d --> %d 1\0A\00"
@.str.4 = [14 x i8] c"%d --> %d %d\0A\00"
define void @generate_circle(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 i32 (i32*, i8*, ...) @fprintf(i32* %2, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32 %0)
%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 ([13 x i8], [13 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
}