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

/* Variables and functions */
int /*<<< orphan*/ O_WRONLY;
int PATH_MAX;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ error(char *, char *, char *, ...);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ snprintf(char *, int, char *, int, int);
char *strerror(int /*<<< orphan*/);
int /*<<< orphan*/ strlen(char *);
int write(int, char *, int /*<<< orphan*/);
void update_id(char *filename, int id_old, int id_new) {
  int status;
  char cmdline[PATH_MAX];
  int fd = open(filename, O_WRONLY);
  if (fd >= 0) {
    snprintf(cmdline, sizeof(cmdline), "%d %d 1", id_new, id_old);
    status = write(fd, cmdline, strlen(cmdline));
    close(fd);
    if (status < 0)
      error("write of %s in %s failed with error: %s\n", cmdline, filename,
            strerror(errno));
  } else
    error("open of %s failed with error: %s\n", filename, strerror(errno));
}


x86 assembly (clang, -O0):
<update_id>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    0x2e67(%rip),%rax
mov    (%rax),%eax
mov    %rax,-0x40(%rbp)
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x38(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
mov    0x2e0b(%rip),%rax
mov    (%rax),%esi
call   1080 <open@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jl     1254 <update_id+0xe4>
mov    -0x38(%rbp),%rdi
mov    -0x40(%rbp),%rax
mov    %eax,%esi
mov    -0x10(%rbp),%ecx
mov    -0xc(%rbp),%r8d
lea    0xe17(%rip),%rdx
call   1050 <snprintf@plt>
mov    -0x38(%rbp),%rdi
mov    -0x2c(%rbp),%eax
mov    %eax,-0x44(%rbp)
call   1040 <strlen@plt>
mov    -0x44(%rbp),%edi
mov    -0x38(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %eax,-0x14(%rbp)
mov    -0x2c(%rbp),%edi
call   1060 <close@plt>
cmpl   $0x0,-0x14(%rbp)
jge    124f <update_id+0xdf>
mov    -0x8(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    0x2da9(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x38(%rbp),%rsi
mov    -0x50(%rbp),%rdx
mov    %rax,%rcx
lea    0xdc0(%rip),%rdi
mov    $0x0,%al
call   1070 <error@plt>
jmp    127f <update_id+0x10f>
mov    -0x8(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    0x2d75(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x58(%rbp),%rsi
mov    %rax,%rdx
lea    0xdb9(%rip),%rdi
mov    $0x0,%al
call   1070 <error@plt>
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<update_id>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %edx,%r12d
mov    %esi,-0x2c(%rbp)
mov    %rdi,%r15
mov    0x2e5f(%rip),%rax
mov    (%rax),%r14d
mov    %rsp,%rbx
lea    0xf(%r14),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    0x2e1c(%rip),%rax
mov    (%rax),%esi
call   1080 <open@plt>
test   %eax,%eax
js     1231 <update_id+0xc1>
mov    %eax,%r13d
mov    %r15,-0x38(%rbp)
lea    0xe3b(%rip),%rdx
mov    %rbx,%rdi
mov    %r14d,%esi
mov    %r12d,%ecx
mov    -0x2c(%rbp),%r8d
call   1050 <snprintf@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %r13d,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %eax,%r14d
mov    %r13d,%edi
call   1060 <close@plt>
test   %r14d,%r14d
jns    1222 <update_id+0xb2>
mov    0x2dd5(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
lea    0xdf7(%rip),%rdi
mov    %rbx,%rsi
mov    -0x38(%rbp),%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1070 <error@plt>
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2da0(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
lea    0xdeb(%rip),%rdi
mov    %r15,%rsi
mov    %rax,%rdx
xor    %eax,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1070 <error@plt>

LLVM IR (-O0):
@PATH_MAX = global i32 0
@O_WRONLY = global i32 0
@.str = [8 x i8] c"%d %d 1\00"
@.str.1 = [41 x i8] c"write of %s in %s failed with error: %s\0A\00"
@errno = global i32 0
@.str.2 = [34 x i8] c"open of %s failed with error: %s\0A\00"
define void @update_id(i8* %0, i32 %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%11 = load i32, i32* @PATH_MAX
%12 = zext i32 %11 to i64
%13 = call i8* @llvm.stacksave()
store i8* %13, i8** %8
%14 = alloca i8, i64 %12
store i64 %12, i64* %9
%15 = load i8*, i8** %4
%16 = load i32, i32* @O_WRONLY
%17 = call i32 @open(i8* %15, i32 %16)
store i32 %17, i32* %10
%18 = load i32, i32* %10
%19 = icmp sge i32 %18, 0
br i1 %19, label %20, label %38
20: ; preds = %3
%21 = trunc i64 %12 to i32
%22 = load i32, i32* %6
%23 = load i32, i32* %5
%24 = call i32 @snprintf(i8* %14, i32 %21, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %22, i32 %23)
%25 = load i32, i32* %10
%26 = call i32 @strlen(i8* %14)
%27 = call i32 @write(i32 %25, i8* %14, i32 %26)
store i32 %27, i32* %7
%28 = load i32, i32* %10
%29 = call i32 @close(i32 %28)
%30 = load i32, i32* %7
%31 = icmp slt i32 %30, 0
br i1 %31, label %32, label %37
32: ; preds = %20
%33 = load i8*, i8** %4
%34 = load i32, i32* @errno
%35 = call i8* @strerror(i32 %34)
%36 = call i32 (i8*, i8*, i8*, ...) @error(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0), i8* %14, i8* %33, i8* %35)
br label %37
37: ; preds = %32, %20
br label %43
38: ; preds = %3
%39 = load i8*, i8** %4
%40 = load i32, i32* @errno
%41 = call i8* @strerror(i32 %40)
%42 = call i32 (i8*, i8*, i8*, ...) @error(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0), i8* %39, i8* %41)
br label %43
43: ; preds = %38, %37
%44 = load i8*, i8** %8
ret void
}

LLVM IR (-O2):
@PATH_MAX = global i32 0
@O_WRONLY = global i32 0
@.str = [8 x i8] c"%d %d 1\00"
@.str.1 = [41 x i8] c"write of %s in %s failed with error: %s\0A\00"
@errno = global i32 0
@.str.2 = [34 x i8] c"open of %s failed with error: %s\0A\00"
define void @update_id(i8* %0, i32 %1, i32 %2) {
%4 = load i32, i32* @PATH_MAX
%5 = zext i32 %4 to i64
%6 = alloca i8, i64 %5
%7 = load i32, i32* @O_WRONLY
%8 = tail call i32 @open(i8* %0, i32 %7)
%9 = icmp sgt i32 %8, -1
br i1 %9, label %10, label %20
10: ; preds = %3
%11 = call i32 @snprintf(i8* %6, i32 %4, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %2, i32 %1)
%12 = call i32 @strlen(i8* %6)
%13 = call i32 @write(i32 %8, i8* %6, i32 %12)
%14 = call i32 @close(i32 %8)
%15 = icmp slt i32 %13, 0
br i1 %15, label %16, label %24
16: ; preds = %10
%17 = load i32, i32* @errno
%18 = call i8* @strerror(i32 %17)
%19 = call i32 (i8*, i8*, i8*, ...) @error(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0), i8* %6, i8* %0, i8* %18)
br label %24
20: ; preds = %3
%21 = load i32, i32* @errno
%22 = tail call i8* @strerror(i32 %21)
%23 = tail call i32 (i8*, i8*, i8*, ...) @error(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0), i8* %0, i8* %22)
br label %24
24: ; preds = %10, %16, %20
ret void
}