#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*/ printf(char *, unsigned int, unsigned char, unsigned int);
unsigned int put_byte(unsigned int, unsigned char, int);
int main() {
  unsigned origin_num = 0x12345678;
  unsigned char place_num = 0xAB;
  unsigned result1 = put_byte(origin_num, place_num, 2);
  unsigned result2 = put_byte(origin_num, place_num, 0);
  printf("%x replace with %x in 2ed byte is: %x\n", origin_num, place_num,
         result1);
  printf("%x replace with %x in 0 byte is: %x\n", origin_num, place_num,
         result2);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x12345678,-0x8(%rbp)
movb   $0xab,-0x9(%rbp)
mov    -0x8(%rbp),%edi
mov    $0x2,%edx
movzbl -0x9(%rbp),%esi
call   1040 <put_byte@plt>
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%edi
xor    %edx,%edx
movzbl -0x9(%rbp),%esi
call   1040 <put_byte@plt>
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%esi
mov    -0x9(%rbp),%al
mov    -0x10(%rbp),%ecx
lea    0xe91(%rip),%rdi
movzbl %al,%edx
call   1030 <printf@plt>
mov    -0x8(%rbp),%esi
mov    -0x9(%rbp),%al
mov    -0x14(%rbp),%ecx
lea    0xea0(%rip),%rdi
movzbl %al,%edx
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
mov    $0x12345678,%edi
mov    $0xab,%esi
mov    $0x2,%edx
call   1040 <put_byte@plt>
mov    %eax,%ebx
mov    $0x12345678,%edi
mov    $0xab,%esi
xor    %edx,%edx
call   1040 <put_byte@plt>
mov    %eax,%ebp
lea    0xead(%rip),%rdi
mov    $0x12345678,%esi
mov    $0xab,%edx
mov    %ebx,%ecx
call   1030 <printf@plt>
lea    0xebc(%rip),%rdi
mov    $0x12345678,%esi
mov    $0xab,%edx
mov    %ebp,%ecx
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [39 x i8] c"%x replace with %x in 2ed byte is: %x\0A\00"
@.str.1 = [37 x i8] c"%x replace with %x in 0 byte is: %x\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i8
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
store i32 305419896, i32* %2
store i8 -85, i8* %3
%6 = load i32, i32* %2
%7 = load i8, i8* %3
%8 = call i32 @put_byte(i32 %6, i8 zeroext %7, i32 2)
store i32 %8, i32* %4
%9 = load i32, i32* %2
%10 = load i8, i8* %3
%11 = call i32 @put_byte(i32 %9, i8 zeroext %10, i32 0)
store i32 %11, i32* %5
%12 = load i32, i32* %2
%13 = load i8, i8* %3
%14 = load i32, i32* %4
%15 = call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i32 %12, i8 zeroext %13, i32 %14)
%16 = load i32, i32* %2
%17 = load i8, i8* %3
%18 = load i32, i32* %5
%19 = call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i32 %16, i8 zeroext %17, i32 %18)
ret i32 0
}

LLVM IR (-O2):
@.str = [39 x i8] c"%x replace with %x in 2ed byte is: %x\0A\00"
@.str.1 = [37 x i8] c"%x replace with %x in 0 byte is: %x\0A\00"
define i32 @main() {
%1 = tail call i32 @put_byte(i32 305419896, i8 zeroext -85, i32 2)
%2 = tail call i32 @put_byte(i32 305419896, i8 zeroext -85, i32 0)
%3 = tail call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i32 305419896, i8 zeroext -85, i32 %1)
%4 = tail call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i32 305419896, i8 zeroext -85, i32 %2)
ret i32 0
}