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

/* Variables and functions */
int /*<<< orphan*/ error_msg(char *);
int /*<<< orphan*/ free(char *);
char **id_to_fmt(unsigned int);
int /*<<< orphan*/ track_format_valid(char const *);
int /*<<< orphan*/ update_full();
char *xstrdup(char const *);
void set_format(unsigned int id, const char *buf) {
  char **fmtp = id_to_fmt(id);
  if (!track_format_valid(buf)) {
    error_msg("invalid format string");
    return;
  }
  free(*fmtp);
  *fmtp = xstrdup(buf);
  update_full();
}


x86 assembly (clang, -O0):
<set_format>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x4(%rbp),%edi
call   1080 <id_to_fmt@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <track_format_valid@plt>
cmp    $0x0,%eax
jne    119e <set_format+0x3e>
lea    0xe6c(%rip),%rdi
call   1040 <error_msg@plt>
jmp    11c4 <set_format+0x64>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
call   1030 <free@plt>
mov    -0x10(%rbp),%rdi
call   1050 <xstrdup@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    $0x0,%al
call   1070 <update_full@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_format>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
call   1080 <id_to_fmt@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   1060 <track_format_valid@plt>
test   %eax,%eax
je     119c <set_format+0x3c>
mov    (%r14),%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
call   1050 <xstrdup@plt>
mov    %rax,(%r14)
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1070 <update_full@plt>
lea    0xe5d(%rip),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1040 <error_msg@plt>

LLVM IR (-O0):
@.str = [22 x i8] c"invalid format string\00"
define void @set_format(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8**
store i32 %0, i32* %3
store i8* %1, i8** %4
%6 = load i32, i32* %3
%7 = call i8** @id_to_fmt(i32 %6)
store i8** %7, i8*** %5
%8 = load i8*, i8** %4
%9 = call i32 @track_format_valid(i8* %8)
%10 = icmp ne i32 %9, 0
br i1 %10, label %13, label %11
11: ; preds = %2
%12 = call i32 @error_msg(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
br label %21
13: ; preds = %2
%14 = load i8**, i8*** %5
%15 = load i8*, i8** %14
%16 = call i32 @free(i8* %15)
%17 = load i8*, i8** %4
%18 = call i8* @xstrdup(i8* %17)
%19 = load i8**, i8*** %5
store i8* %18, i8** %19
%20 = call i32 (...) @update_full()
br label %21
21: ; preds = %13, %11
ret void
}

LLVM IR (-O2):
@.str = [22 x i8] c"invalid format string\00"
define void @set_format(i32 %0, i8* %1) {
%3 = tail call i8** @id_to_fmt(i32 %0)
%4 = tail call i32 @track_format_valid(i8* %1)
%5 = icmp eq i32 %4, 0
br i1 %5, label %6, label %8
6: ; preds = %2
%7 = tail call i32 @error_msg(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
br label %13
8: ; preds = %2
%9 = load i8*, i8** %3
%10 = tail call i32 @free(i8* %9)
%11 = tail call i8* @xstrdup(i8* %1)
store i8* %11, i8** %3
%12 = tail call i32 (...) @update_full()
br label %13
13: ; preds = %8, %6
ret void
}