#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 EXIT_SUCCESS;
int O_CREAT;
int O_RDWR;
int O_TRUNC;
int O_WRONLY;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ close(int);
int dup(int);
int /*<<< orphan*/ err(int, char *);
scalar_t__ lseek(int, int /*<<< orphan*/, int /*<<< orphan*/);
int open(char *, int, int);
int read(int, char *, int);
int /*<<< orphan*/ sprintf(char *, char *, char);
int strlen(char *);
int /*<<< orphan*/ umask(int /*<<< orphan*/);
int /*<<< orphan*/ write(int, char *, int);
int main(int argc, char *argv[]) {
  int count;
  int fd, fd1;
  char buffer[256];
  umask(0);
  if ((fd = open("io.c", O_RDWR, 0)) < 0) {
    err(1, "open");
  }
  if ((fd1 = open("/tmp/thing.c", O_TRUNC | O_WRONLY | O_CREAT, 0666)) < 0) {
    err(1, "open");
  }
  while ((count = read(fd, buffer, 256)) > 0) {
    write(fd1, buffer, count);
  }
  if (lseek(fd, 0, SEEK_SET) < 0) {
    err(1, "lseek");
  }
  if (read(fd, buffer, 1) != 1) {
    err(1, "read");
  }
  count = dup(1);
  sprintf(buffer, "The first character is: %c.\n", buffer[0]);
  write(count, buffer, strlen(buffer));
  close(fd);
  close(fd1);
  close(count);
  return (EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
xor    %edi,%edi
call   1090 <umask@plt>
mov    0x2e11(%rip),%rax
mov    (%rax),%esi
lea    0xe30(%rip),%rdi
xor    %edx,%edx
call   10b0 <open@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
jge    11f4 <main+0x54>
mov    $0x1,%edi
lea    0xe16(%rip),%rsi
call   10a0 <err@plt>
mov    0x2df5(%rip),%rax
mov    (%rax),%esi
mov    0x2dac(%rip),%rax
or     (%rax),%esi
mov    0x2deb(%rip),%rax
or     (%rax),%esi
lea    0xdf4(%rip),%rdi
mov    $0x1b6,%edx
call   10b0 <open@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jge    123d <main+0x9d>
mov    $0x1,%edi
lea    0xdcd(%rip),%rsi
call   10a0 <err@plt>
jmp    1242 <main+0xa2>
mov    -0x18(%rbp),%edi
lea    -0x120(%rbp),%rsi
mov    $0x100,%edx
call   1080 <read@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jle    1279 <main+0xd9>
mov    -0x1c(%rbp),%edi
lea    -0x120(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1030 <write@plt>
jmp    1242 <main+0xa2>
mov    -0x18(%rbp),%edi
mov    0x2d45(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1060 <lseek@plt>
cmp    $0x0,%rax
jge    12a7 <main+0x107>
mov    $0x1,%edi
lea    0xd75(%rip),%rsi
call   10a0 <err@plt>
mov    -0x18(%rbp),%edi
lea    -0x120(%rbp),%rsi
mov    $0x1,%edx
call   1080 <read@plt>
cmp    $0x1,%eax
je     12d5 <main+0x135>
mov    $0x1,%edi
lea    0xd4d(%rip),%rsi
call   10a0 <err@plt>
mov    $0x1,%edi
call   1050 <dup@plt>
mov    %eax,-0x14(%rbp)
lea    -0x120(%rbp),%rdi
lea    0xd32(%rip),%rsi
movsbl -0x120(%rbp),%edx
call   10c0 <sprintf@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x12c(%rbp)
lea    -0x120(%rbp),%rax
mov    %rax,-0x128(%rbp)
lea    -0x120(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x12c(%rbp),%edi
mov    -0x128(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    -0x18(%rbp),%edi
call   1070 <close@plt>
mov    -0x1c(%rbp),%edi
call   1070 <close@plt>
mov    -0x14(%rbp),%edi
call   1070 <close@plt>
mov    0x2c6e(%rip),%rax
mov    (%rax),%eax
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x108,%rsp
xor    %edi,%edi
call   1090 <umask@plt>
mov    0x2e1d(%rip),%rax
mov    (%rax),%esi
lea    0xe3c(%rip),%rdi
xor    %edx,%edx
call   10b0 <open@plt>
mov    %eax,%r14d
test   %eax,%eax
jns    11e3 <main+0x43>
lea    0xe2c(%rip),%rsi
mov    $0x1,%edi
call   10a0 <err@plt>
mov    0x2e06(%rip),%rax
mov    0x2dbf(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2dfc(%rip),%rax
or     (%rax),%esi
lea    0xe05(%rip),%rdi
mov    $0x1b6,%edx
call   10b0 <open@plt>
mov    %eax,%ebp
test   %eax,%eax
jns    1226 <main+0x86>
lea    0xde9(%rip),%rsi
mov    $0x1,%edi
call   10a0 <err@plt>
mov    %rsp,%rsi
mov    %r14d,%edi
mov    $0x100,%edx
call   1080 <read@plt>
test   %eax,%eax
jle    1260 <main+0xc0>
mov    %rsp,%rbx
nopl   (%rax)
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %r14d,%edi
mov    %rbx,%rsi
mov    $0x100,%edx
call   1080 <read@plt>
test   %eax,%eax
jg     1240 <main+0xa0>
mov    0x2d61(%rip),%rax
mov    (%rax),%edx
mov    %r14d,%edi
xor    %esi,%esi
call   1060 <lseek@plt>
test   %rax,%rax
jns    1289 <main+0xe9>
lea    0xd98(%rip),%rsi
mov    $0x1,%edi
call   10a0 <err@plt>
mov    %rsp,%rsi
mov    %r14d,%edi
mov    $0x1,%edx
call   1080 <read@plt>
cmp    $0x1,%eax
je     12af <main+0x10f>
lea    0xd78(%rip),%rsi
mov    $0x1,%edi
call   10a0 <err@plt>
mov    $0x1,%edi
call   1050 <dup@plt>
mov    %eax,%ebx
movsbl (%rsp),%edx
lea    0xd5c(%rip),%rsi
mov    %rsp,%r15
mov    %r15,%rdi
call   10c0 <sprintf@plt>
mov    %r15,%rdi
call   1040 <strlen@plt>
mov    %ebx,%edi
mov    %r15,%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %r14d,%edi
call   1070 <close@plt>
mov    %ebp,%edi
call   1070 <close@plt>
mov    %ebx,%edi
call   1070 <close@plt>
mov    0x2cbe(%rip),%rax
mov    (%rax),%eax
add    $0x108,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"io.c\00"
@O_RDWR = global i32 0
@.str.1 = [5 x i8] c"open\00"
@.str.2 = [13 x i8] c"/tmp/thing.c\00"
@O_TRUNC = global i32 0
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@SEEK_SET = global i32 0
@.str.3 = [6 x i8] c"lseek\00"
@.str.4 = [5 x i8] c"read\00"
@.str.5 = [29 x i8] c"The first character is: %c.\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca [256 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = call i32 @umask(i32 0)
%11 = load i32, i32* @O_RDWR
%12 = call i32 @open(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %11, i32 0)
store i32 %12, i32* %7
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %2
%15 = call i32 @err(i32 1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %16
16: ; preds = %14, %2
%17 = load i32, i32* @O_TRUNC
%18 = load i32, i32* @O_WRONLY
%19 = or i32 %17, %18
%20 = load i32, i32* @O_CREAT
%21 = or i32 %19, %20
%22 = call i32 @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i32 %21, i32 438)
store i32 %22, i32* %8
%23 = icmp slt i32 %22, 0
br i1 %23, label %24, label %26
24: ; preds = %16
%25 = call i32 @err(i32 1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %26
26: ; preds = %24, %16
br label %27
27: ; preds = %32, %26
%28 = load i32, i32* %7
%29 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%30 = call i32 @read(i32 %28, i8* %29, i32 256)
store i32 %30, i32* %6
%31 = icmp sgt i32 %30, 0
br i1 %31, label %32, label %37
32: ; preds = %27
%33 = load i32, i32* %8
%34 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%35 = load i32, i32* %6
%36 = call i32 @write(i32 %33, i8* %34, i32 %35)
br label %27
37: ; preds = %27
%38 = load i32, i32* %7
%39 = load i32, i32* @SEEK_SET
%40 = call i64 @lseek(i32 %38, i32 0, i32 %39)
%41 = icmp slt i64 %40, 0
br i1 %41, label %42, label %44
42: ; preds = %37
%43 = call i32 @err(i32 1, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
br label %44
44: ; preds = %42, %37
%45 = load i32, i32* %7
%46 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%47 = call i32 @read(i32 %45, i8* %46, i32 1)
%48 = icmp ne i32 %47, 1
br i1 %48, label %49, label %51
49: ; preds = %44
%50 = call i32 @err(i32 1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
br label %51
51: ; preds = %49, %44
%52 = call i32 @dup(i32 1)
store i32 %52, i32* %6
%53 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%54 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%55 = load i8, i8* %54
%56 = call i32 @sprintf(i8* %53, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.5, i64 0, i64 0), i8 signext %55)
%57 = load i32, i32* %6
%58 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%59 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%60 = call i32 @strlen(i8* %59)
%61 = call i32 @write(i32 %57, i8* %58, i32 %60)
%62 = load i32, i32* %7
%63 = call i32 @close(i32 %62)
%64 = load i32, i32* %8
%65 = call i32 @close(i32 %64)
%66 = load i32, i32* %6
%67 = call i32 @close(i32 %66)
%68 = load i32, i32* @EXIT_SUCCESS
ret i32 %68
}

LLVM IR (-O2):
@.str = [5 x i8] c"io.c\00"
@O_RDWR = global i32 0
@.str.1 = [5 x i8] c"open\00"
@.str.2 = [13 x i8] c"/tmp/thing.c\00"
@O_TRUNC = global i32 0
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@SEEK_SET = global i32 0
@.str.3 = [6 x i8] c"lseek\00"
@.str.4 = [5 x i8] c"read\00"
@.str.5 = [29 x i8] c"The first character is: %c.\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [256 x i8]
%4 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%5 = tail call i32 @umask(i32 0)
%6 = load i32, i32* @O_RDWR
%7 = tail call i32 @open(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %6, i32 0)
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %2
%10 = tail call i32 @err(i32 1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %11
11: ; preds = %9, %2
%12 = load i32, i32* @O_TRUNC
%13 = load i32, i32* @O_WRONLY
%14 = or i32 %13, %12
%15 = load i32, i32* @O_CREAT
%16 = or i32 %14, %15
%17 = tail call i32 @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i32 %16, i32 438)
%18 = icmp slt i32 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %11
%20 = tail call i32 @err(i32 1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %21
21: ; preds = %19, %11
%22 = call i32 @read(i32 %7, i8* %4, i32 256)
%23 = icmp sgt i32 %22, 0
br i1 %23, label %24, label %29
24: ; preds = %21, %24
%25 = phi i32 [ %27, %24 ], [ %22, %21 ]
%26 = call i32 @write(i32 %17, i8* %4, i32 %25)
%27 = call i32 @read(i32 %7, i8* %4, i32 256)
%28 = icmp sgt i32 %27, 0
br i1 %28, label %24, label %29
29: ; preds = %24, %21
%30 = load i32, i32* @SEEK_SET
%31 = tail call i64 @lseek(i32 %7, i32 0, i32 %30)
%32 = icmp slt i64 %31, 0
br i1 %32, label %33, label %35
33: ; preds = %29
%34 = tail call i32 @err(i32 1, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
br label %35
35: ; preds = %33, %29
%36 = call i32 @read(i32 %7, i8* %4, i32 1)
%37 = icmp eq i32 %36, 1
br i1 %37, label %40, label %38
38: ; preds = %35
%39 = tail call i32 @err(i32 1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
br label %40
40: ; preds = %38, %35
%41 = tail call i32 @dup(i32 1)
%42 = load i8, i8* %4
%43 = call i32 @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.5, i64 0, i64 0), i8 signext %42)
%44 = call i32 @strlen(i8* %4)
%45 = call i32 @write(i32 %41, i8* %4, i32 %44)
%46 = call i32 @close(i32 %7)
%47 = call i32 @close(i32 %17)
%48 = call i32 @close(i32 %41)
%49 = load i32, i32* @EXIT_SUCCESS
ret i32 %49
}