#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*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ *stderr;
void write_ascii_item(FILE *fp, int int_val, unsigned int uint_val,
                      double double_val, int type) {
  switch (type) {
  case 1:
  case 2:
  case 3:
    if (fprintf(fp, "%d ", int_val) <= 0) {
      fprintf(stderr, "PLY ERROR: fprintf() failed -- aborting.\n");
      exit(1);
    }
    break;
  case 4:
  case 5:
  case 6:
    if (fprintf(fp, "%u ", uint_val) <= 0) {
      fprintf(stderr, "PLY ERROR: fprintf() failed -- aborting.\n");
      exit(1);
    }
    break;
  case 7:
  case 8:
    if (fprintf(fp, "%g ", double_val) <= 0) {
      fprintf(stderr, "PLY ERROR: fprintf() failed -- aborting.\n");
      exit(1);
    }
    break;
  default:
    fprintf(stderr, "write_ascii_item: bad type = %d\n", type);
    exit(-1);
  }
}


x86 assembly (clang, -O0):
<write_ascii_item>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
movsd  %xmm0,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x20(%rbp)
add    $0xffffffff,%eax
sub    $0x3,%eax
jb     1179 <write_ascii_item+0x59>
jmp    1151 <write_ascii_item+0x31>
mov    -0x20(%rbp),%eax
add    $0xfffffffc,%eax
sub    $0x3,%eax
jb     11be <write_ascii_item+0x9e>
jmp    1165 <write_ascii_item+0x45>
mov    -0x20(%rbp),%eax
add    $0xfffffff9,%eax
sub    $0x2,%eax
jb     1203 <write_ascii_item+0xe3>
jmp    124a <write_ascii_item+0x12a>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%edx
lea    0xe79(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
cmp    $0x0,%eax
jg     11b9 <write_ascii_item+0x99>
mov    0x2e42(%rip),%rax
mov    (%rax),%rdi
lea    0xe5c(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1040 <exit@plt>
jmp    126f <write_ascii_item+0x14f>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%edx
lea    0xe62(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
cmp    $0x0,%eax
jg     11fe <write_ascii_item+0xde>
mov    0x2dfd(%rip),%rax
mov    (%rax),%rdi
lea    0xe17(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1040 <exit@plt>
jmp    126f <write_ascii_item+0x14f>
mov    -0x8(%rbp),%rdi
movsd  -0x18(%rbp),%xmm0
lea    0xe1f(%rip),%rsi
mov    $0x1,%al
call   1030 <fprintf@plt>
cmp    $0x0,%eax
jg     1245 <write_ascii_item+0x125>
mov    0x2db6(%rip),%rax
mov    (%rax),%rdi
lea    0xdd0(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1040 <exit@plt>
jmp    126f <write_ascii_item+0x14f>
mov    0x2d8f(%rip),%rax
mov    (%rax),%rdi
mov    -0x1c(%rbp),%edx
lea    0xdd8(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    $0xffffffff,%edi
call   1040 <exit@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_ascii_item>:
push   %rax
cmp    $0x8,%ecx
ja     11b1 <write_ascii_item+0x81>
mov    %esi,%eax
mov    $0xe,%esi
bt     %ecx,%esi
jb     1155 <write_ascii_item+0x25>
mov    $0x70,%eax
bt     %ecx,%eax
jae    116b <write_ascii_item+0x3b>
lea    0xedb(%rip),%rsi
jmp    115e <write_ascii_item+0x2e>
lea    0xea4(%rip),%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1030 <fprintf@plt>
test   %eax,%eax
jle    1187 <write_ascii_item+0x57>
pop    %rax
ret
mov    $0x180,%eax
bt     %ecx,%eax
jae    11b1 <write_ascii_item+0x81>
lea    0xeb6(%rip),%rsi
mov    $0x1,%al
call   1030 <fprintf@plt>
test   %eax,%eax
jg     1169 <write_ascii_item+0x39>
mov    0x2e52(%rip),%rax
mov    (%rax),%rcx
lea    0xe6c(%rip),%rdi
mov    $0x29,%esi
mov    $0x1,%edx
call   1050 <fwrite@plt>
mov    $0x1,%edi
call   1040 <exit@plt>
mov    0x2e28(%rip),%rax
mov    (%rax),%rdi
lea    0xe74(%rip),%rsi
mov    %ecx,%edx
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    $0xffffffff,%edi
call   1040 <exit@plt>

LLVM IR (-O0):
@.str = [4 x i8] c"%d \00"
@stderr = global i32* null
@.str.1 = [42 x i8] c"PLY ERROR: fprintf() failed -- aborting.\0A\00"
@.str.2 = [4 x i8] c"%u \00"
@.str.3 = [4 x i8] c"%g \00"
@.str.4 = [33 x i8] c"write_ascii_item: bad type = %d\0A\00"
define void @write_ascii_item(i32* %0, i32 %1, i32 %2, double %3, i32 %4) {
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
%9 = alloca double
%10 = alloca i32
store i32* %0, i32** %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store double %3, double* %9
store i32 %4, i32* %10
%11 = load i32, i32* %10
switch i32 %11, label %42 [
i32 1, label %12
i32 2, label %12
i32 3, label %12
i32 4, label %22
i32 5, label %22
i32 6, label %22
i32 7, label %32
i32 8, label %32
]
12: ; preds = %5, %5, %5
%13 = load i32*, i32** %6
%14 = load i32, i32* %7
%15 = call i32 (i32*, i8*, ...) @fprintf(i32* %13, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %14)
%16 = icmp sle i32 %15, 0
br i1 %16, label %17, label %21
17: ; preds = %12
%18 = load i32*, i32** @stderr
%19 = call i32 (i32*, i8*, ...) @fprintf(i32* %18, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0))
%20 = call i32 @exit(i32 1)
unreachable
21: ; preds = %12
br label %47
22: ; preds = %5, %5, %5
%23 = load i32*, i32** %6
%24 = load i32, i32* %8
%25 = call i32 (i32*, i8*, ...) @fprintf(i32* %23, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %24)
%26 = icmp sle i32 %25, 0
br i1 %26, label %27, label %31
27: ; preds = %22
%28 = load i32*, i32** @stderr
%29 = call i32 (i32*, i8*, ...) @fprintf(i32* %28, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0))
%30 = call i32 @exit(i32 1)
unreachable
31: ; preds = %22
br label %47
32: ; preds = %5, %5
%33 = load i32*, i32** %6
%34 = load double, double* %9
%35 = call i32 (i32*, i8*, ...) @fprintf(i32* %33, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), double %34)
%36 = icmp sle i32 %35, 0
br i1 %36, label %37, label %41
37: ; preds = %32
%38 = load i32*, i32** @stderr
%39 = call i32 (i32*, i8*, ...) @fprintf(i32* %38, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0))
%40 = call i32 @exit(i32 1)
unreachable
41: ; preds = %32
br label %47
42: ; preds = %5
%43 = load i32*, i32** @stderr
%44 = load i32, i32* %10
%45 = call i32 (i32*, i8*, ...) @fprintf(i32* %43, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0), i32 %44)
%46 = call i32 @exit(i32 -1)
unreachable
47: ; preds = %41, %31, %21
ret void
}

LLVM IR (-O2):
@.str = [4 x i8] c"%d \00"
@stderr = global i32* null
@.str.1 = [42 x i8] c"PLY ERROR: fprintf() failed -- aborting.\0A\00"
@.str.2 = [4 x i8] c"%u \00"
@.str.3 = [4 x i8] c"%g \00"
@.str.4 = [33 x i8] c"write_ascii_item: bad type = %d\0A\00"
define void @write_ascii_item(i32* nocapture %0, i32 %1, i32 %2, double %3, i32 %4) {
switch i32 %4, label %27 [
i32 1, label %6
i32 2, label %6
i32 3, label %6
i32 4, label %13
i32 5, label %13
i32 6, label %13
i32 7, label %20
i32 8, label %20
]
6: ; preds = %5, %5, %5
%7 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %1)
%8 = icmp slt i32 %7, 1
br i1 %8, label %9, label %31
9: ; preds = %6
%10 = load i32*, i32** @stderr
%11 = tail call i64 @fwrite(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0), i64 41, i64 1, i32* %10)
%12 = tail call i32 @exit(i32 1)
unreachable
13: ; preds = %5, %5, %5
%14 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %2)
%15 = icmp slt i32 %14, 1
br i1 %15, label %16, label %31
16: ; preds = %13
%17 = load i32*, i32** @stderr
%18 = tail call i64 @fwrite(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0), i64 41, i64 1, i32* %17)
%19 = tail call i32 @exit(i32 1)
unreachable
20: ; preds = %5, %5
%21 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), double %3)
%22 = icmp slt i32 %21, 1
br i1 %22, label %23, label %31
23: ; preds = %20
%24 = load i32*, i32** @stderr
%25 = tail call i64 @fwrite(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0), i64 41, i64 1, i32* %24)
%26 = tail call i32 @exit(i32 1)
unreachable
27: ; preds = %5
%28 = load i32*, i32** @stderr
%29 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %28, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0), i32 %4)
%30 = tail call i32 @exit(i32 -1)
unreachable
31: ; preds = %20, %13, %6
ret void
}