#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*/ *);
scalar_t__ fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ fputc(char, int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
int test_little_endian();
longs_to_file(char *filename, FILE *infile, int len, int *dsizep, int *usizep) {
  FILE *outfile;
  int val;
  int le;
  int i;
  if ((outfile = fopen(filename, "w")) == 0) {
    fprintf(stderr, "Can't open output file %s\n", filename);
    exit(1);
  }
  le = test_little_endian();
  for (i = 0; i < 8; i++) {
    if (le) {
      val = (unsigned char)fgetc(infile);
      val |= ((unsigned char)fgetc(infile) << 8);
      val |= ((unsigned char)fgetc(infile) << 16);
      val |= ((unsigned char)fgetc(infile) << 24);
    } else {
      val = ((unsigned char)fgetc(infile) << 24);
      val |= ((unsigned char)fgetc(infile) << 16);
      val |= ((unsigned char)fgetc(infile) << 8);
      val |= (unsigned char)fgetc(infile);
    }
    if (i == 3) {
      *dsizep = val;
    }
    if (i == 5) {
      *usizep = val;
    }
    fprintf(outfile, "0x%08x, ", val);
  }
  fputc('\n', outfile);
  fclose(outfile);
}


x86 assembly (clang, -O0):
<longs_to_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe6a(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x38(%rbp)
cmp    $0x0,%rax
jne    11cf <longs_to_file+0x5f>
mov    0x2e30(%rip),%rax
movslq (%rax),%rdi
mov    -0x10(%rbp),%rdx
lea    0xe44(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    $0x0,%al
call   1040 <test_little_endian@plt>
mov    %eax,-0x40(%rbp)
movl   $0x0,-0x44(%rbp)
cmpl   $0x8,-0x44(%rbp)
jge    12de <longs_to_file+0x16e>
cmpl   $0x0,-0x40(%rbp)
je     1247 <longs_to_file+0xd7>
mov    -0x18(%rbp),%rdi
call   1050 <fgetc@plt>
movzbl %al,%eax
mov    %eax,-0x3c(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <fgetc@plt>
movzbl %al,%eax
shl    $0x8,%eax
or     -0x3c(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <fgetc@plt>
movzbl %al,%eax
shl    $0x10,%eax
or     -0x3c(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <fgetc@plt>
movzbl %al,%eax
shl    $0x18,%eax
or     -0x3c(%rbp),%eax
mov    %eax,-0x3c(%rbp)
jmp    1295 <longs_to_file+0x125>
mov    -0x18(%rbp),%rdi
call   1050 <fgetc@plt>
movzbl %al,%eax
shl    $0x18,%eax
mov    %eax,-0x3c(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <fgetc@plt>
movzbl %al,%eax
shl    $0x10,%eax
or     -0x3c(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <fgetc@plt>
movzbl %al,%eax
shl    $0x8,%eax
or     -0x3c(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <fgetc@plt>
movzbl %al,%eax
or     -0x3c(%rbp),%eax
mov    %eax,-0x3c(%rbp)
cmpl   $0x3,-0x44(%rbp)
jne    12a8 <longs_to_file+0x138>
mov    -0x3c(%rbp),%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,(%rax)
cmpl   $0x5,-0x44(%rbp)
jne    12bb <longs_to_file+0x14b>
mov    -0x3c(%rbp),%ecx
mov    -0x30(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x38(%rbp),%rdi
mov    -0x3c(%rbp),%edx
lea    0xd54(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    11e0 <longs_to_file+0x70>
mov    -0x38(%rbp),%rsi
mov    $0xa,%edi
call   1060 <fputc@plt>
mov    -0x38(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<longs_to_file>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r8,0x8(%rsp)
mov    %rcx,0x10(%rsp)
mov    %rsi,%r12
mov    %rdi,%rbp
lea    0xe6b(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,(%rsp)
test   %rax,%rax
je     12a7 <longs_to_file+0x137>
xor    %eax,%eax
call   1040 <test_little_endian@plt>
mov    %eax,%r15d
xor    %r13d,%r13d
jmp    11e7 <longs_to_file+0x77>
cs nopw 0x0(%rax,%rax,1)
mov    0x8(%rsp),%rax
mov    %edx,(%rax)
mov    (%rsp),%rdi
lea    0xe4b(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
add    $0x1,%r13d
cmp    $0x8,%r13d
je     1280 <longs_to_file+0x110>
mov    %r12,%rdi
call   1050 <fgetc@plt>
mov    %rax,%r14
test   %r15d,%r15d
je     1230 <longs_to_file+0xc0>
movzbl %r14b,%ebp
mov    %r12,%rdi
call   1050 <fgetc@plt>
shl    $0x8,%eax
movzwl %ax,%ebx
or     %ebp,%ebx
mov    %r12,%rdi
call   1050 <fgetc@plt>
movzbl %al,%ebp
shl    $0x10,%ebp
or     %ebx,%ebp
mov    %r12,%rdi
call   1050 <fgetc@plt>
mov    %rax,%rdx
shl    $0x18,%edx
jmp    1260 <longs_to_file+0xf0>
nopl   0x0(%rax,%rax,1)
shl    $0x18,%r14d
mov    %r12,%rdi
call   1050 <fgetc@plt>
movzbl %al,%ebx
shl    $0x10,%ebx
or     %r14d,%ebx
mov    %r12,%rdi
call   1050 <fgetc@plt>
shl    $0x8,%eax
movzwl %ax,%ebp
or     %ebx,%ebp
mov    %r12,%rdi
call   1050 <fgetc@plt>
movzbl %al,%edx
or     %ebp,%edx
mov    0x10(%rsp),%rax
cmp    $0x3,%r13d
je     11c5 <longs_to_file+0x55>
cmp    $0x5,%r13d
je     11c0 <longs_to_file+0x50>
jmp    11c7 <longs_to_file+0x57>
mov    $0xa,%edi
mov    (%rsp),%rbx
mov    %rbx,%rsi
call   1060 <fputc@plt>
mov    %rbx,%rdi
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <fclose@plt>
mov    0x2d32(%rip),%rax
movslq (%rax),%rdi
lea    0xd4a(%rip),%rsi
mov    %rbp,%rdx
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"w\00"
@stderr = global i32 0
@.str.1 = [27 x i8] c"Can't open output file %s\0A\00"
@.str.2 = [9 x i8] c"0x%08x, \00"
define i32 @longs_to_file(i8* %0, i32* %1, i32 %2, i32* %3, i32* %4) {
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32*
%9 = alloca i32
%10 = alloca i32*
%11 = alloca i32*
%12 = alloca i32*
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
store i8* %0, i8** %7
store i32* %1, i32** %8
store i32 %2, i32* %9
store i32* %3, i32** %10
store i32* %4, i32** %11
%16 = load i8*, i8** %7
%17 = call i32* @fopen(i8* %16, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %17, i32** %12
%18 = icmp eq i32* %17, null
br i1 %18, label %19, label %26
19: ; preds = %5
%20 = load i32, i32* @stderr
%21 = sext i32 %20 to i64
%22 = inttoptr i64 %21 to i32*
%23 = load i8*, i8** %7
%24 = call i32 (i32*, i8*, ...) @fprintf(i32* %22, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* %23)
%25 = call i32 @exit(i32 1)
unreachable
26: ; preds = %5
%27 = call i32 (...) @test_little_endian()
store i32 %27, i32* %14
store i32 0, i32* %15
br label %28
28: ; preds = %102, %26
%29 = load i32, i32* %15
%30 = icmp slt i32 %29, 8
br i1 %30, label %31, label %105
31: ; preds = %28
%32 = load i32, i32* %14
%33 = icmp ne i32 %32, 0
br i1 %33, label %34, label %60
34: ; preds = %31
%35 = load i32*, i32** %8
%36 = call i64 @fgetc(i32* %35)
%37 = trunc i64 %36 to i8
%38 = zext i8 %37 to i32
store i32 %38, i32* %13
%39 = load i32*, i32** %8
%40 = call i64 @fgetc(i32* %39)
%41 = trunc i64 %40 to i8
%42 = zext i8 %41 to i32
%43 = shl i32 %42, 8
%44 = load i32, i32* %13
%45 = or i32 %44, %43
store i32 %45, i32* %13
%46 = load i32*, i32** %8
%47 = call i64 @fgetc(i32* %46)
%48 = trunc i64 %47 to i8
%49 = zext i8 %48 to i32
%50 = shl i32 %49, 16
%51 = load i32, i32* %13
%52 = or i32 %51, %50
store i32 %52, i32* %13
%53 = load i32*, i32** %8
%54 = call i64 @fgetc(i32* %53)
%55 = trunc i64 %54 to i8
%56 = zext i8 %55 to i32
%57 = shl i32 %56, 24
%58 = load i32, i32* %13
%59 = or i32 %58, %57
store i32 %59, i32* %13
br label %86
60: ; preds = %31
%61 = load i32*, i32** %8
%62 = call i64 @fgetc(i32* %61)
%63 = trunc i64 %62 to i8
%64 = zext i8 %63 to i32
%65 = shl i32 %64, 24
store i32 %65, i32* %13
%66 = load i32*, i32** %8
%67 = call i64 @fgetc(i32* %66)
%68 = trunc i64 %67 to i8
%69 = zext i8 %68 to i32
%70 = shl i32 %69, 16
%71 = load i32, i32* %13
%72 = or i32 %71, %70
store i32 %72, i32* %13
%73 = load i32*, i32** %8
%74 = call i64 @fgetc(i32* %73)
%75 = trunc i64 %74 to i8
%76 = zext i8 %75 to i32
%77 = shl i32 %76, 8
%78 = load i32, i32* %13
%79 = or i32 %78, %77
store i32 %79, i32* %13
%80 = load i32*, i32** %8
%81 = call i64 @fgetc(i32* %80)
%82 = trunc i64 %81 to i8
%83 = zext i8 %82 to i32
%84 = load i32, i32* %13
%85 = or i32 %84, %83
store i32 %85, i32* %13
br label %86
86: ; preds = %60, %34
%87 = load i32, i32* %15
%88 = icmp eq i32 %87, 3
br i1 %88, label %89, label %92
89: ; preds = %86
%90 = load i32, i32* %13
%91 = load i32*, i32** %10
store i32 %90, i32* %91
br label %92
92: ; preds = %89, %86
%93 = load i32, i32* %15
%94 = icmp eq i32 %93, 5
br i1 %94, label %95, label %98
95: ; preds = %92
%96 = load i32, i32* %13
%97 = load i32*, i32** %11
store i32 %96, i32* %97
br label %98
98: ; preds = %95, %92
%99 = load i32*, i32** %12
%100 = load i32, i32* %13
%101 = call i32 (i32*, i8*, ...) @fprintf(i32* %99, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 %100)
br label %102
102: ; preds = %98
%103 = load i32, i32* %15
%104 = add nsw i32 %103, 1
store i32 %104, i32* %15
br label %28
105: ; preds = %28
%106 = load i32*, i32** %12
%107 = call i32 @fputc(i8 signext 10, i32* %106)
%108 = load i32*, i32** %12
%109 = call i32 @fclose(i32* %108)
%110 = load i32, i32* %6
ret i32 %110
}

LLVM IR (-O2):
@.str = [2 x i8] c"w\00"
@stderr = global i32 0
@.str.1 = [27 x i8] c"Can't open output file %s\0A\00"
@.str.2 = [9 x i8] c"0x%08x, \00"
define i32 @longs_to_file(i8* %0, i32* nocapture %1, i32 %2, i32* nocapture writeonly %3, i32* nocapture writeonly %4) {
%6 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i32* %6, null
br i1 %7, label %8, label %14
8: ; preds = %5
%9 = load i32, i32* @stderr
%10 = sext i32 %9 to i64
%11 = inttoptr i64 %10 to i32*
%12 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %11, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%13 = tail call i32 @exit(i32 1)
unreachable
14: ; preds = %5
%15 = tail call i32 (...) @test_little_endian()
%16 = icmp eq i32 %15, 0
br label %17
17: ; preds = %14, %58
%18 = phi i32 [ 0, %14 ], [ %60, %58 ]
%19 = tail call i64 @fgetc(i32* %1)
%20 = trunc i64 %19 to i32
br i1 %16, label %37, label %21
21: ; preds = %17
%22 = and i32 %20, 255
%23 = tail call i64 @fgetc(i32* %1)
%24 = trunc i64 %23 to i32
%25 = shl i32 %24, 8
%26 = and i32 %25, 65280
%27 = or i32 %26, %22
%28 = tail call i64 @fgetc(i32* %1)
%29 = trunc i64 %28 to i32
%30 = shl i32 %29, 16
%31 = and i32 %30, 16711680
%32 = or i32 %27, %31
%33 = tail call i64 @fgetc(i32* %1)
%34 = trunc i64 %33 to i32
%35 = shl i32 %34, 24
%36 = or i32 %32, %35
br label %53
37: ; preds = %17
%38 = shl i32 %20, 24
%39 = tail call i64 @fgetc(i32* %1)
%40 = trunc i64 %39 to i32
%41 = shl i32 %40, 16
%42 = and i32 %41, 16711680
%43 = or i32 %42, %38
%44 = tail call i64 @fgetc(i32* %1)
%45 = trunc i64 %44 to i32
%46 = shl i32 %45, 8
%47 = and i32 %46, 65280
%48 = or i32 %43, %47
%49 = tail call i64 @fgetc(i32* %1)
%50 = trunc i64 %49 to i32
%51 = and i32 %50, 255
%52 = or i32 %48, %51
br label %53
53: ; preds = %37, %21
%54 = phi i32 [ %36, %21 ], [ %52, %37 ]
switch i32 %18, label %58 [
i32 3, label %56
i32 5, label %55
]
55: ; preds = %53
br label %56
56: ; preds = %53, %55
%57 = phi i32* [ %4, %55 ], [ %3, %53 ]
store i32 %54, i32* %57
br label %58
58: ; preds = %56, %53
%59 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %6, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 %54)
%60 = add nuw nsw i32 %18, 1
%61 = icmp eq i32 %60, 8
br i1 %61, label %62, label %17
62: ; preds = %58
%63 = tail call i32 @fputc(i8 signext 10, i32* %6)
%64 = tail call i32 @fclose(i32* %6)
ret i32 undef
}