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

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, int);
int /*<<< orphan*/ printf(char *);
int do_task(int max, FILE *record_fp) {
  int idx;
  if (!record_fp) {
    printf("NULL record_fp!\n");
    return -1;
  }
  for (idx = 0; idx < max; idx++)
    fprintf(record_fp, "(%d)", idx + 1);
  fclose(record_fp);
  return 0;
}


x86 assembly (clang, -O0):
<do_task>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1162 <do_task+0x32>
lea    0xeaf(%rip),%rdi
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11a9 <do_task+0x79>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1199 <do_task+0x69>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%edx
add    $0x1,%edx
lea    0xe8b(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1169 <do_task+0x39>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_task>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
test   %rsi,%rsi
je     118c <do_task+0x5c>
mov    %rsi,%r14
mov    %edi,%r12d
test   %edi,%edi
jle    1180 <do_task+0x50>
neg    %r12d
mov    $0x1,%ebx
lea    0xeaa(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %r15,%rsi
mov    %ebx,%edx
call   1050 <fprintf@plt>
lea    (%r12,%rbx,1),%eax
add    $0x1,%eax
mov    %ebx,%ecx
add    $0x1,%ecx
mov    %ecx,%ebx
cmp    $0x1,%eax
jne    1160 <do_task+0x30>
mov    %r14,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
jmp    119d <do_task+0x6d>
lea    0xe72(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [17 x i8] c"NULL record_fp!\0A\00"
@.str.1 = [5 x i8] c"(%d)\00"
define i32 @do_task(i32 %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32
store i32 %0, i32* %4
store i32* %1, i32** %5
%7 = load i32*, i32** %5
%8 = icmp ne i32* %7, null
br i1 %8, label %11, label %9
9: ; preds = %2
%10 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %27
11: ; preds = %2
store i32 0, i32* %6
br label %12
12: ; preds = %21, %11
%13 = load i32, i32* %6
%14 = load i32, i32* %4
%15 = icmp slt i32 %13, %14
br i1 %15, label %16, label %24
16: ; preds = %12
%17 = load i32*, i32** %5
%18 = load i32, i32* %6
%19 = add nsw i32 %18, 1
%20 = call i32 @fprintf(i32* %17, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %19)
br label %21
21: ; preds = %16
%22 = load i32, i32* %6
%23 = add nsw i32 %22, 1
store i32 %23, i32* %6
br label %12
24: ; preds = %12
%25 = load i32*, i32** %5
%26 = call i32 @fclose(i32* %25)
store i32 0, i32* %3
br label %27
27: ; preds = %24, %9
%28 = load i32, i32* %3
ret i32 %28
}

LLVM IR (-O2):
@.str.1 = [5 x i8] c"(%d)\00"
@str = [16 x i8] c"NULL record_fp!\00"
define i32 @do_task(i32 %0, i32* %1) {
%3 = icmp eq i32* %1, null
br i1 %3, label %6, label %4
4: ; preds = %2
%5 = icmp sgt i32 %0, 0
br i1 %5, label %8, label %13
6: ; preds = %2
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str, i64 0, i64 0))
br label %15
8: ; preds = %4, %8
%9 = phi i32 [ %10, %8 ], [ 0, %4 ]
%10 = add nuw nsw i32 %9, 1
%11 = tail call i32 @fprintf(i32* %1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %10)
%12 = icmp eq i32 %10, %0
br i1 %12, label %13, label %8
13: ; preds = %8, %4
%14 = tail call i32 @fclose(i32* %1)
br label %15
15: ; preds = %13, %6
%16 = phi i32 [ 0, %13 ], [ -1, %6 ]
ret i32 %16
}