#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 */
scalar_t__ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
scalar_t__ fprintf(int /*<<< orphan*/ *, char *, int, int);
int /*<<< orphan*/ perror(char *);
int map_ids(int out_id, const char *path) {
  FILE *f = fopen(path, "w");
  if (!f) {
    perror("fopen");
    return 1;
  }
  if (fprintf(f, "%d %d 1\n", out_id, out_id) < 0) {
    perror("fprintf");
    return 1;
  }
  if (fclose(f) != 0) {
    perror("fclose");
    return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<map_ids>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xea6(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1186 <map_ids+0x46>
lea    0xe8d(%rip),%rdi
call   1060 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    11f0 <map_ids+0xb0>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%edx
mov    -0x8(%rbp),%ecx
lea    0xe71(%rip),%rsi
call   1040 <fprintf@plt>
cmp    $0x0,%rax
jge    11be <map_ids+0x7e>
lea    0xe64(%rip),%rdi
call   1060 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    11f0 <map_ids+0xb0>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
cmp    $0x0,%rax
je     11e9 <map_ids+0xa9>
lea    0xe41(%rip),%rdi
call   1060 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    11f0 <map_ids+0xb0>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<map_ids>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rax
mov    %edi,%ebp
lea    0xeb1(%rip),%rsi
mov    %rax,%rdi
call   1050 <fopen@plt>
test   %rax,%rax
je     1190 <map_ids+0x50>
mov    %rax,%rbx
lea    0xea2(%rip),%rsi
mov    %rax,%rdi
mov    %ebp,%edx
mov    %ebp,%ecx
call   1040 <fprintf@plt>
test   %rax,%rax
js     1199 <map_ids+0x59>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
jne    11a2 <map_ids+0x62>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xe6b(%rip),%rdi
jmp    11a9 <map_ids+0x69>
lea    0xe71(%rip),%rdi
jmp    11a9 <map_ids+0x69>
lea    0xe70(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%eax
jmp    1189 <map_ids+0x49>

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

LLVM IR (-O2):
@.str = [2 x i8] c"w\00"
@.str.1 = [6 x i8] c"fopen\00"
@.str.2 = [9 x i8] c"%d %d 1\0A\00"
@.str.3 = [8 x i8] c"fprintf\00"
@.str.4 = [7 x i8] c"fclose\00"
define i32 @map_ids(i32 %0, i8* nocapture %1) {
%3 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %11, label %5
5: ; preds = %2
%6 = tail call i64 @fprintf(i32* %3, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 %0, i32 %0)
%7 = icmp slt i64 %6, 0
br i1 %7, label %11, label %8
8: ; preds = %5
%9 = tail call i64 @fclose(i32* %3)
%10 = icmp eq i64 %9, 0
br i1 %10, label %14, label %11
11: ; preds = %8, %5, %2
%12 = phi i8* [ getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), %2 ], [ getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), %5 ], [ getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), %8 ]
%13 = tail call i32 @perror(i8* %12)
br label %14
14: ; preds = %11, %8
%15 = phi i32 [ 0, %8 ], [ 1, %11 ]
ret i32 %15
}