#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*/ die(char *, char *, int, char *, ...);
scalar_t__ push_resource(char *, char *);
scalar_t__ split_resource_name(char *, char **, char **);
int /*<<< orphan*/ strcpy(char *, char *);
int /*<<< orphan*/ strlen(char *);
void mark_resource(char *restag, char *file, int line) {
  char *category;
  char *resource;
  char buf[strlen(restag) + 1];
  strcpy(buf, restag);
  if (split_resource_name(buf, &category, &resource))
    die("%s:%i: bad resource name %s\n", file, line, restag);
  if (push_resource(category, resource))
    die("%s:%i: duplicate resource %s %s\n", file, line, category, resource);
}


x86 assembly (clang, -O0):
<mark_resource>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
add    $0x1,%eax
mov    %rsp,%rcx
mov    %rcx,-0x30(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x40(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x38(%rbp)
mov    -0x8(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x40(%rbp),%rdi
lea    -0x20(%rbp),%rsi
lea    -0x28(%rbp),%rdx
call   1050 <split_resource_name@plt>
cmp    $0x0,%rax
je     11cf <mark_resource+0x7f>
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
mov    -0x8(%rbp),%rcx
lea    0xe38(%rip),%rdi
mov    $0x0,%al
call   1070 <die@plt>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1060 <push_resource@plt>
cmp    $0x0,%rax
je     1203 <mark_resource+0xb3>
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
mov    -0x20(%rbp),%rcx
mov    -0x28(%rbp),%r8
lea    0xe21(%rip),%rdi
mov    $0x0,%al
call   1070 <die@plt>
mov    -0x30(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mark_resource>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %edx,%r14d
mov    %rsi,%r15
mov    %rdi,%r12
call   1040 <strlen@plt>
mov    %rsp,%r13
add    $0x1,%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %rbx,%rdi
mov    %r12,%rsi
call   1030 <strcpy@plt>
lea    -0x38(%rbp),%rsi
lea    -0x30(%rbp),%rdx
mov    %rbx,%rdi
call   1050 <split_resource_name@plt>
test   %rax,%rax
je     11bd <mark_resource+0x6d>
lea    0xe53(%rip),%rdi
mov    %r15,%rsi
mov    %r14d,%edx
mov    %r12,%rcx
xor    %eax,%eax
call   1070 <die@plt>
mov    -0x38(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1060 <push_resource@plt>
test   %rax,%rax
je     11eb <mark_resource+0x9b>
mov    -0x38(%rbp),%rcx
mov    -0x30(%rbp),%r8
lea    0xe3f(%rip),%rdi
mov    %r15,%rsi
mov    %r14d,%edx
xor    %eax,%eax
call   1070 <die@plt>
mov    %r13,%rsp
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [29 x i8] c"%s:%i: bad resource name %s\0A\00"
@.str.1 = [33 x i8] c"%s:%i: duplicate resource %s %s\0A\00"
define void @mark_resource(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i64
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%11 = load i8*, i8** %4
%12 = call i32 @strlen(i8* %11)
%13 = add nsw i32 %12, 1
%14 = zext i32 %13 to i64
%15 = call i8* @llvm.stacksave()
store i8* %15, i8** %9
%16 = alloca i8, i64 %14
store i64 %14, i64* %10
%17 = load i8*, i8** %4
%18 = call i32 @strcpy(i8* %16, i8* %17)
%19 = call i64 @split_resource_name(i8* %16, i8** %7, i8** %8)
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %26
21: ; preds = %3
%22 = load i8*, i8** %5
%23 = load i32, i32* %6
%24 = load i8*, i8** %4
%25 = call i32 (i8*, i8*, i32, i8*, ...) @die(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* %22, i32 %23, i8* %24)
br label %26
26: ; preds = %21, %3
%27 = load i8*, i8** %7
%28 = load i8*, i8** %8
%29 = call i64 @push_resource(i8* %27, i8* %28)
%30 = icmp ne i64 %29, 0
br i1 %30, label %31, label %37
31: ; preds = %26
%32 = load i8*, i8** %5
%33 = load i32, i32* %6
%34 = load i8*, i8** %7
%35 = load i8*, i8** %8
%36 = call i32 (i8*, i8*, i32, i8*, ...) @die(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i8* %32, i32 %33, i8* %34, i8* %35)
br label %37
37: ; preds = %31, %26
%38 = load i8*, i8** %9
ret void
}

LLVM IR (-O2):
@.str = [29 x i8] c"%s:%i: bad resource name %s\0A\00"
@.str.1 = [33 x i8] c"%s:%i: duplicate resource %s %s\0A\00"
define void @mark_resource(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = bitcast i8** %4 to i8*
%7 = bitcast i8** %5 to i8*
%8 = tail call i32 @strlen(i8* %0)
%9 = add nsw i32 %8, 1
%10 = zext i32 %9 to i64
%11 = tail call i8* @llvm.stacksave()
%12 = alloca i8, i64 %10
%13 = call i32 @strcpy(i8* %12, i8* %0)
%14 = call i64 @split_resource_name(i8* %12, i8** %4, i8** %5)
%15 = icmp eq i64 %14, 0
br i1 %15, label %18, label %16
16: ; preds = %3
%17 = call i32 (i8*, i8*, i32, i8*, ...) @die(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* %1, i32 %2, i8* %0)
br label %18
18: ; preds = %16, %3
%19 = load i8*, i8** %4
%20 = load i8*, i8** %5
%21 = call i64 @push_resource(i8* %19, i8* %20)
%22 = icmp eq i64 %21, 0
br i1 %22, label %27, label %23
23: ; preds = %18
%24 = load i8*, i8** %4
%25 = load i8*, i8** %5
%26 = call i32 (i8*, i8*, i32, i8*, ...) @die(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i8* %1, i32 %2, i8* %24, i8* %25)
br label %27
27: ; preds = %23, %18
ret void
}