#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 *, ...);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ strcmp(char *, char *);
void convert(FILE *mnemfile, FILE *classfile) {
  char mnem1[10], mnem2[10], def[10];
  int src, res, newcl, opc;
  newcl = 1;
  printf("struct class classtab[] = {\n");
  printf("\t{ NOCLASS,\tNOCLASS },\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(classfile, "%s%d%d", mnem2, &src, &res);
    }
    if (feof(classfile) || strcmp(mnem1, mnem2) != 0) {
      printf("\t { NOCLASS,\tNOCLASS },\n");
      newcl = 0;
    } else {
      printf("\t { CLASS%d,\t\tCLASS%d },\n", src, res);
      newcl = 1;
    }
  }
  printf("};\n");
}


x86 assembly (clang, -O0):
<convert>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x1,-0x3c(%rbp)
lea    0xe92(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xea1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%rdi
lea    -0x2e(%rbp),%rdx
lea    -0x1a(%rbp),%rcx
lea    0xe9f(%rip),%rsi
lea    -0x40(%rbp),%r8
mov    $0x0,%al
call   1040 <fscanf@plt>
mov    -0x8(%rbp),%rdi
call   1060 <feof@plt>
cmp    $0x0,%rax
je     11b9 <convert+0x69>
jmp    126b <convert+0x11b>
lea    -0x2e(%rbp),%rdi
lea    0xe78(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
je     11df <convert+0x8f>
lea    0xe6a(%rip),%rdi
call   1070 <error@plt>
cmpl   $0x0,-0x3c(%rbp)
je     1207 <convert+0xb7>
mov    -0x10(%rbp),%rdi
lea    -0x24(%rbp),%rdx
lea    0xe70(%rip),%rsi
lea    -0x34(%rbp),%rcx
lea    -0x38(%rbp),%r8
mov    $0x0,%al
call   1040 <fscanf@plt>
mov    -0x10(%rbp),%rdi
call   1060 <feof@plt>
cmp    $0x0,%rax
jne    1231 <convert+0xe1>
lea    -0x1a(%rbp),%rdi
lea    -0x24(%rbp),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
je     124b <convert+0xfb>
lea    0xe37(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x3c(%rbp)
jmp    1266 <convert+0x116>
mov    -0x34(%rbp),%esi
mov    -0x38(%rbp),%edx
lea    0xe30(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x3c(%rbp)
jmp    1183 <convert+0x33>
lea    0xe30(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<convert>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0xed9(%rip),%rdi
call   1030 <puts@plt>
lea    0xee9(%rip),%rdi
call   1030 <puts@plt>
lea    0xe6d(%rip),%rsi
lea    0x1a(%rsp),%rdx
lea    0x2e(%rsp),%rcx
lea    0xc(%rsp),%r8
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <fscanf@plt>
mov    %rbx,%rdi
call   1070 <feof@plt>
test   %rax,%rax
je     11d4 <convert+0x74>
lea    0xedf(%rip),%rdi
call   1030 <puts@plt>
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0x1,%r15d
lea    0x1a(%rsp),%r12
lea    0x2e(%rsp),%r13
lea    0xc(%rsp),%rbp
jmp    1226 <convert+0xc6>
nopl   0x0(%rax,%rax,1)
lea    0xe90(%rip),%rdi
call   1030 <puts@plt>
xor    %r15d,%r15d
mov    %rbx,%rdi
lea    0xdf7(%rip),%rsi
mov    %r12,%rdx
mov    %r13,%rcx
mov    %rbp,%r8
xor    %eax,%eax
call   1050 <fscanf@plt>
mov    %rbx,%rdi
call   1070 <feof@plt>
test   %rax,%rax
jne    11b9 <convert+0x59>
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   %r15d,%r15d
je     126b <convert+0x10b>
mov    %r14,%rdi
lea    0xdde(%rip),%rsi
lea    0x24(%rsp),%rdx
lea    0x14(%rsp),%rcx
lea    0x10(%rsp),%r8
xor    %eax,%eax
call   1050 <fscanf@plt>
mov    %r14,%rdi
call   1070 <feof@plt>
test   %rax,%rax
jne    11f0 <convert+0x90>
mov    %r13,%rdi
lea    0x24(%rsp),%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
jne    11f0 <convert+0x90>
mov    0x14(%rsp),%esi
mov    0x10(%rsp),%edx
lea    0xd99(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%r15d
jmp    11ff <convert+0x9f>

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

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