#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 */
scalar_t__ SCNormalloc(scalar_t__, char *, int);
scalar_t__ sc_strlen(char *);
int sc_strcpy_ex(char **T, char *S) {
  int walker = 0;
  char *R = 0;
  if (!*T)
    *T = (char *)SCNormalloc(sc_strlen(S) + 1,
                             "/scratch/repos/new/home/jordi_armengol_estape/"
                             "c-scraper/outputs/2022-01-22/02-19-57/repos/"
                             "astrotycoon/semo/refs/heads/master/common/sccl.c",
                             148);
  if (!*T)
    return 0;
  R = *T;
  while (*S)
    *R++ = *S++;
  *R = *S;
  return 1;
}


x86 assembly (clang, -O0):
<sc_strcpy_ex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x10(%rbp),%rax
cmpq   $0x0,(%rax)
jne    1178 <sc_strcpy_ex+0x58>
mov    -0x18(%rbp),%rdi
call   1030 <sc_strlen@plt>
mov    %rax,%rdi
add    $0x1,%rdi
lea    0xe9c(%rip),%rsi
mov    $0x94,%edx
call   1040 <SCNormalloc@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rax
cmpq   $0x0,(%rax)
jne    1192 <sc_strcpy_ex+0x72>
movl   $0x0,-0x4(%rbp)
jmp    11e4 <sc_strcpy_ex+0xc4>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rax
cmpb   $0x0,(%rax)
je     11d1 <sc_strcpy_ex+0xb1>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
mov    (%rax),%cl
mov    -0x28(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x28(%rbp)
mov    %cl,(%rax)
jmp    119d <sc_strcpy_ex+0x7d>
mov    -0x18(%rbp),%rax
mov    (%rax),%cl
mov    -0x28(%rbp),%rax
mov    %cl,(%rax)
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sc_strcpy_ex>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    (%rdi),%rax
test   %rax,%rax
jne    1157 <sc_strcpy_ex+0x37>
mov    %rdi,%r14
mov    %rbx,%rdi
call   1030 <sc_strlen@plt>
lea    0x1(%rax),%rdi
lea    0xebb(%rip),%rsi
mov    $0x94,%edx
call   1040 <SCNormalloc@plt>
mov    %rax,(%r14)
test   %rax,%rax
je     1191 <sc_strcpy_ex+0x71>
mov    (%rbx),%cl
test   %cl,%cl
je     1181 <sc_strcpy_ex+0x61>
add    $0x1,%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %cl,(%rax)
add    $0x1,%rax
movzbl (%rbx),%ecx
add    $0x1,%rbx
test   %cl,%cl
jne    1170 <sc_strcpy_ex+0x50>
movb   $0x0,(%rax)
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
xor    %eax,%eax
jmp    1189 <sc_strcpy_ex+0x69>

LLVM IR (-O0):
@.str = [139 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/astrotycoon/semo/refs/heads/master/common/sccl.c\00"
define i32 @sc_strcpy_ex(i8** %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
store i8** %0, i8*** %4
store i8* %1, i8** %5
store i32 0, i32* %6
store i8* null, i8** %7
%8 = load i8**, i8*** %4
%9 = load i8*, i8** %8
%10 = icmp ne i8* %9, null
br i1 %10, label %18, label %11
11: ; preds = %2
%12 = load i8*, i8** %5
%13 = call i64 @sc_strlen(i8* %12)
%14 = add nsw i64 %13, 1
%15 = call i64 @SCNormalloc(i64 %14, i8* getelementptr inbounds ([139 x i8], [139 x i8]* @.str, i64 0, i64 0), i32 148)
%16 = inttoptr i64 %15 to i8*
%17 = load i8**, i8*** %4
store i8* %16, i8** %17
br label %18
18: ; preds = %11, %2
%19 = load i8**, i8*** %4
%20 = load i8*, i8** %19
%21 = icmp ne i8* %20, null
br i1 %21, label %23, label %22
22: ; preds = %18
store i32 0, i32* %3
br label %40
23: ; preds = %18
%24 = load i8**, i8*** %4
%25 = load i8*, i8** %24
store i8* %25, i8** %7
br label %26
26: ; preds = %30, %23
%27 = load i8*, i8** %5
%28 = load i8, i8* %27
%29 = icmp ne i8 %28, 0
br i1 %29, label %30, label %36
30: ; preds = %26
%31 = load i8*, i8** %5
%32 = getelementptr inbounds i8, i8* %31, i32 1
store i8* %32, i8** %5
%33 = load i8, i8* %31
%34 = load i8*, i8** %7
%35 = getelementptr inbounds i8, i8* %34, i32 1
store i8* %35, i8** %7
store i8 %33, i8* %34
br label %26
36: ; preds = %26
%37 = load i8*, i8** %5
%38 = load i8, i8* %37
%39 = load i8*, i8** %7
store i8 %38, i8* %39
store i32 1, i32* %3
br label %40
40: ; preds = %36, %22
%41 = load i32, i32* %3
ret i32 %41
}

LLVM IR (-O2):
@.str = [139 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/astrotycoon/semo/refs/heads/master/common/sccl.c\00"
define i32 @sc_strcpy_ex(i8** nocapture %0, i8* %1) {
%3 = load i8*, i8** %0
%4 = icmp eq i8* %3, null
br i1 %4, label %5, label %11
5: ; preds = %2
%6 = tail call i64 @sc_strlen(i8* %1)
%7 = add nsw i64 %6, 1
%8 = tail call i64 @SCNormalloc(i64 %7, i8* getelementptr inbounds ([139 x i8], [139 x i8]* @.str, i64 0, i64 0), i32 148)
%9 = inttoptr i64 %8 to i8*
store i8* %9, i8** %0
%10 = icmp eq i64 %8, 0
br i1 %10, label %25, label %11
11: ; preds = %2, %5
%12 = phi i8* [ %9, %5 ], [ %3, %2 ]
%13 = load i8, i8* %1
%14 = icmp eq i8 %13, 0
br i1 %14, label %23, label %15
15: ; preds = %11, %15
%16 = phi i8 [ %21, %15 ], [ %13, %11 ]
%17 = phi i8* [ %20, %15 ], [ %12, %11 ]
%18 = phi i8* [ %19, %15 ], [ %1, %11 ]
%19 = getelementptr inbounds i8, i8* %18, i64 1
%20 = getelementptr inbounds i8, i8* %17, i64 1
store i8 %16, i8* %17
%21 = load i8, i8* %19
%22 = icmp eq i8 %21, 0
br i1 %22, label %23, label %15
23: ; preds = %15, %11
%24 = phi i8* [ %12, %11 ], [ %20, %15 ]
store i8 0, i8* %24
br label %25
25: ; preds = %5, %23
%26 = phi i32 [ 1, %23 ], [ 0, %5 ]
ret i32 %26
}