#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*/ fwrite(unsigned int *, int, int, int /*<<< orphan*/ *);
unsigned int htonl(unsigned int);
int /*<<< orphan*/ printf(char *, unsigned int);
int main() {
  unsigned int ns = 400000;
  unsigned int f_ns = htonl(ns);
  FILE *f = fopen("orsys.conf", "wb");
  printf("ns  =%08x\n", ns);
  printf("f_ns=%08x\n", f_ns);
  fwrite(&f_ns, 4, 1, f);
  fclose(f);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x61a80,-0x8(%rbp)
mov    -0x8(%rbp),%edi
call   1050 <htonl@plt>
mov    %eax,-0xc(%rbp)
lea    0xe88(%rip),%rdi
lea    0xe8c(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%esi
lea    0xe7c(%rip),%rdi
call   1040 <printf@plt>
mov    -0xc(%rbp),%esi
lea    0xe78(%rip),%rdi
call   1040 <printf@plt>
mov    -0x18(%rbp),%rcx
lea    -0xc(%rbp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
call   1070 <fwrite@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    $0x61a80,%edi
call   1050 <htonl@plt>
mov    %eax,%ebx
mov    %eax,0x4(%rsp)
lea    0xe95(%rip),%rdi
lea    0xe99(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%r14
lea    0xe8d(%rip),%rdi
mov    $0x61a80,%esi
call   1040 <printf@plt>
lea    0xe87(%rip),%rdi
mov    %ebx,%esi
call   1040 <printf@plt>
lea    0x4(%rsp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   1070 <fwrite@plt>
mov    %r14,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [11 x i8] c"orsys.conf\00"
@.str.1 = [3 x i8] c"wb\00"
@.str.2 = [11 x i8] c"ns =%08x\0A\00"
@.str.3 = [11 x i8] c"f_ns=%08x\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32*
store i32 0, i32* %1
store i32 400000, i32* %2
%5 = load i32, i32* %2
%6 = call i32 @htonl(i32 %5)
store i32 %6, i32* %3
%7 = call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %7, i32** %4
%8 = load i32, i32* %2
%9 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i32 %8)
%10 = load i32, i32* %3
%11 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i32 %10)
%12 = load i32*, i32** %4
%13 = call i32 @fwrite(i32* %3, i32 4, i32 1, i32* %12)
%14 = load i32*, i32** %4
%15 = call i32 @fclose(i32* %14)
ret i32 0
}

LLVM IR (-O2):
@.str = [11 x i8] c"orsys.conf\00"
@.str.1 = [3 x i8] c"wb\00"
@.str.2 = [11 x i8] c"ns =%08x\0A\00"
@.str.3 = [11 x i8] c"f_ns=%08x\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 @htonl(i32 400000)
store i32 %3, i32* %1
%4 = tail call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%5 = tail call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i32 400000)
%6 = tail call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i32 %3)
%7 = call i32 @fwrite(i32* %1, i32 4, i32 1, i32* %4)
%8 = tail call i32 @fclose(i32* %4)
ret i32 0
}