#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*/ fprintf(int /*<<< orphan*/, char *, char *, int, char *);
int /*<<< orphan*/ memcpy(char *, char *, int);
int /*<<< orphan*/ perror(char *);
char *shmat(int, int /*<<< orphan*/, int /*<<< orphan*/);
int shmget(int, int /*<<< orphan*/, int);
int /*<<< orphan*/ stderr;
void child() {
  int shmid;
  char *addr;
  char buf[1024];
  shmid = shmget(1, 0, 0666);
  if (shmid < 0) {
    perror("child shmget");
    return;
  }
  addr = shmat(shmid, 0, 0);
  memcpy(buf, addr, 1024);
  do {
    if (4 <= 4) {
      fprintf(stderr,
              "%s %d: "
              "buf is: %s\n",
              "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
              "2022-01-22/02-19-57/repos/clpsz/linux-ipcs/refs/heads/master/"
              "XSI_shm/main.c",
              66, buf);
    }
  } while (0);
}


x86 assembly (clang, -O0):
<child>:
push   %rbp
mov    %rsp,%rbp
sub    $0x410,%rsp
mov    $0x1,%edi
xor    %esi,%esi
mov    $0x1b6,%edx
call   1070 <shmget@plt>
mov    %eax,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
jge    118a <child+0x3a>
lea    0xe80(%rip),%rdi
call   1050 <perror@plt>
jmp    11d7 <child+0x87>
mov    -0x4(%rbp),%edi
xor    %edx,%edx
mov    %edx,%esi
call   1060 <shmat@plt>
mov    %rax,-0x10(%rbp)
lea    -0x410(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0x400,%edx
call   1040 <memcpy@plt>
mov    0x2e2a(%rip),%rax
mov    (%rax),%edi
lea    -0x410(%rbp),%r8
lea    0xe47(%rip),%rsi
lea    0xe53(%rip),%rdx
mov    $0x42,%ecx
call   1030 <fprintf@plt>
add    $0x410,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<child>:
push   %rbx
sub    $0x400,%rsp
mov    $0x1,%edi
xor    %esi,%esi
mov    $0x1b6,%edx
call   1070 <shmget@plt>
test   %eax,%eax
js     11b8 <child+0x68>
mov    %eax,%edi
xor    %esi,%esi
xor    %edx,%edx
call   1060 <shmat@plt>
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    %rax,%rsi
mov    $0x400,%edx
call   1040 <memcpy@plt>
mov    0x2e4e(%rip),%rax
mov    (%rax),%edi
lea    0xe72(%rip),%rsi
lea    0xe7e(%rip),%rdx
mov    $0x42,%ecx
mov    %rbx,%r8
call   1030 <fprintf@plt>
add    $0x400,%rsp
pop    %rbx
ret
lea    0xe41(%rip),%rdi
add    $0x400,%rsp
pop    %rbx
jmp    1050 <perror@plt>

LLVM IR (-O0):
@.str = [13 x i8] c"child shmget\00"
@stderr = global i32 0
@.str.1 = [19 x i8] c"%s %d: buf is: %s\0A\00"
@.str.2 = [140 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/clpsz/linux-ipcs/refs/heads/master/XSI_shm/main.c\00"
define void @child() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca [1024 x i8]
%4 = call i32 @shmget(i32 1, i32 0, i32 438)
store i32 %4, i32* %1
%5 = load i32, i32* %1
%6 = icmp slt i32 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
br label %19
9: ; preds = %0
%10 = load i32, i32* %1
%11 = call i8* @shmat(i32 %10, i32 0, i32 0)
store i8* %11, i8** %2
%12 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%13 = load i8*, i8** %2
%14 = call i32 @memcpy(i8* %12, i8* %13, i32 1024)
br label %15
15: ; preds = %9
%16 = load i32, i32* @stderr
%17 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%18 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([140 x i8], [140 x i8]* @.str.2, i64 0, i64 0), i32 66, i8* %17)
br label %19
19: ; preds = %7, %15
ret void
}

LLVM IR (-O2):
@.str = [13 x i8] c"child shmget\00"
@stderr = global i32 0
@.str.1 = [19 x i8] c"%s %d: buf is: %s\0A\00"
@.str.2 = [140 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/clpsz/linux-ipcs/refs/heads/master/XSI_shm/main.c\00"
define void @child() {
%1 = alloca [1024 x i8]
%2 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 0
%3 = tail call i32 @shmget(i32 1, i32 0, i32 438)
%4 = icmp slt i32 %3, 0
br i1 %4, label %5, label %7
5: ; preds = %0
%6 = tail call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
br label %12
7: ; preds = %0
%8 = tail call i8* @shmat(i32 %3, i32 0, i32 0)
%9 = call i32 @memcpy(i8* %2, i8* %8, i32 1024)
%10 = load i32, i32* @stderr
%11 = call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([140 x i8], [140 x i8]* @.str.2, i64 0, i64 0), i32 66, i8* %2)
br label %12
12: ; preds = %7, %5
ret void
}