#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ *stderr;
main() {
  FILE *fp;
  union {
    unsigned int ui;
    char byte[4];
  } i;
  fp = fopen("swap.h", "w");
  fprintf(fp, "/* header file generated by endian.c -- do not edit */\n\n");
  i.ui = 0;
  i.byte[3] = 1;
  if (i.ui == 1) {
    fprintf(stderr, "big endian [%u]\n", i.ui);
    fprintf(fp, "/* big endian [%u] */\n", i.ui);
    fprintf(fp, "#define DOSWAP 0\n");
  } else {
    fprintf(stderr, "little endian [%u]\n", i.ui);
    fprintf(fp, "/* little endian [%u] */\n", i.ui);
    fprintf(fp, "#define DOSWAP 1\n");
  }
  fclose(fp);
  fprintf(stderr, "swap.h generated\n");
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeba(%rip),%rdi
lea    0xeba(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xea8(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0x0,-0x18(%rbp)
movb   $0x1,-0x15(%rbp)
cmpl   $0x1,-0x18(%rbp)
jne    11c4 <main+0x94>
mov    0x2e5c(%rip),%rax
mov    (%rax),%rdi
mov    -0x18(%rbp),%edx
lea    0xeb1(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%edx
lea    0xead(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x10(%rbp),%rdi
lea    0xeb2(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
jmp    1206 <main+0xd6>
mov    0x2e15(%rip),%rax
mov    (%rax),%rdi
mov    -0x18(%rbp),%edx
lea    0xea4(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%edx
lea    0xea3(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x10(%rbp),%rdi
lea    0xeab(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
mov    0x2dca(%rip),%rax
mov    (%rax),%rdi
lea    0xe9c(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
lea    0xeb5(%rip),%rdi
lea    0xeb5(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,%rbx
lea    0xea8(%rip),%rdi
mov    $0x38,%esi
mov    $0x1,%edx
mov    %rax,%rcx
call   1060 <fwrite@plt>
mov    0x2e66(%rip),%r14
mov    (%r14),%rdi
lea    0xebe(%rip),%rsi
mov    $0x1000000,%edx
xor    %eax,%eax
call   1040 <fprintf@plt>
lea    0xebf(%rip),%rsi
mov    %rbx,%rdi
mov    $0x1000000,%edx
xor    %eax,%eax
call   1040 <fprintf@plt>
lea    0xec3(%rip),%rdi
mov    $0x11,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1060 <fwrite@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    (%r14),%rcx
lea    0xeb1(%rip),%rdi
mov    $0x11,%esi
mov    $0x1,%edx
call   1060 <fwrite@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%union.anon = type { i32 }
@.str = [7 x i8] c"swap.h\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [57 x i8] c"/* header file generated by endian.c -- do not edit */\0A\0A\00"
@stderr = global i32* null
@.str.3 = [17 x i8] c"big endian [%u]\0A\00"
@.str.4 = [23 x i8] c"/* big endian [%u] */\0A\00"
@.str.5 = [18 x i8] c"#define DOSWAP 0\0A\00"
@.str.6 = [20 x i8] c"little endian [%u]\0A\00"
@.str.7 = [26 x i8] c"/* little endian [%u] */\0A\00"
@.str.8 = [18 x i8] c"#define DOSWAP 1\0A\00"
@.str.9 = [18 x i8] c"swap.h generated\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca %union.anon
store i32 0, i32* %1
%4 = call i32* @fopen(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %4, i32** %2
%5 = load i32*, i32** %2
%6 = call i32 (i32*, i8*, ...) @fprintf(i32* %5, i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.2, i64 0, i64 0))
%7 = bitcast %union.anon* %3 to i32*
store i32 0, i32* %7
%8 = bitcast %union.anon* %3 to [4 x i8]*
%9 = getelementptr inbounds [4 x i8], [4 x i8]* %8, i64 0, i64 3
store i8 1, i8* %9
%10 = bitcast %union.anon* %3 to i32*
%11 = load i32, i32* %10
%12 = icmp eq i32 %11, 1
br i1 %12, label %13, label %24
13: ; preds = %0
%14 = load i32*, i32** @stderr
%15 = bitcast %union.anon* %3 to i32*
%16 = load i32, i32* %15
%17 = call i32 (i32*, i8*, ...) @fprintf(i32* %14, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), i32 %16)
%18 = load i32*, i32** %2
%19 = bitcast %union.anon* %3 to i32*
%20 = load i32, i32* %19
%21 = call i32 (i32*, i8*, ...) @fprintf(i32* %18, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0), i32 %20)
%22 = load i32*, i32** %2
%23 = call i32 (i32*, i8*, ...) @fprintf(i32* %22, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0))
br label %35
24: ; preds = %0
%25 = load i32*, i32** @stderr
%26 = bitcast %union.anon* %3 to i32*
%27 = load i32, i32* %26
%28 = call i32 (i32*, i8*, ...) @fprintf(i32* %25, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.6, i64 0, i64 0), i32 %27)
%29 = load i32*, i32** %2
%30 = bitcast %union.anon* %3 to i32*
%31 = load i32, i32* %30
%32 = call i32 (i32*, i8*, ...) @fprintf(i32* %29, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.7, i64 0, i64 0), i32 %31)
%33 = load i32*, i32** %2
%34 = call i32 (i32*, i8*, ...) @fprintf(i32* %33, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.8, i64 0, i64 0))
br label %35
35: ; preds = %24, %13
%36 = load i32*, i32** %2
%37 = call i32 @fclose(i32* %36)
%38 = load i32*, i32** @stderr
%39 = call i32 (i32*, i8*, ...) @fprintf(i32* %38, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.9, i64 0, i64 0))
%40 = load i32, i32* %1
ret i32 %40
}

LLVM IR (-O2):
@.str = [7 x i8] c"swap.h\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [57 x i8] c"/* header file generated by endian.c -- do not edit */\0A\0A\00"
@stderr = global i32* null
@.str.6 = [20 x i8] c"little endian [%u]\0A\00"
@.str.7 = [26 x i8] c"/* little endian [%u] */\0A\00"
@.str.8 = [18 x i8] c"#define DOSWAP 1\0A\00"
@.str.9 = [18 x i8] c"swap.h generated\0A\00"
define i32 @main() {
%1 = tail call i32* @fopen(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%2 = tail call i64 @fwrite(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.2, i64 0, i64 0), i64 56, i64 1, i32* %1)
%3 = load i32*, i32** @stderr
%4 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %3, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.6, i64 0, i64 0), i32 16777216)
%5 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %1, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.7, i64 0, i64 0), i32 16777216)
%6 = tail call i64 @fwrite(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.8, i64 0, i64 0), i64 17, i64 1, i32* %1)
%7 = tail call i32 @fclose(i32* %1)
%8 = load i32*, i32** @stderr
%9 = tail call i64 @fwrite(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.9, i64 0, i64 0), i64 17, i64 1, i32* %8)
ret i32 0
}