#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*/ error(char *);
scalar_t__ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, char *, char *, int *);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ strcmp(char *, char *);
void convert(FILE *mnemfile, FILE *itemfile) {
  char mnem1[20], mnem2[20], def[20], itemtype[20];
  int newcl, opc, index;
  newcl = 1;
  printf("struct item_descr itemtab[] = {\n");
  for (;;) {
    fscanf(mnemfile, "%s%s%d", def, mnem1, &opc);
    if (feof(mnemfile))
      break;
    if (strcmp(def, "#define") != 0) {
      error("bad mnemonic file, #define expected");
    }
    if (newcl) {
      fscanf(itemfile, "%s%s%d", mnem2, itemtype, &index);
    }
    if (feof(itemfile) || strcmp(mnem1, mnem2) != 0) {
      printf("{NO_ITEM,0}, /* %s */\n", mnem1);
      newcl = 0;
    } else {
      printf("{%s,%d}, /* %s */\n", itemtype, index, mnem1);
      newcl = 1;
    }
  }
  printf("};\n");
}


x86 assembly (clang, -O0):
<convert>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x1,-0x94(%rbp)
lea    0xe8c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%rdi
lea    -0x70(%rbp),%rdx
lea    -0x30(%rbp),%rcx
lea    0xe93(%rip),%rsi
lea    -0x98(%rbp),%r8
call   1040 <fscanf@plt>
mov    -0x8(%rbp),%rdi
call   1060 <feof@plt>
cmp    $0x0,%rax
je     11b2 <convert+0x62>
jmp    1280 <convert+0x130>
lea    -0x70(%rbp),%rdi
lea    0xe6b(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
je     11d8 <convert+0x88>
lea    0xe5d(%rip),%rdi
call   1070 <error@plt>
cmpl   $0x0,-0x94(%rbp)
je     1207 <convert+0xb7>
mov    -0x10(%rbp),%rdi
lea    -0x50(%rbp),%rdx
lea    -0x90(%rbp),%rcx
lea    0xe26(%rip),%rsi
lea    -0x9c(%rbp),%r8
call   1040 <fscanf@plt>
mov    -0x10(%rbp),%rdi
call   1060 <feof@plt>
cmp    $0x0,%rax
jne    1231 <convert+0xe1>
lea    -0x30(%rbp),%rdi
lea    -0x50(%rbp),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
je     1252 <convert+0x102>
lea    -0x30(%rbp),%rsi
lea    0xe18(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x94(%rbp)
jmp    127b <convert+0x12b>
lea    -0x90(%rbp),%rsi
mov    -0x9c(%rbp),%edx
lea    -0x30(%rbp),%rcx
lea    0xe01(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x94(%rbp)
jmp    117b <convert+0x2b>
lea    0xdf7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<convert>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x88,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0xedf(%rip),%rdi
call   1030 <puts@plt>
lea    0xe76(%rip),%rsi
lea    0x30(%rsp),%rdx
lea    0x70(%rsp),%rcx
lea    0xc(%rsp),%r8
mov    %rbx,%rdi
call   1050 <fscanf@plt>
mov    %rbx,%rdi
call   1070 <feof@plt>
test   %rax,%rax
je     11cc <convert+0x6c>
lea    0xec8(%rip),%rdi
call   1030 <puts@plt>
add    $0x88,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0x1,%ebp
lea    0x30(%rsp),%r12
lea    0x70(%rsp),%r13
lea    0xe1e(%rip),%r15
jmp    1226 <convert+0xc6>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
xor    %ebp,%ebp
lea    0xe3a(%rip),%rdi
mov    %r13,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
mov    %r13,%rcx
lea    0xc(%rsp),%r8
call   1050 <fscanf@plt>
mov    %rbx,%rdi
call   1070 <feof@plt>
test   %rax,%rax
jne    11ae <convert+0x4e>
mov    %r12,%rdi
lea    0xdd7(%rip),%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
je     1246 <convert+0xe6>
lea    0xdce(%rip),%rdi
call   1080 <error@plt>
test   %ebp,%ebp
je     1264 <convert+0x104>
mov    %r14,%rdi
mov    %r15,%rsi
lea    0x50(%rsp),%rdx
lea    0x10(%rsp),%rcx
lea    0x8(%rsp),%r8
call   1050 <fscanf@plt>
mov    %r14,%rdi
call   1070 <feof@plt>
test   %rax,%rax
jne    11f0 <convert+0x90>
mov    %r13,%rdi
lea    0x50(%rsp),%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
jne    11f0 <convert+0x90>
mov    0x8(%rsp),%edx
lea    0xdb4(%rip),%rdi
lea    0x10(%rsp),%rsi
mov    %r13,%rcx
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%ebp
jmp    1203 <convert+0xa3>

LLVM IR (-O0):
@.str = [33 x i8] c"struct item_descr itemtab[] = {\0A\00"
@.str.1 = [7 x i8] c"%s%s%d\00"
@.str.2 = [8 x i8] c"#define\00"
@.str.3 = [36 x i8] c"bad mnemonic file, #define expected\00"
@.str.4 = [23 x i8] c"{NO_ITEM,0}, /* %s */\0A\00"
@.str.5 = [19 x i8] c"{%s,%d}, /* %s */\0A\00"
@.str.6 = [4 x i8] c"};\0A\00"
define void @convert(i32* %0, i32* %1) {
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca [20 x i8]
%6 = alloca [20 x i8]
%7 = alloca [20 x i8]
%8 = alloca [20 x i8]
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i32* %0, i32** %3
store i32* %1, i32** %4
store i32 1, i32* %9
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
br label %13
13: ; preds = %53, %2
%14 = load i32*, i32** %3
%15 = getelementptr inbounds [20 x i8], [20 x i8]* %7, i64 0, i64 0
%16 = getelementptr inbounds [20 x i8], [20 x i8]* %5, i64 0, i64 0
%17 = call i32 @fscanf(i32* %14, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* %15, i8* %16, i32* %10)
%18 = load i32*, i32** %3
%19 = call i64 @feof(i32* %18)
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %22
21: ; preds = %13
br label %54
22: ; preds = %13
%23 = getelementptr inbounds [20 x i8], [20 x i8]* %7, i64 0, i64 0
%24 = call i64 @strcmp(i8* %23, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%25 = icmp ne i64 %24, 0
br i1 %25, label %26, label %28
26: ; preds = %22
%27 = call i32 @error(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0))
br label %28
28: ; preds = %26, %22
%29 = load i32, i32* %9
%30 = icmp ne i32 %29, 0
br i1 %30, label %31, label %36
31: ; preds = %28
%32 = load i32*, i32** %4
%33 = getelementptr inbounds [20 x i8], [20 x i8]* %6, i64 0, i64 0
%34 = getelementptr inbounds [20 x i8], [20 x i8]* %8, i64 0, i64 0
%35 = call i32 @fscanf(i32* %32, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* %33, i8* %34, i32* %11)
br label %36
36: ; preds = %31, %28
%37 = load i32*, i32** %4
%38 = call i64 @feof(i32* %37)
%39 = icmp ne i64 %38, 0
br i1 %39, label %45, label %40
40: ; preds = %36
%41 = getelementptr inbounds [20 x i8], [20 x i8]* %5, i64 0, i64 0
%42 = getelementptr inbounds [20 x i8], [20 x i8]* %6, i64 0, i64 0
%43 = call i64 @strcmp(i8* %41, i8* %42)
%44 = icmp ne i64 %43, 0
br i1 %44, label %45, label %48
45: ; preds = %40, %36
%46 = getelementptr inbounds [20 x i8], [20 x i8]* %5, i64 0, i64 0
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0), i8* %46)
store i32 0, i32* %9
br label %53
48: ; preds = %40
%49 = getelementptr inbounds [20 x i8], [20 x i8]* %8, i64 0, i64 0
%50 = load i32, i32* %11
%51 = getelementptr inbounds [20 x i8], [20 x i8]* %5, i64 0, i64 0
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0), i8* %49, i32 %50, i8* %51)
store i32 1, i32* %9
br label %53
53: ; preds = %48, %45
br label %13
54: ; preds = %21
%55 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str.1 = [7 x i8] c"%s%s%d\00"
@.str.2 = [8 x i8] c"#define\00"
@.str.3 = [36 x i8] c"bad mnemonic file, #define expected\00"
@.str.4 = [23 x i8] c"{NO_ITEM,0}, /* %s */\0A\00"
@.str.5 = [19 x i8] c"{%s,%d}, /* %s */\0A\00"
@str = [32 x i8] c"struct item_descr itemtab[] = {\00"
@str.7 = [3 x i8] c"};\00"
define void @convert(i32* nocapture %0, i32* nocapture %1) {
%3 = alloca [20 x i8]
%4 = alloca [20 x i8]
%5 = alloca [20 x i8]
%6 = alloca [20 x i8]
%7 = alloca i32
%8 = alloca i32
%9 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 0
%10 = getelementptr inbounds [20 x i8], [20 x i8]* %4, i64 0, i64 0
%11 = getelementptr inbounds [20 x i8], [20 x i8]* %5, i64 0, i64 0
%12 = getelementptr inbounds [20 x i8], [20 x i8]* %6, i64 0, i64 0
%13 = bitcast i32* %7 to i8*
%14 = bitcast i32* %8 to i8*
%15 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @str, i64 0, i64 0))
%16 = call i32 @fscanf(i32* %0, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* %11, i8* %9, i32* %7)
%17 = call i64 @feof(i32* %0)
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %45
19: ; preds = %2, %40
%20 = phi i32 [ %41, %40 ], [ 1, %2 ]
%21 = call i64 @strcmp(i8* %11, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%22 = icmp eq i64 %21, 0
br i1 %22, label %25, label %23
23: ; preds = %19
%24 = call i32 @error(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0))
br label %25
25: ; preds = %23, %19
%26 = icmp eq i32 %20, 0
br i1 %26, label %29, label %27
27: ; preds = %25
%28 = call i32 @fscanf(i32* %1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* %10, i8* %12, i32* %8)
br label %29
29: ; preds = %27, %25
%30 = call i64 @feof(i32* %1)
%31 = icmp eq i64 %30, 0
br i1 %31, label %32, label %35
32: ; preds = %29
%33 = call i64 @strcmp(i8* %9, i8* %10)
%34 = icmp eq i64 %33, 0
br i1 %34, label %37, label %35
35: ; preds = %32, %29
%36 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0), i8* %9)
br label %40
37: ; preds = %32
%38 = load i32, i32* %8
%39 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0), i8* %12, i32 %38, i8* %9)
br label %40
40: ; preds = %37, %35
%41 = phi i32 [ 0, %35 ], [ 1, %37 ]
%42 = call i32 @fscanf(i32* %0, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* %11, i8* %9, i32* %7)
%43 = call i64 @feof(i32* %0)
%44 = icmp eq i64 %43, 0
br i1 %44, label %19, label %45
45: ; preds = %40, %2
%46 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @str.7, i64 0, i64 0))
ret void
}