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

/* Variables and functions */
int EXIT_SUCCESS;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int /*<<< orphan*/);
int /*<<< orphan*/ ipv4_csum(char const *);
int /*<<< orphan*/ stderr;
int main(void) {
  const char a[] = {
      0x45, 0x00, 0x00, 0x46, 0x51, 0xdc, 0x00, 0x00, 0x40, 0x11,
      0x2b, 0xc9, 0x7f, 0x00, 0x00, 0x01, 0x7f, 0x00, 0x00, 0x01,
  };
  const char b[] = {
      0x45, 0x00, 0x00, 0x48, 0x67, 0x45, 0x00, 0x00, 0x40, 0x11,
      0x52, 0xba, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xa8, 0x01, 0xfe,
  };
  uint16_t cs;
  cs = ipv4_csum(a);
  fprintf(stderr, "csum: 0x%04hx\n", cs);
  cs = ipv4_csum(b);
  fprintf(stderr, "csum: 0x%04hx\n", cs);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xeca(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xec7(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    0xec5(%rip),%eax
mov    %eax,-0x10(%rbp)
mov    0xecb(%rip),%rax
mov    %rax,-0x40(%rbp)
mov    0xec8(%rip),%rax
mov    %rax,-0x38(%rbp)
mov    0xec6(%rip),%eax
mov    %eax,-0x30(%rbp)
lea    -0x20(%rbp),%rdi
call   1040 <ipv4_csum@plt>
mov    %eax,-0x44(%rbp)
mov    0x2e60(%rip),%rax
mov    (%rax),%edi
mov    -0x44(%rbp),%edx
lea    0xea8(%rip),%rsi
call   1030 <fprintf@plt>
lea    -0x40(%rbp),%rdi
call   1040 <ipv4_csum@plt>
mov    %eax,-0x44(%rbp)
mov    0x2e3c(%rip),%rax
mov    (%rax),%edi
mov    -0x44(%rbp),%edx
lea    0xe84(%rip),%rsi
call   1030 <fprintf@plt>
mov    0x2e1c(%rip),%rax
mov    (%rax),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x38,%rsp
movaps 0xed2(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movl   $0x100007f,0x30(%rsp)
01
movaps 0xede(%rip),%xmm0
movaps %xmm0,(%rsp)
movl   $0xfe01a8c0,0x10(%rsp)
fe
lea    0x20(%rsp),%rdi
call   1040 <ipv4_csum@plt>
mov    0x2e81(%rip),%r14
mov    (%r14),%edi
lea    0xecb(%rip),%rbx
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <fprintf@plt>
mov    %rsp,%rdi
call   1040 <ipv4_csum@plt>
mov    (%r14),%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <fprintf@plt>
mov    0x2e49(%rip),%rax
mov    (%rax),%eax
add    $0x38,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@__const.main.a = [20 x i8] c"E\00\00FQ\DC\00\00@\11+\C9\7F\00\00\01\7F\00\00\01"
@__const.main.b = [20 x i8] c"E\00\00HgE\00\00@\11R\BA\00\00\00\00\C0\A8\01\FE"
@stderr = global i32 0
@.str = [15 x i8] c"csum: 0x%04hx\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca [20 x i8]
%3 = alloca [20 x i8]
%4 = alloca i32
store i32 0, i32* %1
%5 = bitcast [20 x i8]* %2 to i8*
%6 = bitcast [20 x i8]* %3 to i8*
%7 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 0
%8 = call i32 @ipv4_csum(i8* %7)
store i32 %8, i32* %4
%9 = load i32, i32* @stderr
%10 = load i32, i32* %4
%11 = call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %10)
%12 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 0
%13 = call i32 @ipv4_csum(i8* %12)
store i32 %13, i32* %4
%14 = load i32, i32* @stderr
%15 = load i32, i32* %4
%16 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %15)
%17 = load i32, i32* @EXIT_SUCCESS
ret i32 %17
}

LLVM IR (-O2):
@__const.main.a = [20 x i8] c"E\00\00FQ\DC\00\00@\11+\C9\7F\00\00\01\7F\00\00\01"
@__const.main.b = [20 x i8] c"E\00\00HgE\00\00@\11R\BA\00\00\00\00\C0\A8\01\FE"
@stderr = global i32 0
@.str = [15 x i8] c"csum: 0x%04hx\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca [20 x i8]
%2 = alloca [20 x i8]
%3 = getelementptr inbounds [20 x i8], [20 x i8]* %1, i64 0, i64 0
%4 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 0
%5 = call i32 @ipv4_csum(i8* %3)
%6 = load i32, i32* @stderr
%7 = call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %5)
%8 = call i32 @ipv4_csum(i8* %4)
%9 = load i32, i32* @stderr
%10 = call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %8)
%11 = load i32, i32* @EXIT_SUCCESS
ret i32 %11
}