#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*/ fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int, int /*<<< orphan*/);
int /*<<< orphan*/ fwrite(char *, int, int, int /*<<< orphan*/ *);
void swap_char(FILE *fp, long int pos1, long int pos2) {
  char c1, c2;
  fseek(fp, sizeof(char) * pos1, 0);
  fread(&c1, sizeof(char), 1, fp);
  fseek(fp, sizeof(char) * pos2, 0);
  fread(&c2, sizeof(char), 1, fp);
  fseek(fp, sizeof(char) * pos1, 0);
  fwrite(&c2, sizeof(char), 1, fp);
  fseek(fp, sizeof(char) * pos2, 0);
  fwrite(&c1, sizeof(char), 1, fp);
}


x86 assembly (clang, -O0):
<swap_char>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%esi
xor    %edx,%edx
call   1040 <fseek@plt>
mov    -0x8(%rbp),%rcx
lea    -0x19(%rbp),%rdi
mov    $0x1,%edx
mov    %edx,%esi
call   1030 <fread@plt>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%esi
xor    %edx,%edx
call   1040 <fseek@plt>
mov    -0x8(%rbp),%rcx
lea    -0x1a(%rbp),%rdi
mov    $0x1,%edx
mov    %edx,%esi
call   1030 <fread@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%esi
xor    %edx,%edx
call   1040 <fseek@plt>
mov    -0x8(%rbp),%rcx
lea    -0x1a(%rbp),%rdi
mov    $0x1,%edx
mov    %edx,%esi
call   1050 <fwrite@plt>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%esi
xor    %edx,%edx
call   1040 <fseek@plt>
mov    -0x8(%rbp),%rcx
lea    -0x19(%rbp),%rdi
mov    $0x1,%edx
mov    %edx,%esi
call   1050 <fwrite@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<swap_char>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
xor    %edx,%edx
call   1050 <fseek@plt>
lea    0xf(%rsp),%rdi
mov    $0x1,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1030 <fread@plt>
mov    %rbx,%rdi
mov    %r14d,%esi
xor    %edx,%edx
call   1050 <fseek@plt>
lea    0xe(%rsp),%rdi
mov    $0x1,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1030 <fread@plt>
mov    %rbx,%rdi
mov    %r15d,%esi
xor    %edx,%edx
call   1050 <fseek@plt>
movsbl 0xe(%rsp),%edi
mov    %rbx,%rsi
call   1040 <fputc@plt>
mov    %rbx,%rdi
mov    %r14d,%esi
xor    %edx,%edx
call   1050 <fseek@plt>
movsbl 0xf(%rsp),%edi
mov    %rbx,%rsi
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
jmp    1040 <fputc@plt>

LLVM IR (-O0):
define void @swap_char(i32* %0, i64 %1, i64 %2) {
%4 = alloca i32*
%5 = alloca i64
%6 = alloca i64
%7 = alloca i8
%8 = alloca i8
store i32* %0, i32** %4
store i64 %1, i64* %5
store i64 %2, i64* %6
%9 = load i32*, i32** %4
%10 = load i64, i64* %5
%11 = mul i64 1, %10
%12 = trunc i64 %11 to i32
%13 = call i32 @fseek(i32* %9, i32 %12, i32 0)
%14 = load i32*, i32** %4
%15 = call i32 @fread(i8* %7, i32 1, i32 1, i32* %14)
%16 = load i32*, i32** %4
%17 = load i64, i64* %6
%18 = mul i64 1, %17
%19 = trunc i64 %18 to i32
%20 = call i32 @fseek(i32* %16, i32 %19, i32 0)
%21 = load i32*, i32** %4
%22 = call i32 @fread(i8* %8, i32 1, i32 1, i32* %21)
%23 = load i32*, i32** %4
%24 = load i64, i64* %5
%25 = mul i64 1, %24
%26 = trunc i64 %25 to i32
%27 = call i32 @fseek(i32* %23, i32 %26, i32 0)
%28 = load i32*, i32** %4
%29 = call i32 @fwrite(i8* %8, i32 1, i32 1, i32* %28)
%30 = load i32*, i32** %4
%31 = load i64, i64* %6
%32 = mul i64 1, %31
%33 = trunc i64 %32 to i32
%34 = call i32 @fseek(i32* %30, i32 %33, i32 0)
%35 = load i32*, i32** %4
%36 = call i32 @fwrite(i8* %7, i32 1, i32 1, i32* %35)
ret void
}

LLVM IR (-O2):
define void @swap_char(i32* nocapture %0, i64 %1, i64 %2) {
%4 = alloca i8
%5 = alloca i8
%6 = trunc i64 %1 to i32
%7 = tail call i32 @fseek(i32* %0, i32 %6, i32 0)
%8 = call i32 @fread(i8* %4, i32 1, i32 1, i32* %0)
%9 = trunc i64 %2 to i32
%10 = tail call i32 @fseek(i32* %0, i32 %9, i32 0)
%11 = call i32 @fread(i8* %5, i32 1, i32 1, i32* %0)
%12 = tail call i32 @fseek(i32* %0, i32 %6, i32 0)
%13 = load i8, i8* %5
%14 = sext i8 %13 to i32
%15 = tail call i32 @fputc(i32 %14, i32* %0)
%16 = tail call i32 @fseek(i32* %0, i32 %9, i32 0)
%17 = load i8, i8* %4
%18 = sext i8 %17 to i32
%19 = tail call i32 @fputc(i32 %18, i32* %0)
ret void
}