#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 */

/* Variables and functions */
int /*<<< orphan*/ sprintf(char *, char *, char, char, char, char);
char *byteorder_32(void) {
  static char buf[32 / 4 + 1];
  if (8 * sizeof(int) == 32) {
    union {
      int all;
      struct {
        char a;
        char b;
        char c;
        char d;
      };
    } test = {.all = 0x01020304};
    sprintf(buf, "%02i%02i%02i%02i", test.a, test.b, test.c, test.d);
  } else {
    union {
      long int all;
      struct {
        char a;
        char b;
        char c;
        char d;
      };
    } test = {.all = 0x01020304L};
    sprintf(buf, "%02i%02i%02i%02i", test.a, test.b, test.c, test.d);
  }
  return buf;
}


x86 assembly (clang, -O0):
<byteorder_32>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0xee2(%rip),%eax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%dl
mov    -0x7(%rbp),%cl
mov    -0x6(%rbp),%al
lea    0x2ef8(%rip),%rdi
lea    0xecc(%rip),%rsi
movsbl %dl,%edx
movsbl %cl,%ecx
movsbl %al,%r8d
movsbl -0x5(%rbp),%r9d
call   1030 <sprintf@plt>
lea    0x2ed6(%rip),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<byteorder_32>:
push   %rbx
lea    0x2f11(%rip),%rbx
lea    0xee1(%rip),%rsi
mov    %rbx,%rdi
mov    $0x4,%edx
mov    $0x3,%ecx
mov    $0x2,%r8d
mov    $0x1,%r9d
call   1030 <sprintf@plt>
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
%union.anon = type { i32 }
%struct.anon = type { i8, i8, i8, i8 }
@byteorder_32.buf = internal global [9 x i8] zeroinitializer
@__const.byteorder_32.test = %union.anon { i32 16909060 }
@.str = [17 x i8] c"%02i%02i%02i%02i\00"
define i8* @byteorder_32() {
%1 = alloca %union.anon
%2 = bitcast %union.anon* %1 to i8*
%3 = bitcast %union.anon* %1 to %struct.anon*
%4 = getelementptr inbounds %struct.anon, %struct.anon* %3, i32 0, i32 0
%5 = load i8, i8* %4
%6 = bitcast %union.anon* %1 to %struct.anon*
%7 = getelementptr inbounds %struct.anon, %struct.anon* %6, i32 0, i32 1
%8 = load i8, i8* %7
%9 = bitcast %union.anon* %1 to %struct.anon*
%10 = getelementptr inbounds %struct.anon, %struct.anon* %9, i32 0, i32 2
%11 = load i8, i8* %10
%12 = bitcast %union.anon* %1 to %struct.anon*
%13 = getelementptr inbounds %struct.anon, %struct.anon* %12, i32 0, i32 3
%14 = load i8, i8* %13
%15 = call i32 @sprintf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @byteorder_32.buf, i64 0, i64 0), i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8 signext %5, i8 signext %8, i8 signext %11, i8 signext %14)
ret i8* getelementptr inbounds ([9 x i8], [9 x i8]* @byteorder_32.buf, i64 0, i64 0)
}

LLVM IR (-O2):
@byteorder_32.buf = internal global [9 x i8] zeroinitializer
@.str = [17 x i8] c"%02i%02i%02i%02i\00"
define i8* @byteorder_32() {
%1 = tail call i32 @sprintf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @byteorder_32.buf, i64 0, i64 0), i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8 signext 4, i8 signext 3, i8 signext 2, i8 signext 1)
ret i8* getelementptr inbounds ([9 x i8], [9 x i8]* @byteorder_32.buf, i64 0, i64 0)
}