#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*/ O_WRONLY;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ memset(char *, int, char);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ scanf(char *, char *);
int /*<<< orphan*/ write(int, char *, int);
int main() {
  char buf[32];
  int fd = open("c1.dat", O_WRONLY);
  if (fd == -1) {
    printf("%s\n", "open() error");
    exit(1);
  };
  while (1) {
    memset(buf, 32, '\0');
    scanf("%s", buf);
    write(fd, buf, 32);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e62(%rip),%rax
mov    (%rax),%esi
lea    0xe81(%rip),%rdi
call   1070 <open@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0xffffffff,-0x34(%rbp)
jne    11ae <main+0x4e>
lea    0xe6f(%rip),%rdi
lea    0xe6c(%rip),%rsi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
jmp    11b3 <main+0x53>
lea    -0x30(%rbp),%rdi
mov    $0x20,%esi
xor    %edx,%edx
call   1050 <memset@plt>
lea    -0x30(%rbp),%rsi
lea    0xe4a(%rip),%rdi
call   1060 <scanf@plt>
mov    -0x34(%rbp),%edi
lea    -0x30(%rbp),%rsi
mov    $0x20,%edx
call   1030 <write@plt>
jmp    11b3 <main+0x53>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    0x2e69(%rip),%rax
mov    (%rax),%esi
lea    0xe88(%rip),%rdi
call   1070 <open@plt>
cmp    $0xffffffff,%eax
je     11bb <main+0x5b>
mov    %eax,%ebp
mov    %rsp,%rbx
lea    0xe8a(%rip),%r14
xchg   %ax,%ax
mov    %rbx,%rdi
mov    $0x20,%esi
xor    %edx,%edx
call   1050 <memset@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1060 <scanf@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x20,%edx
call   1030 <write@plt>
jmp    1190 <main+0x30>
lea    0xe45(%rip),%rdi
lea    0xe42(%rip),%rsi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [7 x i8] c"c1.dat\00"
@O_WRONLY = global i32 0
@.str.1 = [4 x i8] c"%s\0A\00"
@.str.2 = [13 x i8] c"open() error\00"
@.str.3 = [3 x i8] c"%s\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [32 x i8]
%3 = alloca i32
store i32 0, i32* %1
%4 = load i32, i32* @O_WRONLY
%5 = call i32 @open(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %4)
store i32 %5, i32* %3
%6 = load i32, i32* %3
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %11
8: ; preds = %0
%9 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%10 = call i32 @exit(i32 1)
unreachable
11: ; preds = %0
br label %12
12: ; preds = %11, %12
%13 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 0
%14 = call i32 @memset(i8* %13, i32 32, i8 signext 0)
%15 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 0
%16 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %15)
%17 = load i32, i32* %3
%18 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 0
%19 = call i32 @write(i32 %17, i8* %18, i32 32)
br label %12
}

LLVM IR (-O2):
@.str = [7 x i8] c"c1.dat\00"
@O_WRONLY = global i32 0
@.str.1 = [4 x i8] c"%s\0A\00"
@.str.2 = [13 x i8] c"open() error\00"
@.str.3 = [3 x i8] c"%s\00"
define i32 @main() {
%1 = alloca [32 x i8]
%2 = getelementptr inbounds [32 x i8], [32 x i8]* %1, i64 0, i64 0
%3 = load i32, i32* @O_WRONLY
%4 = tail call i32 @open(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = icmp eq i32 %4, -1
br i1 %5, label %6, label %9
6: ; preds = %0
%7 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%8 = tail call i32 @exit(i32 1)
unreachable
9: ; preds = %0, %9
%10 = call i32 @memset(i8* %2, i32 32, i8 signext 0)
%11 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %2)
%12 = call i32 @write(i32 %4, i8* %2, i32 32)
br label %9
}