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

/* Variables and functions */
int O_CREAT;
int O_EXCL;
int O_RDWR;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ memcpy(char *, char *, scalar_t__);
int open(char *, int, int);
int /*<<< orphan*/ printf(char *);
scalar_t__ strlen(char *);
int /*<<< orphan*/ write(int, ...);
int main() {
  char name[20];
  short age;
  float score;
  char sex;
  int fd = open("test.dat", O_RDWR | O_CREAT | O_EXCL, 00666);
  if (fd == -1) {
    printf("open file error:%m\n");
    exit(-1);
  }
  memcpy(name, "mizu", strlen("mizu") + 1);
  age = 30;
  score = 99.99;
  sex = 'F';
  write(fd, name, sizeof(name));
  write(fd, &age, sizeof age);
  write(fd, &score, sizeof(float));
  write(fd, &sex, sizeof(char));
  memcpy(name, "tani", strlen("tani") + 1);
  age = 20;
  score = 98.99;
  sex = 'M';
  write(fd, name, sizeof(name));
  write(fd, &age, sizeof age);
  write(fd, &score, sizeof(float));
  write(fd, &sex, sizeof(char));
  memcpy(name, "純", strlen("純") + 1);
  age = 330;
  score = 100.0;
  sex = 'M';
  write(fd, name, sizeof(name));
  write(fd, &age, sizeof age);
  write(fd, &score, sizeof(float));
  write(fd, &sex, sizeof(char));
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e5a(%rip),%rax
mov    (%rax),%esi
mov    0x2e69(%rip),%rax
or     (%rax),%esi
mov    0x2e38(%rip),%rax
or     (%rax),%esi
lea    0xe6b(%rip),%rdi
mov    $0x1b6,%edx
call   1080 <open@plt>
mov    %eax,-0x30(%rbp)
cmpl   $0xffffffff,-0x30(%rbp)
jne    11ce <main+0x5e>
lea    0xe56(%rip),%rdi
call   1050 <printf@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>
lea    -0x20(%rbp),%rax
mov    %rax,-0x48(%rbp)
lea    0xe4c(%rip),%rdi
call   1040 <strlen@plt>
mov    -0x48(%rbp),%rdi
mov    %rax,%rdx
add    $0x1,%rdx
lea    0xe35(%rip),%rsi
call   1070 <memcpy@plt>
movw   $0x1e,-0x22(%rbp)
movss  0xe01(%rip),%xmm0
movss  %xmm0,-0x28(%rbp)
movb   $0x46,-0x29(%rbp)
mov    -0x30(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0x14,%edx
mov    $0x0,%al
call   1030 <write@plt>
mov    -0x30(%rbp),%edi
lea    -0x22(%rbp),%rsi
mov    $0x2,%edx
mov    $0x0,%al
call   1030 <write@plt>
mov    -0x30(%rbp),%edi
lea    -0x28(%rbp),%rsi
mov    $0x4,%edx
mov    $0x0,%al
call   1030 <write@plt>
mov    -0x30(%rbp),%edi
lea    -0x29(%rbp),%rsi
mov    $0x1,%edx
mov    $0x0,%al
call   1030 <write@plt>
lea    -0x20(%rbp),%rax
mov    %rax,-0x40(%rbp)
lea    0xdc3(%rip),%rdi
call   1040 <strlen@plt>
mov    -0x40(%rbp),%rdi
mov    %rax,%rdx
add    $0x1,%rdx
lea    0xdac(%rip),%rsi
call   1070 <memcpy@plt>
movw   $0x14,-0x22(%rbp)
movss  0xd6f(%rip),%xmm0
movss  %xmm0,-0x28(%rbp)
movb   $0x4d,-0x29(%rbp)
mov    -0x30(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0x14,%edx
mov    $0x0,%al
call   1030 <write@plt>
mov    -0x30(%rbp),%edi
lea    -0x22(%rbp),%rsi
mov    $0x2,%edx
mov    $0x0,%al
call   1030 <write@plt>
mov    -0x30(%rbp),%edi
lea    -0x28(%rbp),%rsi
mov    $0x4,%edx
mov    $0x0,%al
call   1030 <write@plt>
mov    -0x30(%rbp),%edi
lea    -0x29(%rbp),%rsi
mov    $0x1,%edx
mov    $0x0,%al
call   1030 <write@plt>
lea    -0x20(%rbp),%rax
mov    %rax,-0x38(%rbp)
lea    0xd3a(%rip),%rdi
call   1040 <strlen@plt>
mov    -0x38(%rbp),%rdi
mov    %rax,%rdx
add    $0x1,%rdx
lea    0xd23(%rip),%rsi
call   1070 <memcpy@plt>
movw   $0x14a,-0x22(%rbp)
movss  0xcdd(%rip),%xmm0
movss  %xmm0,-0x28(%rbp)
movb   $0x4d,-0x29(%rbp)
mov    -0x30(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0x14,%edx
mov    $0x0,%al
call   1030 <write@plt>
mov    -0x30(%rbp),%edi
lea    -0x22(%rbp),%rsi
mov    $0x2,%edx
mov    $0x0,%al
call   1030 <write@plt>
mov    -0x30(%rbp),%edi
lea    -0x28(%rbp),%rsi
mov    $0x4,%edx
mov    $0x0,%al
call   1030 <write@plt>
mov    -0x30(%rbp),%edi
lea    -0x29(%rbp),%rsi
mov    $0x1,%edx
mov    $0x0,%al
call   1030 <write@plt>
mov    -0x30(%rbp),%edi
call   1060 <close@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x30,%rsp
mov    0x2e6c(%rip),%rax
mov    0x2e7d(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2e4a(%rip),%rax
or     (%rax),%esi
lea    0xe71(%rip),%rdi
mov    $0x1b6,%edx
call   1070 <open@plt>
cmp    $0xffffffff,%eax
je     1313 <main+0x1b3>
mov    %eax,%ebx
lea    0xe72(%rip),%rsi
lea    0x10(%rsp),%r14
mov    $0x5,%edx
mov    %r14,%rdi
call   1060 <memcpy@plt>
movw   $0x1e,0xa(%rsp)
movl   $0x42c7fae1,0xc(%rsp)
42
movb   $0x46,0x9(%rsp)
mov    $0x14,%edx
mov    %ebx,%edi
mov    %r14,%rsi
xor    %eax,%eax
call   1030 <write@plt>
lea    0xa(%rsp),%r15
mov    $0x2,%edx
mov    %ebx,%edi
mov    %r15,%rsi
xor    %eax,%eax
call   1030 <write@plt>
lea    0xc(%rsp),%r12
mov    $0x4,%edx
mov    %ebx,%edi
mov    %r12,%rsi
xor    %eax,%eax
call   1030 <write@plt>
lea    0x9(%rsp),%r13
mov    $0x1,%edx
mov    %ebx,%edi
mov    %r13,%rsi
xor    %eax,%eax
call   1030 <write@plt>
lea    0xdf7(%rip),%rsi
mov    $0x5,%edx
mov    %r14,%rdi
call   1060 <memcpy@plt>
movw   $0x14,0xa(%rsp)
movl   $0x42c5fae1,0xc(%rsp)
42
movb   $0x4d,0x9(%rsp)
mov    $0x14,%edx
mov    %ebx,%edi
mov    %r14,%rsi
xor    %eax,%eax
call   1030 <write@plt>
mov    $0x2,%edx
mov    %ebx,%edi
mov    %r15,%rsi
xor    %eax,%eax
call   1030 <write@plt>
mov    $0x4,%edx
mov    %ebx,%edi
mov    %r12,%rsi
xor    %eax,%eax
call   1030 <write@plt>
mov    $0x1,%edx
mov    %ebx,%edi
mov    %r13,%rsi
xor    %eax,%eax
call   1030 <write@plt>
lea    0xd90(%rip),%rsi
mov    $0x4,%edx
mov    %r14,%rdi
call   1060 <memcpy@plt>
movw   $0x14a,0xa(%rsp)
movl   $0x42c80000,0xc(%rsp)
42
movb   $0x4d,0x9(%rsp)
mov    $0x14,%edx
mov    %ebx,%edi
mov    %r14,%rsi
xor    %eax,%eax
call   1030 <write@plt>
mov    $0x2,%edx
mov    %ebx,%edi
mov    %r15,%rsi
xor    %eax,%eax
call   1030 <write@plt>
mov    $0x4,%edx
mov    %ebx,%edi
mov    %r12,%rsi
xor    %eax,%eax
call   1030 <write@plt>
mov    $0x1,%edx
mov    %ebx,%edi
mov    %r13,%rsi
xor    %eax,%eax
call   1030 <write@plt>
mov    %ebx,%edi
call   1050 <close@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
lea    0xcef(%rip),%rdi
call   1040 <printf@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [9 x i8] c"test.dat\00"
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@O_EXCL = global i32 0
@.str.1 = [20 x i8] c"open file error:%m\0A\00"
@.str.2 = [5 x i8] c"mizu\00"
@.str.3 = [5 x i8] c"tani\00"
@.str.4 = [4 x i8] c"\E7\B4\94\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [20 x i8]
%3 = alloca i16
%4 = alloca float
%5 = alloca i8
%6 = alloca i32
store i32 0, i32* %1
%7 = load i32, i32* @O_RDWR
%8 = load i32, i32* @O_CREAT
%9 = or i32 %7, %8
%10 = load i32, i32* @O_EXCL
%11 = or i32 %9, %10
%12 = call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %11, i32 438)
store i32 %12, i32* %6
%13 = load i32, i32* %6
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %18
15: ; preds = %0
%16 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
%17 = call i32 @exit(i32 -1)
unreachable
18: ; preds = %0
%19 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 0
%20 = call i64 @strlen(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%21 = add nsw i64 %20, 1
%22 = call i32 @memcpy(i8* %19, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i64 %21)
store i16 30, i16* %3
store float 0x4058FF5C20000000, float* %4
store i8 70, i8* %5
%23 = load i32, i32* %6
%24 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 0
%25 = call i32 (i32, ...) @write(i32 %23, i8* %24, i64 20)
%26 = load i32, i32* %6
%27 = call i32 (i32, ...) @write(i32 %26, i16* %3, i64 2)
%28 = load i32, i32* %6
%29 = call i32 (i32, ...) @write(i32 %28, float* %4, i64 4)
%30 = load i32, i32* %6
%31 = call i32 (i32, ...) @write(i32 %30, i8* %5, i64 1)
%32 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 0
%33 = call i64 @strlen(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%34 = add nsw i64 %33, 1
%35 = call i32 @memcpy(i8* %32, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i64 %34)
store i16 20, i16* %3
store float 0x4058BF5C20000000, float* %4
store i8 77, i8* %5
%36 = load i32, i32* %6
%37 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 0
%38 = call i32 (i32, ...) @write(i32 %36, i8* %37, i64 20)
%39 = load i32, i32* %6
%40 = call i32 (i32, ...) @write(i32 %39, i16* %3, i64 2)
%41 = load i32, i32* %6
%42 = call i32 (i32, ...) @write(i32 %41, float* %4, i64 4)
%43 = load i32, i32* %6
%44 = call i32 (i32, ...) @write(i32 %43, i8* %5, i64 1)
%45 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 0
%46 = call i64 @strlen(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
%47 = add nsw i64 %46, 1
%48 = call i32 @memcpy(i8* %45, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i64 %47)
store i16 330, i16* %3
store float 1.000000e+02, float* %4
store i8 77, i8* %5
%49 = load i32, i32* %6
%50 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 0
%51 = call i32 (i32, ...) @write(i32 %49, i8* %50, i64 20)
%52 = load i32, i32* %6
%53 = call i32 (i32, ...) @write(i32 %52, i16* %3, i64 2)
%54 = load i32, i32* %6
%55 = call i32 (i32, ...) @write(i32 %54, float* %4, i64 4)
%56 = load i32, i32* %6
%57 = call i32 (i32, ...) @write(i32 %56, i8* %5, i64 1)
%58 = load i32, i32* %6
%59 = call i32 @close(i32 %58)
ret i32 0
}

LLVM IR (-O2):
@.str = [9 x i8] c"test.dat\00"
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@O_EXCL = global i32 0
@.str.1 = [20 x i8] c"open file error:%m\0A\00"
@.str.2 = [5 x i8] c"mizu\00"
@.str.3 = [5 x i8] c"tani\00"
@.str.4 = [4 x i8] c"\E7\B4\94\00"
define i32 @main() {
%1 = alloca [20 x i8]
%2 = alloca i16
%3 = alloca float
%4 = alloca i8
%5 = getelementptr inbounds [20 x i8], [20 x i8]* %1, i64 0, i64 0
%6 = bitcast i16* %2 to i8*
%7 = bitcast float* %3 to i8*
%8 = load i32, i32* @O_RDWR
%9 = load i32, i32* @O_CREAT
%10 = or i32 %9, %8
%11 = load i32, i32* @O_EXCL
%12 = or i32 %10, %11
%13 = tail call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %12, i32 438)
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %18
15: ; preds = %0
%16 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
%17 = tail call i32 @exit(i32 -1)
unreachable
18: ; preds = %0
%19 = call i32 @memcpy(i8* %5, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i64 5)
store i16 30, i16* %2
store float 0x4058FF5C20000000, float* %3
store i8 70, i8* %4
%20 = call i32 (i32, ...) @write(i32 %13, i8* %5, i64 20)
%21 = call i32 (i32, ...) @write(i32 %13, i16* %2, i64 2)
%22 = call i32 (i32, ...) @write(i32 %13, float* %3, i64 4)
%23 = call i32 (i32, ...) @write(i32 %13, i8* %4, i64 1)
%24 = call i32 @memcpy(i8* %5, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i64 5)
store i16 20, i16* %2
store float 0x4058BF5C20000000, float* %3
store i8 77, i8* %4
%25 = call i32 (i32, ...) @write(i32 %13, i8* %5, i64 20)
%26 = call i32 (i32, ...) @write(i32 %13, i16* %2, i64 2)
%27 = call i32 (i32, ...) @write(i32 %13, float* %3, i64 4)
%28 = call i32 (i32, ...) @write(i32 %13, i8* %4, i64 1)
%29 = call i32 @memcpy(i8* %5, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i64 4)
store i16 330, i16* %2
store float 1.000000e+02, float* %3
store i8 77, i8* %4
%30 = call i32 (i32, ...) @write(i32 %13, i8* %5, i64 20)
%31 = call i32 (i32, ...) @write(i32 %13, i16* %2, i64 2)
%32 = call i32 (i32, ...) @write(i32 %13, float* %3, i64 4)
%33 = call i32 (i32, ...) @write(i32 %13, i8* %4, i64 1)
%34 = call i32 @close(i32 %13)
ret i32 0
}