#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_RDONLY;
int /*<<< orphan*/ close(int);
int open(char const *, int /*<<< orphan*/);
int read(int, char *, int);
char *read_header(const char *name) {
  static char buf[160 + 1];
  int fd, k;
  fd = open(name, O_RDONLY);
  if (fd < 0)
    return 0;
  k = read(fd, buf, 160);
  close(fd);
  if (k < 0)
    return 0;
  buf[k] = 0;
  return buf;
}


x86 assembly (clang, -O0):
<read_header>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2ea1(%rip),%rax
mov    (%rax),%esi
call   1050 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1168 <read_header+0x38>
movq   $0x0,-0x8(%rbp)
jmp    11b8 <read_header+0x88>
mov    -0x14(%rbp),%edi
lea    0x2ede(%rip),%rsi
mov    $0xa0,%edx
call   1040 <read@plt>
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%edi
call   1030 <close@plt>
cmpl   $0x0,-0x18(%rbp)
jge    119e <read_header+0x6e>
movq   $0x0,-0x8(%rbp)
jmp    11b8 <read_header+0x88>
movslq -0x18(%rbp),%rcx
lea    0x2ea7(%rip),%rax
movb   $0x0,(%rax,%rcx,1)
lea    0x2e9c(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_header>:
push   %rbp
push   %r14
push   %rbx
mov    0x2ead(%rip),%rax
mov    (%rax),%esi
call   1050 <open@plt>
test   %eax,%eax
js     1176 <read_header+0x46>
mov    %eax,%ebp
lea    0x2f01(%rip),%rbx
mov    %eax,%edi
mov    %rbx,%rsi
mov    $0xa0,%edx
call   1040 <read@plt>
mov    %eax,%r14d
mov    %ebp,%edi
call   1030 <close@plt>
test   %r14d,%r14d
js     1176 <read_header+0x46>
mov    %r14d,%eax
movb   $0x0,(%rax,%rbx,1)
jmp    1178 <read_header+0x48>
xor    %ebx,%ebx
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@read_header.buf = internal global [161 x i8] zeroinitializer
@O_RDONLY = global i32 0
define i8* @read_header(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = load i32, i32* @O_RDONLY
%8 = call i32 @open(i8* %6, i32 %7)
store i32 %8, i32* %4
%9 = load i32, i32* %4
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %12
11: ; preds = %1
store i8* null, i8** %2
br label %24
12: ; preds = %1
%13 = load i32, i32* %4
%14 = call i32 @read(i32 %13, i8* getelementptr inbounds ([161 x i8], [161 x i8]* @read_header.buf, i64 0, i64 0), i32 160)
store i32 %14, i32* %5
%15 = load i32, i32* %4
%16 = call i32 @close(i32 %15)
%17 = load i32, i32* %5
%18 = icmp slt i32 %17, 0
br i1 %18, label %19, label %20
19: ; preds = %12
store i8* null, i8** %2
br label %24
20: ; preds = %12
%21 = load i32, i32* %5
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds [161 x i8], [161 x i8]* @read_header.buf, i64 0, i64 %22
store i8 0, i8* %23
store i8* getelementptr inbounds ([161 x i8], [161 x i8]* @read_header.buf, i64 0, i64 0), i8** %2
br label %24
24: ; preds = %20, %19, %11
%25 = load i8*, i8** %2
ret i8* %25
}

LLVM IR (-O2):
@read_header.buf = internal global [161 x i8] zeroinitializer
@O_RDONLY = global i32 0
define i8* @read_header(i8* nocapture %0) {
%2 = load i32, i32* @O_RDONLY
%3 = tail call i32 @open(i8* %0, i32 %2)
%4 = icmp slt i32 %3, 0
br i1 %4, label %12, label %5
5: ; preds = %1
%6 = tail call i32 @read(i32 %3, i8* getelementptr inbounds ([161 x i8], [161 x i8]* @read_header.buf, i64 0, i64 0), i32 160)
%7 = tail call i32 @close(i32 %3)
%8 = icmp slt i32 %6, 0
br i1 %8, label %12, label %9
9: ; preds = %5
%10 = zext i32 %6 to i64
%11 = getelementptr inbounds [161 x i8], [161 x i8]* @read_header.buf, i64 0, i64 %10
store i8 0, i8* %11
br label %12
12: ; preds = %5, %1, %9
%13 = phi i8* [ getelementptr inbounds ([161 x i8], [161 x i8]* @read_header.buf, i64 0, i64 0), %9 ], [ null, %1 ], [ null, %5 ]
ret i8* %13
}