#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*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ get_line(int /*<<< orphan*/ *, char **, char **);
scalar_t__ isspace(char);
int /*<<< orphan*/ new_unique_id(char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ strcmp(char *, char *);
int strlen(char *);
int /*<<< orphan*/ unlink(char *);
int main(int n, char **v) {
  FILE *in;
  FILE *out;
  char *name;
  char *value;
  char *in_name;
  char *out_name;
  if (n != 3) {
    printf("gimme <source> <dest>\n");
    exit(1);
  }
  n = 0;
  in_name = v[1];
  out_name = v[2];
  in = fopen(in_name, "r");
  if (in == NULL) {
    perror(in_name);
    exit(1);
  }
  out = fopen(out_name, "w");
  if (out == NULL) {
    perror(out_name);
    exit(1);
  }
  fprintf(out, "/* generated file, do not edit by hand */\n\n");
  while (1) {
    get_line(in, &name, &value);
    if (name == NULL)
      break;
    printf("name '%s' value '%s'\n", name, value);
    if (isspace(value[strlen(value) - 1])) {
      printf("bad value '%s' (no space at the end please!)\n", value);
      unlink(out_name);
      exit(1);
    }
    if (!strcmp(name, "ID")) {
      if (!new_unique_id(value)) {
        unlink(out_name);
        exit(1);
      }
      fprintf(out, "#define T_%s T_ID(%d)\n", value, n);
      n++;
    }
  }
  fprintf(out, "#define T_NUMBER_OF_IDS %d\n", n);
  fclose(in);
  fclose(out);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     11f8 <main+0x38>
lea    0xe19(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
movl   $0x0,-0x8(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x40(%rbp)
mov    -0x38(%rbp),%rdi
lea    0xdf5(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1249 <main+0x89>
mov    -0x38(%rbp),%rdi
call   10c0 <perror@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
mov    -0x40(%rbp),%rdi
lea    0xdc5(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    127b <main+0xbb>
mov    -0x40(%rbp),%rdi
call   10c0 <perror@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
mov    -0x20(%rbp),%rdi
lea    0xd95(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
mov    -0x18(%rbp),%rdi
lea    -0x28(%rbp),%rsi
lea    -0x30(%rbp),%rdx
call   1040 <get_line@plt>
cmpq   $0x0,-0x28(%rbp)
jne    12ae <main+0xee>
jmp    137e <main+0x1be>
mov    -0x28(%rbp),%rsi
mov    -0x30(%rbp),%rdx
lea    0xd8a(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x30(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x30(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,%ecx
mov    -0x48(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%edi
call   1080 <isspace@plt>
cmp    $0x0,%rax
je     1319 <main+0x159>
mov    -0x30(%rbp),%rsi
lea    0xd5e(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x40(%rbp),%rdi
call   1030 <unlink@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
mov    -0x28(%rbp),%rdi
lea    0xd67(%rip),%rsi
call   1090 <strcmp@plt>
cmp    $0x0,%eax
jne    1379 <main+0x1b9>
mov    -0x30(%rbp),%rdi
call   10e0 <new_unique_id@plt>
cmp    $0x0,%eax
jne    1357 <main+0x197>
mov    -0x40(%rbp),%rdi
call   1030 <unlink@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
mov    -0x20(%rbp),%rdi
mov    -0x30(%rbp),%rdx
mov    -0x8(%rbp),%ecx
lea    0xd25(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    128d <main+0xcd>
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%edx
lea    0xd19(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1050 <fclose@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
cmp    $0x3,%edi
jne    137d <main+0x19d>
mov    0x8(%rsi),%rbp
mov    0x10(%rsi),%r14
lea    0xdfa(%rip),%rsi
mov    %rbp,%rdi
call   10c0 <fopen@plt>
test   %rax,%rax
je     1393 <main+0x1b3>
mov    %rax,%rbx
lea    0xde1(%rip),%rsi
mov    %r14,%rdi
call   10c0 <fopen@plt>
test   %rax,%rax
je     1398 <main+0x1b8>
lea    0xdcb(%rip),%rdi
mov    $0x2b,%esi
mov    $0x1,%edx
mov    %rax,0x20(%rsp)
mov    %rax,%rcx
call   10f0 <fwrite@plt>
lea    0x10(%rsp),%rsi
lea    0x8(%rsp),%rdx
mov    %rbx,%rdi
call   1050 <get_line@plt>
mov    0x10(%rsp),%rsi
test   %rsi,%rsi
je     131b <main+0x13b>
mov    %r14,0x18(%rsp)
lea    0xdf8(%rip),%r13
lea    0x10(%rsp),%r14
lea    0x8(%rsp),%r15
xor    %ebp,%ebp
jmp    12a8 <main+0xc8>
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   1050 <get_line@plt>
mov    0x10(%rsp),%rsi
test   %rsi,%rsi
je     131d <main+0x13d>
mov    0x8(%rsp),%rdx
lea    0xd7c(%rip),%rdi
xor    %eax,%eax
call   1080 <printf@plt>
mov    0x8(%rsp),%r12
mov    %r12,%rdi
call   1070 <strlen@plt>
cltq
movsbl -0x1(%rax,%r12,1),%edi
call   1090 <isspace@plt>
test   %rax,%rax
jne    1356 <main+0x176>
mov    0x10(%rsp),%rdi
mov    %r13,%rsi
call   10a0 <strcmp@plt>
test   %eax,%eax
jne    1290 <main+0xb0>
mov    0x8(%rsp),%rdi
call   1100 <new_unique_id@plt>
test   %eax,%eax
je     1369 <main+0x189>
mov    0x8(%rsp),%rdx
mov    0x20(%rsp),%rdi
lea    0xd6d(%rip),%rsi
mov    %ebp,%ecx
xor    %eax,%eax
call   10b0 <fprintf@plt>
add    $0x1,%ebp
jmp    1290 <main+0xb0>
xor    %ebp,%ebp
lea    0xd6a(%rip),%rsi
mov    0x20(%rsp),%r14
mov    %r14,%rdi
mov    %ebp,%edx
xor    %eax,%eax
call   10b0 <fprintf@plt>
mov    %rbx,%rdi
call   1060 <fclose@plt>
mov    %r14,%rdi
call   1060 <fclose@plt>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x8(%rsp),%rsi
lea    0xce4(%rip),%rdi
xor    %eax,%eax
call   1080 <printf@plt>
mov    0x18(%rsp),%rdi
call   1030 <unlink@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
lea    0xd26(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
mov    %rbp,%rdi
jmp    139b <main+0x1bb>
mov    %r14,%rdi
call   10d0 <perror@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>

LLVM IR (-O0):
@.str = [23 x i8] c"gimme <source> <dest>\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [2 x i8] c"w\00"
@.str.3 = [44 x i8] c"/* generated file, do not edit by hand */\0A\0A\00"
@.str.4 = [22 x i8] c"name '%s' value '%s'\0A\00"
@.str.5 = [46 x i8] c"bad value '%s' (no space at the end please!)\0A\00"
@.str.6 = [3 x i8] c"ID\00"
@.str.7 = [23 x i8] c"#define T_%s T_ID(%d)\0A\00"
@.str.8 = [28 x i8] c"#define T_NUMBER_OF_IDS %d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = load i32, i32* %4
%13 = icmp ne i32 %12, 3
br i1 %13, label %14, label %17
14: ; preds = %2
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%16 = call i32 @exit(i32 1)
unreachable
17: ; preds = %2
store i32 0, i32* %4
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
store i8* %20, i8** %10
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 2
%23 = load i8*, i8** %22
store i8* %23, i8** %11
%24 = load i8*, i8** %10
%25 = call i32* @fopen(i8* %24, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %25, i32** %6
%26 = load i32*, i32** %6
%27 = icmp eq i32* %26, null
br i1 %27, label %28, label %32
28: ; preds = %17
%29 = load i8*, i8** %10
%30 = call i32 @perror(i8* %29)
%31 = call i32 @exit(i32 1)
unreachable
32: ; preds = %17
%33 = load i8*, i8** %11
%34 = call i32* @fopen(i8* %33, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %34, i32** %7
%35 = load i32*, i32** %7
%36 = icmp eq i32* %35, null
br i1 %36, label %37, label %41
37: ; preds = %32
%38 = load i8*, i8** %11
%39 = call i32 @perror(i8* %38)
%40 = call i32 @exit(i32 1)
unreachable
41: ; preds = %32
%42 = load i32*, i32** %7
%43 = call i32 (i32*, i8*, ...) @fprintf(i32* %42, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.3, i64 0, i64 0))
br label %44
44: ; preds = %41, %88
%45 = load i32*, i32** %6
%46 = call i32 @get_line(i32* %45, i8** %8, i8** %9)
%47 = load i8*, i8** %8
%48 = icmp eq i8* %47, null
br i1 %48, label %49, label %50
49: ; preds = %44
br label %89
50: ; preds = %44
%51 = load i8*, i8** %8
%52 = load i8*, i8** %9
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0), i8* %51, i8* %52)
%54 = load i8*, i8** %9
%55 = load i8*, i8** %9
%56 = call i32 @strlen(i8* %55)
%57 = sub nsw i32 %56, 1
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds i8, i8* %54, i64 %58
%60 = load i8, i8* %59
%61 = call i64 @isspace(i8 signext %60)
%62 = icmp ne i64 %61, 0
br i1 %62, label %63, label %69
63: ; preds = %50
%64 = load i8*, i8** %9
%65 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.5, i64 0, i64 0), i8* %64)
%66 = load i8*, i8** %11
%67 = call i32 @unlink(i8* %66)
%68 = call i32 @exit(i32 1)
unreachable
69: ; preds = %50
%70 = load i8*, i8** %8
%71 = call i32 @strcmp(i8* %70, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0))
%72 = icmp ne i32 %71, 0
br i1 %72, label %88, label %73
73: ; preds = %69
%74 = load i8*, i8** %9
%75 = call i32 @new_unique_id(i8* %74)
%76 = icmp ne i32 %75, 0
br i1 %76, label %81, label %77
77: ; preds = %73
%78 = load i8*, i8** %11
%79 = call i32 @unlink(i8* %78)
%80 = call i32 @exit(i32 1)
unreachable
81: ; preds = %73
%82 = load i32*, i32** %7
%83 = load i8*, i8** %9
%84 = load i32, i32* %4
%85 = call i32 (i32*, i8*, ...) @fprintf(i32* %82, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.7, i64 0, i64 0), i8* %83, i32 %84)
%86 = load i32, i32* %4
%87 = add nsw i32 %86, 1
store i32 %87, i32* %4
br label %88
88: ; preds = %81, %69
br label %44
89: ; preds = %49
%90 = load i32*, i32** %7
%91 = load i32, i32* %4
%92 = call i32 (i32*, i8*, ...) @fprintf(i32* %90, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.8, i64 0, i64 0), i32 %91)
%93 = load i32*, i32** %6
%94 = call i32 @fclose(i32* %93)
%95 = load i32*, i32** %7
%96 = call i32 @fclose(i32* %95)
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [2 x i8] c"w\00"
@.str.3 = [44 x i8] c"/* generated file, do not edit by hand */\0A\0A\00"
@.str.4 = [22 x i8] c"name '%s' value '%s'\0A\00"
@.str.5 = [46 x i8] c"bad value '%s' (no space at the end please!)\0A\00"
@.str.6 = [3 x i8] c"ID\00"
@.str.7 = [23 x i8] c"#define T_%s T_ID(%d)\0A\00"
@.str.8 = [28 x i8] c"#define T_NUMBER_OF_IDS %d\0A\00"
@str = [22 x i8] c"gimme <source> <dest>\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = bitcast i8** %3 to i8*
%6 = bitcast i8** %4 to i8*
%7 = icmp eq i32 %0, 3
br i1 %7, label %11, label %8
8: ; preds = %2
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str, i64 0, i64 0))
%10 = tail call i32 @exit(i32 1)
unreachable
11: ; preds = %2
%12 = getelementptr inbounds i8*, i8** %1, i64 1
%13 = load i8*, i8** %12
%14 = getelementptr inbounds i8*, i8** %1, i64 2
%15 = load i8*, i8** %14
%16 = tail call i32* @fopen(i8* %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%17 = icmp eq i32* %16, null
br i1 %17, label %18, label %21
18: ; preds = %11
%19 = tail call i32 @perror(i8* %13)
%20 = tail call i32 @exit(i32 1)
unreachable
21: ; preds = %11
%22 = tail call i32* @fopen(i8* %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%23 = icmp eq i32* %22, null
br i1 %23, label %24, label %27
24: ; preds = %21
%25 = tail call i32 @perror(i8* %15)
%26 = tail call i32 @exit(i32 1)
unreachable
27: ; preds = %21
%28 = tail call i64 @fwrite(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.3, i64 0, i64 0), i64 43, i64 1, i32* %22)
%29 = call i32 @get_line(i32* %16, i8** %3, i8** %4)
%30 = load i8*, i8** %3
%31 = icmp eq i8* %30, null
br i1 %31, label %70, label %32
32: ; preds = %27, %65
%33 = phi i8* [ %68, %65 ], [ %30, %27 ]
%34 = phi i32 [ %66, %65 ], [ 0, %27 ]
%35 = load i8*, i8** %4
%36 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0), i8* %33, i8* %35)
%37 = load i8*, i8** %4
%38 = call i32 @strlen(i8* %37)
%39 = add nsw i32 %38, -1
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i8, i8* %37, i64 %40
%42 = load i8, i8* %41
%43 = call i64 @isspace(i8 signext %42)
%44 = icmp eq i64 %43, 0
br i1 %44, label %50, label %45
45: ; preds = %32
%46 = load i8*, i8** %4
%47 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @.str.5, i64 0, i64 0), i8* %46)
%48 = call i32 @unlink(i8* %15)
%49 = call i32 @exit(i32 1)
unreachable
50: ; preds = %32
%51 = load i8*, i8** %3
%52 = call i32 @strcmp(i8* dereferenceable(1) %51, i8* dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0))
%53 = icmp eq i32 %52, 0
br i1 %53, label %54, label %65
54: ; preds = %50
%55 = load i8*, i8** %4
%56 = call i32 @new_unique_id(i8* %55)
%57 = icmp eq i32 %56, 0
br i1 %57, label %58, label %61
58: ; preds = %54
%59 = call i32 @unlink(i8* %15)
%60 = call i32 @exit(i32 1)
unreachable
61: ; preds = %54
%62 = load i8*, i8** %4
%63 = call i32 (i32*, i8*, ...) @fprintf(i32* %22, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.7, i64 0, i64 0), i8* %62, i32 %34)
%64 = add nsw i32 %34, 1
br label %65
65: ; preds = %61, %50
%66 = phi i32 [ %34, %50 ], [ %64, %61 ]
%67 = call i32 @get_line(i32* %16, i8** %3, i8** %4)
%68 = load i8*, i8** %3
%69 = icmp eq i8* %68, null
br i1 %69, label %70, label %32
70: ; preds = %65, %27
%71 = phi i32 [ 0, %27 ], [ %66, %65 ]
%72 = call i32 (i32*, i8*, ...) @fprintf(i32* %22, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.8, i64 0, i64 0), i32 %71)
%73 = call i32 @fclose(i32* %16)
%74 = call i32 @fclose(i32* %22)
ret i32 0
}